aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/tests
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 02:33:17 +0000
committertv <tv@krebsco.de>2026-11-20 02:33:17 +0000
commit7e4597a38a29f66fd8bbc7415973caeaa9442bde (patch)
treed730cc0db0bb3fdb5db9e977a996dbccc5fedbfc /pkgs/populate/tests
parent7837a236e728988fcd501917444828b790c367f9 (diff)
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.
Diffstat (limited to 'pkgs/populate/tests')
-rw-r--r--pkgs/populate/tests/scenarios.nix49
1 files changed, 49 insertions, 0 deletions
diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix
index fbcae73..33a2171 100644
--- a/pkgs/populate/tests/scenarios.nix
+++ b/pkgs/populate/tests/scenarios.nix
@@ -870,6 +870,55 @@ in
}
];
}))
+ # A file source's record setting: the commit of the Git work tree, and
+ # whether it's dirty, on every run, and the digest, computed when the
+ # source changed, and else taken from the last record.
+ (s "record-file" (let
+ sources.x.file = {
+ path = "/tmp/record-file";
+ record = { commit = true; digest = true; };
+ };
+ digest = ''
+ expect_eq digest "$(record sources.x.digest)" \
+ "\"$(nix-hash --type sha256 --sri "$T"/x)\""
+ '';
+ in {
+ prepareDeployer = ''
+ rm -fR /tmp/record-file
+ git init -q /tmp/record-file
+ echo a > /tmp/record-file/a
+ git -C /tmp/record-file add a
+ git -C /tmp/record-file -c user.name=krops -c user.email=spam@krebsco.de \
+ commit -q -m a
+ '';
+ phases = [
+ {
+ inherit sources;
+ check = digest + ''
+ expect_eq dirty "$(record sources.x.dirty)" false
+ record sources.x.commit > "$T".commit
+ grep -Eqx '"[0-9a-f]{40}"' "$T".commit || fail "no commit"
+ '';
+ }
+ {
+ inherit sources;
+ check = digest + ''
+ expect_eq changed "$(record sources.x.changed)" false
+ '';
+ mutateDeployer = ''
+ echo b > /tmp/record-file/b
+ '';
+ }
+ {
+ inherit sources;
+ check = digest + ''
+ expect_eq changed "$(record sources.x.changed)" true
+ expect_eq dirty "$(record sources.x.dirty)" true
+ expect_eq commit "$(record sources.x.commit)" "$(cat "$T".commit)"
+ '';
+ }
+ ];
+ }))
# A consumer of the target directory holding a shared lock delays the
# next run.
(s "lock" {