aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-14 01:49:56 +0000
committertv <tv@krebsco.de>2026-11-14 01:49:56 +0000
commitf46bb7f2a5dbdcd0098904654f7d8742dc111c01 (patch)
treef1d3a091e5ac2302a93456025552b10fc6f550f0 /tests
parent31e6c94a174bc2a1f4db3a18b4365482307b1fa8 (diff)
populate: tell whether a Git work tree drawn from changed by its commit
Whether a derived copy of a flake or flake-input source needs to be made again depends on the sources it draws inputs from. For one that isn't in the store, the key had its hash, so every run read all of it, e.g. all of a nixpkgs work tree, .git included, which takes long even when nothing changed. For a Git work tree that Nix gets as git+file:, whose commit and tracked files are all Nix uses, the key has its commit instead, if no tracked file differs from it, which Git tells quickly. git_flake decides what Nix gets as git+file:, for flake_url as well. Keys of copies drawing from such work trees change once, so those copies get made again on the first run. The keys are the same as krops 2's. rewrite-cache-git checks that such a copy gets made again for a new commit, but not for redeploying, nor for an untracked file.
Diffstat (limited to 'tests')
-rw-r--r--tests/scenarios.nix61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/scenarios.nix b/tests/scenarios.nix
index 2a092aa..3426b92 100644
--- a/tests/scenarios.nix
+++ b/tests/scenarios.nix
@@ -1010,6 +1010,67 @@ assert !(krops.isLocalTarget (targets.remote "/"));
}
];
}))
+ # A copy with a rewritten lock file that draws an input from a Git work
+ # tree, which Nix gets as git+file:, gets made again only when the
+ # commit or the tracked files change, not for an untracked file, which
+ # Nix doesn't see. The source is a file source keeping its .git.
+ (s "rewrite-cache-git" (let
+ sources = {
+ x.flake-input = {
+ url = "/fixtures/top"; name = "dep"; inherit fetchOnTarget;
+ inputs.inner.follows = "a";
+ };
+ a.file = "/tmp/rewrite-cache-git";
+ };
+ copyKept = ''
+ expect_eq "store path" "$(readlink "$T"/x)" "$(cat "$T".first)"
+ expect_eq "copy made at" "$(stat -c %y "$T"/.populate/derived/x/key)" "$(cat "$T".key)"
+ '';
+ in {
+ prepareDeployer = ''
+ rm -fR /tmp/rewrite-cache-git
+ mkdir /tmp/rewrite-cache-git
+ cd /tmp/rewrite-cache-git
+ echo '{ outputs = _: { greeting = "altgit"; }; }' > flake.nix
+ git init -q
+ git add flake.nix
+ git -c user.name=krops -c user.email=spam@krebsco.de commit -q -m altgit
+ '';
+ phases = [
+ {
+ inherit sources;
+ check = checkFlake { attr = "greeting"; expected = "dep+altgit"; };
+ mutate = ''
+ readlink "$T"/x > "$T".first
+ stat -c %y "$T"/.populate/derived/x/key > "$T".key
+ '';
+ }
+ {
+ inherit sources;
+ check = copyKept;
+ mutateDeployer = ''
+ echo untracked > /tmp/rewrite-cache-git/untracked
+ '';
+ }
+ {
+ inherit sources;
+ check = copyKept + ''
+ test -e "$T"/a/untracked || fail "a/untracked missing"
+ '';
+ mutateDeployer = ''
+ cd /tmp/rewrite-cache-git
+ echo '{ outputs = _: { greeting = "altgit2"; }; }' > flake.nix
+ git -c user.name=krops -c user.email=spam@krebsco.de commit -q -a -m altgit2
+ '';
+ }
+ {
+ inherit sources;
+ check = checkFlake { attr = "greeting"; expected = "dep+altgit2"; } + ''
+ test "$(readlink "$T"/x)" != "$(cat "$T".first)" || fail "store path unchanged"
+ '';
+ }
+ ];
+ }))
# A materialized input is a writable copy, patched and with a rewritten
# lock file, which gets made again only when what it derives from
# changes, and becomes a link again when not materialized anymore.