aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-13 21:26:00 +0000
committertv <tv@krebsco.de>2026-11-13 22:35:59 +0100
commit80d5426c3a5ed621c650cd1928f1eb1cafdb1b7a (patch)
treee463c8193d9d24e810d1071ae66ea85dc300272c /tests
parenta74582d4f1563c1251f34002c12feffe4a3e5200 (diff)
tests: a hook in a flake populate locks
lock-hooks plants a .git in a file source that keeps it, with configuration a git source would use, but a post-index-change hook, which Nix's Git runs when it adds the lock file it writes into a git+file: flake. Drawing inputs refers to that flake as path:, so the hook doesn't run. (cherry picked from commit 6b2491a410dfb7ffb33b15280a5861d4ab67e1da)
Diffstat (limited to 'tests')
-rw-r--r--tests/scenarios.nix42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/scenarios.nix b/tests/scenarios.nix
index 8c532b6..2a092aa 100644
--- a/tests/scenarios.nix
+++ b/tests/scenarios.nix
@@ -2312,6 +2312,48 @@ assert !(krops.isLocalTarget (targets.remote "/"));
}
];
}))
+ # A .git that a file source keeps, with configuration a git source would
+ # use, but a hook, which Nix's Git runs when it adds the lock file it
+ # writes: populate's Git runs none, so git sources keep hooks, but
+ # drawing inputs refers to the flake as path:.
+ (s "lock-hooks" (let
+ elsewhere = "/var/krops-elsewhere";
+ sources = alt // {
+ y.file = {
+ path = "/fixtures/filesrc";
+ deleteExcluded = false;
+ filters = [ { type = "exclude"; pattern = "/.git"; } ];
+ inputs.dep.follows = "alt";
+ };
+ };
+ in {
+ isolate = true;
+ prepare = ''
+ rm -fR ${elsewhere}
+ mkdir -p ${elsewhere}
+ '';
+ phases = [
+ {
+ inherit sources;
+ # A repository tracking only flake.nix, so Nix adds the lock file,
+ # which runs post-index-change.
+ mutate = ''
+ git -C "$T"/y init -q
+ git -C "$T"/y add flake.nix
+ git -C "$T"/y -c user.name=x -c user.email=x@x commit -q -m x
+ printf '#! /bin/sh\ntouch ${elsewhere}/ran\n' > "$T"/y/.git/hooks/post-index-change
+ chmod +x "$T"/y/.git/hooks/post-index-change
+ '';
+ }
+ {
+ inherit sources;
+ check = ''
+ test ! -e ${elsewhere}/ran || fail "a hook in a .git directory ran"
+ test -e "$T"/y/flake.lock || fail "y/flake.lock missing"
+ '';
+ }
+ ];
+ }))
# A file in populate's state replaced by a symlink to a file outside.
(s "state-key" (let
sources.x.flake-input = {