aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/tests
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-14 01:24:34 +0000
committertv <tv@krebsco.de>2026-11-14 02:45:43 +0100
commit361b504079389cfd6f8cf3160da96b88cc5e5a69 (patch)
treea74d65e8365b9244211057aaeac144de83bae546 /pkgs/populate/tests
parente4991d754160dd851b980f142e4b9a23815eafa3 (diff)
populate: tell whether a Git work tree drawn from changed by its commitHEADmaster
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 resolve as well. Keys of copies drawing from such work trees change once, so those copies get made again on the first run, also after deploying with krops 1. 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 'pkgs/populate/tests')
-rw-r--r--pkgs/populate/tests/scenarios.nix61
1 files changed, 61 insertions, 0 deletions
diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix
index d00ebcb..d50cf19 100644
--- a/pkgs/populate/tests/scenarios.nix
+++ b/pkgs/populate/tests/scenarios.nix
@@ -675,6 +675,67 @@ with import ./builder.nix args;
}
];
}))
+ # 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.