| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | ) |
| 7 | |
| 8 | // cmdInputs prints the input-closure digest of one or more pure checks over |
| 9 | // a revision's tree, without building anything. |
| 10 | // |
| 11 | // This is what an integrator needs and a contributor does not. The pure |
| 12 | // transfer rule of dcr-439b771 is closure-digest equality: the integrator |
| 13 | // recomputes each required check's closure over the rebased tree and |
| 14 | // compares it with the digest the attestation recorded. Equality means the |
| 15 | // rebased tree presents the same computation over the same inputs, so the |
| 16 | // recorded result is the result on the new base too. Inequality means that |
| 17 | // check, and only that check, is stale. |
| 18 | // |
| 19 | // Evaluating rather than building is the point. The serialized critical |
| 20 | // section at the commit point is digest comparison and a ref write; check |
| 21 | // latency never enters it. |
| 22 | func cmdInputs(args []string) error { |
| 23 | fs := newFlagSet("inputs") |
| 24 | repo := fs.String("repo", "", "repository") |
| 25 | rev := fs.String("rev", "HEAD", "revision") |
| 26 | system := fs.String("system", nixSystem(), "flake system") |
| 27 | var checks repeatable |
| 28 | fs.Var(&checks, "check", "flake check to digest") |
| 29 | if err := fs.Parse(args); err != nil { |
| 30 | return err |
| 31 | } |
| 32 | root, err := repoRoot(*repo) |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | |
| 37 | tree, err := os.MkdirTemp("", "valley-attest-inputs") |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | defer os.RemoveAll(tree) |
| 42 | if err := exportTree(root, *rev, tree); err != nil { |
| 43 | return err |
| 44 | } |
| 45 | |
| 46 | specs, err := checkSpecs(tree, *system, checks, nil) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | for _, spec := range specs { |
| 51 | if spec.runner() != "nix" { |
| 52 | return fmt.Errorf("%s is a %s check; only a pure check has an input closure", spec.name, spec.runner()) |
| 53 | } |
| 54 | c, err := evalClosure(tree, *system, spec) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | fmt.Printf("%s %s:%s sha256:%s\n", spec.name, inputsScheme, c.inputs, c.derivation) |
| 59 | } |
| 60 | return nil |
| 61 | } |