| 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. Every check asked for is |
| 10 | // evaluated in one nix evaluation where it can be (evalClosures). |
| 11 | // |
| 12 | // This is what an integrator needs and a contributor does not. The pure |
| 13 | // transfer rule of dcr-439b771 is closure-digest equality: the integrator |
| 14 | // recomputes each required check's closure over the rebased tree and |
| 15 | // compares it with the digest the attestation recorded. Equality means the |
| 16 | // rebased tree presents the same computation over the same inputs, so the |
| 17 | // recorded result is the result on the new base too. Inequality means that |
| 18 | // check, and only that check, is stale. |
| 19 | // |
| 20 | // Evaluating rather than building is the point. The serialized critical |
| 21 | // section at the commit point is digest comparison and a ref write; check |
| 22 | // latency never enters it. |
| 23 | func cmdInputs(args []string) error { |
| 24 | fs := newFlagSet("inputs") |
| 25 | repo := fs.String("repo", "", "repository") |
| 26 | rev := fs.String("rev", "HEAD", "revision") |
| 27 | system := fs.String("system", nixSystem(), "flake system") |
| 28 | var checks repeatable |
| 29 | fs.Var(&checks, "check", "flake check to digest") |
| 30 | if err := fs.Parse(args); err != nil { |
| 31 | return err |
| 32 | } |
| 33 | root, err := repoRoot(*repo) |
| 34 | if err != nil { |
| 35 | return err |
| 36 | } |
| 37 | |
| 38 | tree, err := os.MkdirTemp("", "valley-attest-inputs") |
| 39 | if err != nil { |
| 40 | return err |
| 41 | } |
| 42 | defer os.RemoveAll(tree) |
| 43 | if err := exportTree(root, *rev, tree); err != nil { |
| 44 | return err |
| 45 | } |
| 46 | |
| 47 | specs, err := checkSpecs(tree, *system, checks, nil) |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | // The checks are evaluated together, and printed in the order asked |
| 52 | // for, up to the first that did not evaluate. Its error ends the |
| 53 | // command, as when each check was evaluated in turn. |
| 54 | evals, _ := evalClosures(tree, *system, specs, nil) |
| 55 | for i, e := range evals { |
| 56 | if e.err != nil { |
| 57 | return e.err |
| 58 | } |
| 59 | fmt.Printf("%s %s:%s sha256:%s\n", specs[i].name, inputsScheme, e.inputs, e.derivation) |
| 60 | } |
| 61 | return nil |
| 62 | } |