engine

package
v0.0.0-...-1d82e13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: GPL-3.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine holds the ecosystem registry and the engine.Ecosystem interface.

Index

Constants

View Source
const GoModHeader = "// Code generated by bob from bob.go. DO NOT EDIT."

GoModHeader is the first line of every go.mod bob writes (§03.0.2). The Go generator writes it and the evaluator recognises bob's own go.mod by it, so both use this one constant.

View Source
const TestIndexEnv = "BOB_TEST_NIXPKGS_INDEX"

TestIndexEnv names a JSON file {"native": Versions, "cross": Versions} that replaces the versions looked up in the nixpkgs index (tests/platforms R-PLAT-007): "native" are the target system's own packages, "cross" the cross toolchain's glibc and the host's rustc.

View Source
const UnknownLicence = "unknown"

UnknownLicence is the licence of a path nothing declares one for (R-OUT-008).

Variables

View Source
var ErrClosureBuild = errors.New("building a closure while planning failed")

ErrClosureBuild wraps a Closure failure caused by a build (a program that does not compile): the planner then plans a derivation that depends on the failing inputs, so the build stage reports the real failure with its log.

Functions

func Blocked

func Blocked(jobs *Jobs, label, name string, codegen []string) (drvPath, out string, err error)

Blocked plans the derivation of a package that cannot be planned because codegen it needs failed while planning: it depends on the failing codegen derivations, so the build stage builds those first and reports their failure, and the package itself is skipped. It never succeeds.

func CToolchain

func CToolchain(n *ir.Node) (bob.Toolchain, error)

CToolchain is the C/C++ toolchain of a node, as the evaluator selected it (R-FW-033).

func CheckPruned

func CheckPruned(st PlanStore, label string, paths []string, r *Pruning, programs ...string) error

