From 7e4597a38a29f66fd8bbc7415973caeaa9442bde Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 02:33:17 +0000 Subject: populate: file sources' record setting, for provenance in the run record A consumer recording what a build used gets the commit of git sources, and the store paths of flake, flake-input, and derivation sources, but nothing for file sources, which often hold the configuration, taken from work trees on the deploying machine. Recording nothing about them stays the default, since they may hold secrets, whose hash could give them away. file sources' record setting, with flags that default to false, adds to the source's entry in the record: - commit: if path is in a Git work tree, the commit HEAD names, and dirty, whether git status lists anything in path. Git runs on the deploying machine, without hooks, file system monitors, and writing the index, on every run, which is cheap: a new commit can change HEAD without changing any file. - digest: what nix-hash --type sha256 --sri prints for the target path, after the flakes step, which may have rewritten its lock file. That takes reading all of it, so populate only computes it if the source changed since the last record, and else takes it from that record, which the command taking the lock prints, so a run that changes nothing reads nothing more. The record's format stays version 0: the fields are optional additions. The README documents that the record tells what populate delivered, which something changing the target directory meanwhile would make it miss, and how rsync can leave out much of what Git ignores, with :- .gitignore in a .rsync-filter file, and what that misses. record-file checks the commit, dirty, and the digest, also taken from the last record. --- pkgs/populate/src/sh.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'pkgs/populate/src/sh.rs') diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs index 3df2cc4..040ec0a 100644 --- a/pkgs/populate/src/sh.rs +++ b/pkgs/populate/src/sh.rs @@ -154,11 +154,13 @@ fi /// lock SENTINEL NAME ENTRY: waits for an exclusive lock on SENTINEL/lock, /// prints what's in SENTINEL/journal, which is there if a run didn't -/// finish, appends ENTRY to it, and prints locked. Then it keeps the lock -/// until its standard input ends, which consumers of the target directory -/// can wait for by taking a shared lock. NAME is the sentinel's name in -/// messages. Writing to a symlink in place of the lock or the journal -/// would write to what it points to, so it refuses those. +/// finish, appends ENTRY to it, prints record and what's in +/// SENTINEL/run.json, the last run's record, if any, and prints locked. +/// Then it keeps the lock until its standard input ends, which consumers +/// of the target directory can wait for by taking a shared lock. NAME is +/// the sentinel's name in messages. Writing to a symlink in place of the +/// lock or the journal would write to what it points to, so it refuses +/// those. pub const LOCK: &str = r#" sentinel=$1 name=$2 entry=$3 for file in lock journal; do @@ -177,6 +179,10 @@ if test -f "$sentinel"/journal; then cat "$sentinel"/journal fi printf '%s\n' "$entry" >> "$sentinel"/journal +echo record +if test -f "$sentinel"/run.json; then + cat "$sentinel"/run.json +fi echo locked exec cat >/dev/null "#; @@ -193,6 +199,14 @@ mv -f "$tmp" "$sentinel"/run.json rm -f "$sentinel"/journal "#; +/// digests PATH...: prints the hash of what's at each PATH, as Nix hashes +/// store paths, in SRI format, on lines of their own. +pub const DIGESTS: &str = r#" +for path; do + nix-hash --type sha256 --sri "$path" +done +"#; + /// The shell code adding the lines a command gets before its own arguments /// to the journal: the journal's path, the number of lines, and the lines. pub const JOURNAL: &str = r#" @@ -312,8 +326,9 @@ fi /// which names another repository, no linked work trees, and only the /// configuration they write: the repository's format, the remote, branches, /// and submodules, whose repositories have their work tree in the work -/// tree. Hooks don't matter: populate's Git doesn't run them. And each .git below the work tree, which Git uses for a -/// submodule there, is a file naming a repository in .git/modules. +/// tree. Hooks don't matter: populate's Git doesn't run them. And each +/// .git below the work tree, which Git uses for a submodule there, is a +/// file naming a repository in .git/modules. pub const GIT_PROBLEMS: &str = r#" git_problems() ( path=$1 -- cgit v1.3.1