CheckPruned reports a pruned file that an ELF file left in the bundle needs (DT_NEEDED, resolved through its RUNPATH/RPATH in the closure): BOB-E-2015 for label (R-OUT-007). programs (store paths of the bundle's program files) are checked first, together with the kept libraries they load, and a hit names the program (SPEC: "removes libssl.so.3, which api needs" although api loads libssl through libfoo.so); every other file names itself.

func CheckVersions

func CheckVersions(target bob.Platform, native, cross Versions, libs, rust bool) error

CheckVersions is the pre-check of R-PLAT-007 for one cross target: with target libraries from the target system's own set (libs), its glibc must equal the cross toolchain's; with Rust code (rust), the target system's rustc must equal the host's (its standard library is the target std). An empty version is unknown and not compared.

func ClosureOf

func ClosureOf(refs map[string][]string, roots ...string) []string

ClosureOf returns the closure of roots in refs (path → references), sorted.

func CodegenOutput

func CodegenOutput(st PlanStore, rv Resolved) (host, storePath string, ok bool)

CodegenOutput returns where a consumer reads the generated files of rv while planning, and the store path it depends on: the content-addressed copy PlanCodegen made. ok is false when there is none (the generator failed while planning; a failed build may leave an empty, invalid output directory behind, so the derivation's output is never read): the consumer then plans Blocked.

func ConsumerOf

func ConsumerOf(g *ir.Graph, id string, kinds ...string) *ir.Node

ConsumerOf returns the node of g that realises the codegen node id (the go.module or npm importer that lists it as a dependency) of one of kinds, or nil.

func CrossRefused

func CrossRefused(n *ir.Node) error

CrossRefused returns the error for a node of a native-only ecosystem requested for another platform than the host's, or nil.

func HostPlatform

func HostPlatform() bob.Platform

HostPlatform is the platform bob runs on ("" on an unsupported architecture).

func HostSystem

func HostSystem() string

HostSystem is the Nix system of every derivation bob generates on this machine.

func IncludeDirOf

func IncludeDirOf(n *ir.Node) string

IncludeDirOf returns the include directory n exports (relative to its package directory), or "".

func Internal

func Internal(n *ir.Node, format string, a ...any) error

Internal is an error of node n that is bob's bug (the engine reports it as such).

func Invalid

func Invalid(n *ir.Node, option, reason string) error

Invalid is BOB-E-1020 for node n: an option that is wrong for the files or deps it names.

func IsCodegenKind

func IsCodegenKind(kind string) bool

IsCodegenKind reports whether kind was registered with RegisterCodegenKind.

func JoinErrors

func JoinErrors(errs []error) error

JoinErrors joins the errors of a planner so that the engine still sees each diagnostic (Unwrap []error): nil for none, the error itself for one.

func LabelDir

func LabelDir(label string) string

LabelDir is the repository-relative directory of a label of this repository ("" for the root and for labels of other repositories).

func NixpkgsSource

func NixpkgsSource(n *ir.Node) (system, attr string, err error)

NixpkgsSource returns where the nixpkgs package of node n comes from: the Nix system of the package set and the attribute in it (R-FW-032, R-FW-036). Tools come from the host set; a Lib or Pkg for a cross target from the target system's own set, or with Cross() from the host's pkgsCross set; natively all three are the host set's attribute.

func NodePlatform

func NodePlatform(n *ir.Node) (bob.Platform, error)

NodePlatform returns the platform a node is built for: its projected platform, else the host's (nodes without a platform axis are host-independent).

func OutPath

func OutPath(d *drv.Derivation) string

OutPath is the store path of output "out" of d ("" when d has none).

func OwnLicences

func OwnLicences(g *ir.Graph, inputs map[string]Resolved) map[string]Licence

OwnLicences returns the licences.json entries of the paths built by bob packages of the graph (outputs of non-nixpkgs nodes in inputs): name = the package name, licence "unknown".

func OwnedDir

func OwnedDir(consumerDir, dir string) (string, error)

OwnedDir checks a codegen output directory relative to its consumer and returns it repository-relative: clean, relative, inside the consumer, never in .git or .bob.

func PickOutput

func PickOutput(outs map[string]string, prefer ...string) string

PickOutput returns the first of prefer that outs has, else its first output by name.

func PlanCodegen

func PlanCodegen(ctx context.Context, req PlanRequest, c Codegen) (Resolved, Materialisation)

PlanCodegen finishes a codegen node (§03.6.3, R-GEN-005): the derivation is built while planning (engine.PlanRealiser), its output is added to the store by content as `gen-<label slug>` and the node's Resolved names that copy in Cutoff, so consumers depend on the content instead of the derivation and a byte-identical regeneration rebuilds nothing downstream. When the build fails (or the store cannot build while planning) the node resolves to the derivation itself: the build stage then builds it and reports the generator's failure, and consumers that need its files plan blocked (see Blocked). The Materialisation puts the output into the working tree after the build.

func PlanCodegens

func PlanCodegens(ctx context.Context, req PlanRequest, cs []Codegen) ([]Resolved, []Materialisation)

PlanCodegens is PlanCodegen for several nodes with one build and one source import (the no-change cost of the two-phase planning, R-GEN-005). A failed build retries the nodes one by one, so only the failing ones lose the cutoff.

func PruneGlob

func PruneGlob(pattern string) (*regexp.Regexp, error)

PruneGlob compiles a prune pattern (R-OUT-007): matched against /nix/store/<hash>-<name>/<path>; "*" and "?" do not cross "/", "**" does.

func Register

func Register(e Ecosystem)

Register registers an ecosystem. Generator packages call it from init. Its Name is the bob.lock section key and the first element of its node kinds ("<name>.<kind>"). An invalid or duplicate name is recorded and reported by Ecosystems, so a broken registration fails every build instead of panicking during initialisation.

func RegisterCodegenKind

func RegisterCodegenKind(kind string)

RegisterCodegenKind marks a node kind as a code generator: a failed build of it is reported as `✗ <label> code generation failed (defined at <bob.go:line>)` with the generator's own messages (R-GEN-001a). Generator packages call it from init.

func RegisterIncludeDir

func RegisterIncludeDir(kind string, f func(spec json.RawMessage) string)

RegisterIncludeDir tells the engine which directory a node kind exports to its consumers as an include directory (cc.library's Hdrs): f returns it relative to the package directory, "" for none. Build errors use it to explain a header that the sandbox does not show a package (translate.Export). Ecosystem packages call it from init.

func RuntimeMismatch

func RuntimeMismatch(label, generator, version, runtime, need, file, have string, at ir.Pos) *diag.Error

RuntimeMismatch is the BOB-E-1021 error of a generator whose runtime library an explicit pin contradicts (§03.6.4, R-GEN-006), raised before anything is built:

✗ //svc:gen-graph: generator gqlgen 0.17.90 (bob's nixpkgs pin) does not match its runtime: the generated code needs github.com/99designs/gqlgen 0.17.90, but svc/bob.go requires v0.17.89

func SPDXExpression

func SPDXExpression(ls []Licence) string

SPDXExpression joins the licences of ls into one SPDX expression ("MIT AND Apache-2.0"); "unknown" becomes NOASSERTION.

func StoreHome

func StoreHome(ctx context.Context) string

StoreHome is the home WithStoreHome set ("" = none).

func StoreName

func StoreName(storePath string) (name, version string)

StoreName splits the name part of a store path the way Nix splits a derivation name: the version starts at the first "-" that is followed by a character other than a letter ("glibc-2.42-47" → "glibc", "2.42-47"; "nss-cacert-3.115" → "nss-cacert", "3.115").

func WithStoreHome

func WithStoreHome(ctx context.Context, home string) context.Context

WithStoreHome returns a context that tells ecosystems where bob's store lives on the host (the directory below which store path p is <home>/p). Native and Plan code that wants to read files of store outputs that already exist (compile_commands.json lists the include directories of nixpkgs libraries) maps the paths with it; without it, or when the file is not there, they use what they know without reading.

Types

type BuilderJob

type BuilderJob struct {
	Name    string // store name of the derivation
	System  string
	Builder string // bob-builder store path
	Kind    string // bob-builder subcommand
	Label   string // package label for log lines
	Args    any    // the kind's Args
	Fixup   *Fixup // nil: NoFixup
	Inputs  *Inputs
	Discard bool           // unsafeDiscardReferences.out (R-OUT-011)
	Attrs   map[string]any // further structured attributes (besides allowSubstitutes = false)
}

BuilderJob is one bob-builder job of a generator, before it is a derivation.

func (BuilderJob) Finalize

func (j BuilderJob) Finalize(r drv.Resolver) (string, *drv.Derivation, error)

Finalize turns the job into its finalised derivation and returns the derivation's path. The forbidden paths of the fixup are sorted and deduplicated in place; when there are any they are also the output's disallowed references.

type Codegen

type Codegen struct {
	Node *ir.Node
	Drv  *drv.Derivation
	Path string // drv path
	Out  string // its "out" store path
	Dir  string // owned directory, repository-relative
}

Codegen is the planned derivation of one codegen node: Drv builds Out, whose content becomes the owned directory Dir (repository-relative).

type DevPackage

type DevPackage struct {
	Name    string // "go", "gopls": the summary line of bob dev
	Version string // "1.26.8"; "" when unknown
	Path    string // store path whose bin/ goes on PATH
	Drv     string // the derivation that realises Path ("" when Path needs no realisation)
}

DevPackage is one top-level package of a dev shell.

type DevPrep

type DevPrep struct {
	// Packages are top-level packages whose bin/ goes on PATH inside, in this order (after
	// the dev shell's own Packages). Every executable in their bin/ gets a shim (§02.7.2).
	Packages []DevPackage
	// Env are variables of the dev shell. They are exported outside the namespace too when
	// their value references no store path (§02.7.2 outside rules); the dev shell's own Env
	// wins over them.
	Env map[string]string
	// InsideEnv are variables for inside the namespace only (GOROOT, GOTOOLCHAIN).
	InsideEnv map[string]string
	// ToolEnv are extra variables for single tools (tool name → variables), e.g. gopls's
	// GOFLAGS=-tags=bob (S1-7).
	ToolEnv map[string]map[string]string
	// Tools are in-tree tools (tool name → repo-relative path), e.g. node_modules/.bin/tsc.
	Tools map[string]string
	// Files are working-tree files tooling needs beyond the Native files (materialised
	// codegen, a dev-server wrapper config). bob writes them like Native files.
	Files []GeneratedFile
	// Servers are the dev servers of the requested Servers nodes.
	Servers []DevServerSpec
	// Drvs are derivations the ecosystem planned for the dev shell beyond the graph's own
	// (bob writes them to the store); Realise names derivations (of the graph's plan in
	// req.Inputs, or of Drvs) whose outputs must exist before tools run, e.g. proc-macro
	// dylibs and OUT_DIR trees named in rust-project.json, or local OCaml libraries.
	Drvs    []*drv.Derivation
	Realise []string
}

DevPrep is an ecosystem's share of a dev shell.

type DevPreparer

type DevPreparer interface {
	PrepareDev(ctx context.Context, req DevRequest) (DevPrep, error)
}

DevPreparer is implemented by an Ecosystem that contributes to developer environments (SPEC §02.7, R-DEV-001, R-DEV-002; §02 open item 10): its toolchain and tools on PATH, its variables, the working-tree files tooling needs, in-tree tools and dev servers. bob dev, bob env, the shell hook and editor settings call it for every registered ecosystem that owns nodes of the repository's graph. PrepareDev must be deterministic; it may look up nixpkgs attributes through req.Nixpkgs and fetch pinned inputs (req.Store).

type DevRequest

type DevRequest struct {
	// PlanRequest is a full plan request (as bob build's): the whole repository's graph, this
	// ecosystem's nodes, its lock section, the nixpkgs index, Builder, Sources, Resolver, and
	// Inputs holding every planned node of the graph (node id → derivation and outputs; the
	// derivations are in the store), so local libraries and generated code can be named.
	PlanRequest
	Shell   string   // the dev shell's name
	Servers []string // ids of this ecosystem's nodes the shell lists in DevShell.Servers
}

DevRequest asks an ecosystem for its share of one dev shell.

type DevServerSpec

type DevServerSpec struct {
	Name  string            // unique per shell, [a-z0-9-]: the log is .bob/dev/<name>.log
	Label string            // the package it serves
	Cmd   []string          // argv; a name without "/" is looked up on the dev shell's PATH
	Cwd   string            // repo-relative working directory
	Env   map[string]string // extra variables
	// Ready is how bob sees that the server is up: "http" = a TCP connect to Port succeeds,
	// "log" = Pattern (a Go regexp) matches a line of its output.
	Ready   string
	Port    int
	Host    string // for the readiness line; "" = localhost
	Pattern string
}

DevServerSpec is one dev server bob dev starts (§02.7.7 step 5, the §03 contract).

type DriftLine

type DriftLine struct {
	Op   string // "+" added outside bob, "-" removed outside bob, "~" changed
	Text string // e.g. "golang.org/x/text v0.20.0  (not declared in bob.go)"
	// Hint, when set, replaces BOB-E-1011's default hint ("move the change into bob.go"): the
	// difference is one bob.go cannot express, so the hint says what bob generates and why.
	Hint string
}

DriftLine is one difference between a generated file and the working tree, in bob.go terms.

type Ecosystem

type Ecosystem interface {
	Name() string // bob.lock section key; also the prefix of the ecosystem's node kinds
	Lock(ctx context.Context, req LockRequest) (json.RawMessage, error)
	Plan(ctx context.Context, req PlanRequest) (PlanResult, error)
	Native(ctx context.Context, req PlanRequest) ([]GeneratedFile, error)
}

Ecosystem is implemented by every ecosystem's generator package (SPEC R-FW-051, §03.0.1) and registered from its init with Register. It is never linked into the evaluator.

func Ecosystems

func Ecosystems() ([]Ecosystem, error)

Ecosystems returns the registered ecosystems sorted by name, or an error naming every broken registration.

func ForKind

func ForKind(kind string) (Ecosystem, bool)

ForKind returns the ecosystem that plans nodes of kind ("<name>.<kind>").

func Lookup

func Lookup(name string) (Ecosystem, bool)

Lookup returns the ecosystem registered under name.

type Event

type Event struct {
	Name string          // "package.finish", …
	Data json.RawMessage // the event object
}

Event is one --json event of a build (SPEC §02.4).

type Fixup

type Fixup struct {
	Strip       bool
	DebugOut    bool
	ShrinkRPath bool
	Forbidden   []string // store paths the output must not reference
	Tools       FixupTools
}

Fixup is the fixup contract of a job (R-NIX-019), bspec.Fixup's fields.

func NoFixup

func NoFixup() *Fixup

NoFixup is the contract of a job whose output is not an ELF tree bob controls: no stripping, no RUNPATH change, a reference check against nothing.

type FixupTools

type FixupTools struct {
	Strip, Objcopy, Patchelf string
}

FixupTools are the store paths of the fixup tools (bspec.FixupTools).

type GeneratedFile

type GeneratedFile struct {
	Path    string // repo-relative, clean, slash-separated
	Content []byte
	Mode    fs.FileMode // always 0o444 (bob writes 0444 whatever is set here)
	Owner   string      // label of the owning package
	// Committed marks a file that belongs in git (Go's go.mod and go.sum, R-FW-022). Every
	// other generated file is kept out of git by bob's block in .git/info/exclude.
	Committed bool
	// Explain maps the bytes found in the working tree to the differences in bob.go terms
	// (R-FW-061); nil: the drift error names the file only.
	Explain func(onDisk []byte) []DriftLine
}

GeneratedFile is one native tooling file an ecosystem writes (§03.0.2). bob writes it with mode 0444 and records its sha256 in .bob/state/native.json (R-FW-060).

type GoTarget

type GoTarget struct {
	Platform     bob.Platform // the target
	GOOS, GOARCH string
	CC, CXX      string // C and C++ compiler commands ("gcc", "x86_64-unknown-linux-gnu-gcc")
	Cross        bool
}

GoTarget is the Go side of the toolchain table (R-FW-033): the host's go with GOOS/GOARCH of the target; cgo and external links use the target's C compiler.

func GoFor

func GoFor(host, target bob.Platform) GoTarget

GoFor returns the Go settings that compile on host for target.

func (GoTarget) Env

func (g GoTarget) Env() map[string]string

Env is the environment the table names for a cross build (GOOS, GOARCH, CC, CXX); nil natively, where the defaults apply.

type Inputs

type Inputs struct {
	// contains filtered or unexported fields
}

Inputs collects the input derivations and input sources of one bob-builder job.

func NewInputs

func NewInputs(builder string) *Inputs

NewInputs returns a collector holding the bob-builder store path as a source.

func (*Inputs) Add

func (in *Inputs) Add(rv Resolved, o string) string

Add records output o of rv and returns its store path. An output rv does not have records nothing and returns "".

func (*Inputs) AddAll

func (in *Inputs) AddAll(rv Resolved)

AddAll records every output of rv.

func (*Inputs) AddCutoff

func (in *Inputs) AddCutoff(rv Resolved, o string) string

AddCutoff is Add for an input that may be a codegen output with early cutoff (§03.6.3): the job then depends on the content-addressed copy, not on the generating derivation.

func (*Inputs) AddDrv

func (in *Inputs) AddDrv(path string, outputs ...string)

AddDrv records outputs of the derivation at path.

func (*Inputs) AddSrc

func (in *Inputs) AddSrc(p string)

AddSrc records a plain store path.

func (*Inputs) List

func (in *Inputs) List() ([]drv.InputDrv, []string)

List returns the input derivations (by path, outputs sorted) and the sorted input sources.

func (*Inputs) Merge

func (in *Inputs) Merge(o *Inputs)

Merge records every input of o.

type Job

type Job struct {
	Name    string              // store name of the derivation
	Kind    string              // bob-builder subcommand
	Label   string              // package label for log lines
	Args    any                 // the kind's Args
	Drvs    map[string][]string // input derivation → outputs
	Srcs    []string            // input store paths (besides bob-builder)
	Discard bool                // unsafeDiscardReferences.out (R-OUT-011)
}

Job is one bob-builder job of an output generator.

type Jobs

type Jobs struct {
	Drvs []*drv.Derivation // in planning order
	// contains filtered or unexported fields
}

Jobs plans the bob-builder derivations of one output generator run (no fixup: output kinds keep their bytes exactly).

func NewJobs

func NewJobs(req PlanRequest) *Jobs

NewJobs returns an empty job set for req.

func (*Jobs) Add

func (j *Jobs) Add(jb Job) (drvPath, out string, err error)

Add finalises jb and records it; it returns the derivation's path and its "out" path.

func (*Jobs) Modulo

func (j *Jobs) Modulo(p string) ([32]byte, error)

Modulo resolves the derivations planned here first, then the engine's.

type Licence

type Licence struct {
	Path     string   `json:"path"`
	Name     string   `json:"name"`
	Version  string   `json:"version"`
	Licenses []string `json:"licenses"`
}

Licence is one entry of licences.json (R-OUT-008).

func Licences

func Licences(ctx context.Context, idx *nixidx.Index, paths []string, own map[string]Licence) []Licence

Licences returns the licences.json entries of paths, sorted by path. own holds the entries of paths bob built (name = package name, licence from the package, default "unknown"); every other path is looked up in nixpkgs by the name part of its store name (meta.license of the attribute of that name). A failed or missing lookup gives "unknown"; the lookup is best effort and never fails a build.

type LockFreshness

type LockFreshness interface {
	Stale(ctx context.Context, req LockRequest) (what string, at ir.Pos, err error)
}

LockFreshness is implemented by an Ecosystem whose lock section records the declarations it was resolved from (`inputs`, R-FW-062). Stale compares req.Prev (bob.lock's section; a missing section is locked on demand instead) with the declarations in req.Graph without network and without changing anything; it returns "" when the section is fresh, else what changed ("npm zod ^3 is not pinned") and the bob.go position of the changed declaration (zero when unknown). bob build, bob test and bob check report a stale section as BOB-E-1012; bob lock and --lock re-resolve it. An Ecosystem without this method is never reported stale.

type LockRequest

type LockRequest struct {
	Graph   *ir.Graph       // validated IR (all configurations)
	Prev    json.RawMessage // previous section, nil if none
	Update  []string        // names to move (bob lock --update), empty = keep pins
	Fetch   fetch.Fetcher
	Nixpkgs *nixidx.Index
	// Root is the repository root (working tree) the graph was evaluated from; "" when the
	// caller has none. Resolvers that follow source imports read it (Go: which modules provide
	// packages, R-GO-002b).
	Root string
	// Note prints one "note: …" line for the user (npm: install scripts bob does not run,
	// R-NPM-004); nil discards notes.
	Note func(msg string)
}

LockRequest asks an ecosystem to resolve its declarations (bob lock).

type Materialisation

type Materialisation struct {
	Dir    string // repo-relative owned directory ("web/node_modules")
	Label  string // the package whose output it is (bob gen patterns select by it)
	Drv    string // the derivation that builds Output
	Output string // store path of the tree that becomes Dir's content
	// Keep are top-level names inside Dir that belong to the user's tools and survive
	// (node_modules/.vite, node_modules/.cache).
	Keep []string
	// Record is a repo-relative file that receives Output's store path once Dir is up to date
	// (an npm importer's .bob/node_modules.path); "" for none.
	Record string
}

Materialisation is a planned output an ecosystem puts into the working tree (SPEC §03.6.6, R-FW-007): codegen output directories, an npm importer's node_modules (§03.4.3). After a local bob build, bob test or bob run, bob mirrors every valid one into Dir with the manifest protocol of pkg/engine/materialise; bob gen builds them first. Remote workers and pipeline runs never materialise.

type Materialiser

type Materialiser interface {
	Materialises(g *ir.Graph) bool
}

Materialiser is implemented by an Ecosystem whose Plan returns Materialisations (in PlanResult.Materialise). bob gen plans and builds the graph only when one of its ecosystems reports that g has something to materialise.

type PlanCloser

type PlanCloser interface {
	// Closure makes outs valid (bob derivations planned so far are built as RealiseNow does,
	// other derivations are substituted or built by Nix) and returns every path of their
	// closure with its references (without the path itself), sorted.
	Closure(ctx context.Context, outs []PlanOutput) (map[string][]string, error)
}

PlanCloser is an optional extension of PlanStore (a type assertion on PlanRequest.Store) for outputs that are built from closures (SPEC §04): an OCI image has one layer derivation per store path of its programs' closures (R-OUT-011), a static tarball must reject a program with run-time dependencies before anything is built (R-OUT-004), and pruning is checked against the ELF files of the closure (R-OUT-007).

type PlanOutput

type PlanOutput struct {
	Drv, Name, Path string
}

PlanOutput is one store output an ecosystem needs on disk while planning: Path is the output of the derivation Drv (its output Name). Drv is "" for a plain store path (a source).

func PrimaryOutputs

func PrimaryOutputs(n *ir.Node, rv Resolved) []PlanOutput

PrimaryOutputs returns the outputs a package contributes to a bundle as a root: every output a nixpkgs node names explicitly, else its "bin" output when it has one, else "out" (the programs of a nixpkgs package; dev, man and doc stay out); for bob packages "out".

type PlanRealiser

type PlanRealiser interface {
	// RealiseNow makes the derivations valid (with the bob derivations they need, planned by
	// this or earlier calls) and builds those whose outputs are not valid yet. It returns, per
	// derivation path, output name → path bob can read (HostPath). A failed build is an error;
	// the caller then plans without the cutoff and the build stage reports the failure.
	RealiseNow(ctx context.Context, drvs map[string]*drv.Derivation) (map[string]map[string]string, error)
}

PlanRealiser is an optional extension of PlanStore (a type assertion on PlanRequest.Store): building derivations while planning, for the early-cutoff modes (§03.6.3 codegen, R-GO-005 Go export data). An ecosystem builds what it planned so far, adds a part of the outputs to the store by content (ImportSources) and plans dependents against that path, so a byte-identical part rebuilds nothing downstream.

type PlanRequest

type PlanRequest struct {
	Graph *ir.Graph
	Nodes []*ir.Node      // this ecosystem's nodes (by kind prefix "<name>.")
	Lock  json.RawMessage // this ecosystem's section
	// Locks are all sections of bob.lock by key (read-only): a code generator that loads the
	// consumer's packages reads the consumer's section (gqlgen, the Go build list, §03.6.2).
	Locks   map[string]json.RawMessage
	Inputs  map[string]Resolved // node id → resolved deps: drv paths/outputs, store paths, LinkInfo
	Sources map[string]string   // node id → imported source store path (R-NIX-009)
	Nixpkgs *nixidx.Index
	Builder string // bob-builder store path for the host system
	// Resolver returns hashDerivationModulo of any derivation in Inputs (bob's own, nixpkgs'),
	// so Plan can Finalize derivations that depend on them.
	Resolver drv.Resolver
	// TestArgs are the arguments after `--` of bob test; they become part of every test unit
	// planned here (so its result is cached per argument set).
	TestArgs []string
	// Root is the repository root (working tree) the graph was evaluated from (also in Native;
	// "" when the caller has none).
	Root string
	// Store gives Plan the store access it may need: reading store paths, importing source
	// trees it selected itself, realising pinned inputs it must read (planstore.go). nil in
	// Native and wherever the caller has no store.
	Store PlanStore
	// FrameworkSum holds the go.sum lines of the framework module that bob serves at its own
	// version (Native only; the root go.mod requires the framework, R-FW-043.4).
	FrameworkSum string
	// Version is the release version of this build (bob build --version, "0.0.0-dev" without
	// one). Only release-related derivations may depend on it (R-OUT-022): the release manifest
	// and the versioned image a release publishes; every other package must ignore it.
	Version string
}

PlanRequest asks an ecosystem for the derivations of its nodes. Plan must be deterministic and run no processes.

type PlanResult

type PlanResult struct {
	Drvs    []*drv.Derivation   // new derivations, any order (bob sorts topologically)
	Nodes   map[string]Resolved // node id → its outputs and, for Linkables, filled LinkInfo
	Fetches []fetch.Request     // external inputs; the fetcher makes their paths valid before nix build
	// Materialise are outputs of this plan bob puts into the working tree (host platform only).
	Materialise []Materialisation
}

PlanResult is what Plan returns.

type PlanStore

type PlanStore interface {
	// HostPath returns where bob can read the store path p: p itself inside bob's namespace,
	// else the same path below the store's home.
	HostPath(p string) string
	// ImportSources imports trees (files of the working tree or of readable store paths) as
	// content-addressed source paths (R-NIX-009, srcs.Import) and returns their store paths
	// in order. Trees that are already valid cost one batched validity query.
	ImportSources(ctx context.Context, trees []srcs.Source) ([]string, error)
	// Ensure makes a pinned external input valid and returns its store path (the fetcher's
	// Ensure: store, substituters, origin). It never runs a Nix fixed-output build.
	Ensure(ctx context.Context, r fetch.Request) (string, error)
}

PlanStore is the store access an ecosystem may use while planning (PlanRequest.Store). The build fills it from its store and fetcher. Ecosystems that decide their own source sets while planning need it: Go reads the files of each package and imports one source path per workspace package (R-GO-002a), and reads third-party module trees before planning them (two phases, S2-2).

type Pruning

type Pruning struct {
	// Skip lists, per store path, the entries removed from the bundle's copy (absolute
	// /nix/store/... paths; a removed directory stands for its whole subtree), sorted.
	Skip map[string][]string
	// Used lists, per store path, the patterns that removed something from it (in pattern order).
	Used map[string][]string
	// contains filtered or unexported fields
}

Pruning is the result of applying prune patterns to the files of a closure.

func Prune

func Prune(st PlanStore, paths, patterns []string) (*Pruning, error)

Prune applies patterns to the files of paths, read through st (host paths). The store paths themselves are never modified; only the bundle's copy leaves the entries out (R-OUT-007).

type RemoteExecutor

type RemoteExecutor interface {
	Build(ctx context.Context, req RemoteRequest) (<-chan Event, error)
}

RemoteExecutor runs a build elsewhere and makes the outputs available locally (bob build --remote).

type RemoteRequest

type RemoteRequest struct {
	Root      string
	Patterns  []string
	Platforms []bob.Platform
	Variants  []string
	Test      bool   // bob test --remote: the patterns name tests
	Version   string // release version (bob build --remote --version, R-OUT-022); "" = none
}

RemoteRequest is one remote build (SPEC §02.6).

type Resolved

type Resolved struct {
	Drv         string            // drv path ("" for plain store paths)
	Outputs     map[string]string // output name → store path
	LinkInfo    *bob.LinkInfo
	MainProgram string
	// Cutoff maps an output name to a content-addressed copy of that output (codegen early
	// cutoff, §03.6.3): consumers depend on that store path (an input source) instead of on
	// Drv, so a byte-identical regeneration rebuilds nothing downstream. Nil for most nodes.
	Cutoff map[string]string
}

Resolved is a node's outputs after planning.

type RustTarget

type RustTarget struct {
	Triple    string // target triple, also natively ("aarch64-unknown-linux-gnu")
	Cross     bool
	StdAttr   string // nixpkgs attribute of the rustc whose lib/rustlib/<Triple> is the target std
	StdSystem string // Nix system of the package set StdAttr is taken from
	Linker    string // linker command ("x86_64-unknown-linux-gnu-cc"; "cc" natively)
	StdName   string // derivation name of the target std ("rust-std-x86_64-unknown-linux-gnu")
}

RustTarget is the Rust side of the toolchain table (R-FW-033, R-FW-034): the host's rustc; for a cross target with --target Triple, a sysroot holding the target's standard library copied from the target system's own rustc (StdAttr in the package set of StdSystem), and the cross C compiler as linker.

func RustFor

func RustFor(host, target bob.Platform) RustTarget

RustFor returns the Rust settings that compile on host for target. Rust host units (proc-macros, build-script compiles) always use RustFor(host, host) (R-FW-035).

type Substituter

type Substituter struct{ URL, PublicKey, NetrcMachine, NetrcPassword string }

Substituter is a binary cache bob passes to Nix (URL, public key, optional netrc credential).

type Versions

type Versions struct {
	Glibc string `json:"glibc"`
	Rustc string `json:"rustc"`
}

Versions are the facts the nixpkgs consistency pre-check compares (R-PLAT-007).

func TestVersions

func TestVersions() (native, cross Versions, ok bool, err error)

TestVersions reads the file named by TestIndexEnv; ok is false when it is not set.

Directories

Path Synopsis
Package build runs the whole build pipeline from patterns to outputs.
Package build runs the whole build pipeline from patterns to outputs.
testrun
Package testrun is the engine side of `bob test` (SPEC §03.0.5, R-FW-024, R-FW-064, O-02-9): it finds the test units among the planned derivations, decides which results are cached, makes rerun derivations and reads the results the builder's test-run kind wrote.
Package testrun is the engine side of `bob test` (SPEC §03.0.5, R-FW-024, R-FW-064, O-02-9): it finds the test units among the planned derivations, decides which results are cached, makes rerun derivations and reads the results the builder's test-run kind wrote.
Package drv computes Nix derivations, store paths and fixed-output paths.
Package drv computes Nix derivations, store paths and fixed-output paths.
Package eval generates and runs the bob.go evaluator in its sandbox.
Package eval generates and runs the bob.go evaluator in its sandbox.
evalbox
Package evalbox is the evaluator sandbox of SPEC R-FW-045 (S13 evalbox, ADR 0015): it runs the compile and run steps of a bob.go evaluation, locally and on workers, inside
Package evalbox is the evaluator sandbox of SPEC R-FW-045 (S13 evalbox, ADR 0015): it runs the compile and run steps of a bob.go evaluation, locally and on workers, inside
Package fetch downloads and verifies sources and adds them to the store.
Package fetch downloads and verifies sources and adds them to the store.
Package ir defines and validates the graph IR v1.
Package ir defines and validates the graph IR v1.
Package lock reads and writes bob.lock.
Package lock reads and writes bob.lock.
Package materialise puts build outputs into the working tree (SPEC §03.6.6, R-FW-007, R-FW-066, R-FW-067): codegen output directories and an npm importer's node_modules (§03.4.3).
Package materialise puts build outputs into the working tree (SPEC §03.6.6, R-FW-007, R-FW-066, R-FW-067): codegen output directories and an npm importer's node_modules (§03.4.3).
Package nar reads and writes NAR archives.
Package nar reads and writes NAR archives.
Package nixidx looks up packages in the nixpkgs index.
Package nixidx looks up packages in the nixpkgs index.
goname
Package goname is the naming rule of bob's typed nixpkgs surface (ADR 0020 §2), shared by the pin check of pkg/engine/nixidx and the generator cmd/nixpkgsgen.
Package goname is the naming rule of bob's typed nixpkgs surface (ADR 0020 §2), shared by the pin check of pkg/engine/nixidx and the generator cmd/nixpkgsgen.
Package pcflags is bob's small pkg-config for nixpkgs libraries and Externals (an E0 engine primitive: the builder and the generators may both import it, R-ARCH-003).
Package pcflags is bob's small pkg-config for nixpkgs libraries and Externals (an E0 engine primitive: the builder and the generators may both import it, R-ARCH-003).
Package srcs imports repository sources into the store.
Package srcs imports repository sources into the store.
Package store runs the embedded rootless Nix store.
Package store runs the embedded rootless Nix store.
Package translate turns Nix's `--log-format internal-json` stream into bob diagnostics (ADR 0017, SPEC R-NIX-010, R-NIX-012).
Package translate turns Nix's `--log-format internal-json` stream into bob diagnostics (ADR 0017, SPEC R-NIX-010, R-NIX-012).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL