2021-11-05 16:17:49 +01:00
|
|
|
|
source common.sh
|
|
|
|
|
|
2022-07-13 20:51:28 +02:00
|
|
|
|
cp ../simple.nix ../simple.builder.sh ../config.nix $TEST_HOME
|
2021-11-05 16:17:49 +01:00
|
|
|
|
|
|
|
|
|
cd $TEST_HOME
|
|
|
|
|
|
|
|
|
|
rm -f post-hook-ran
|
|
|
|
|
cat <<EOF > echoing-post-hook.sh
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
2021-11-12 16:28:39 +01:00
|
|
|
|
echo "ThePostHookRan as \$0" > $PWD/post-hook-ran
|
2021-11-05 16:17:49 +01:00
|
|
|
|
EOF
|
|
|
|
|
chmod +x echoing-post-hook.sh
|
|
|
|
|
|
|
|
|
|
cat <<EOF > flake.nix
|
|
|
|
|
{
|
2021-11-12 16:28:39 +01:00
|
|
|
|
nixConfig.post-build-hook = ./echoing-post-hook.sh;
|
2021-12-14 09:15:24 +01:00
|
|
|
|
nixConfig.allow-dirty = false; # See #5621
|
2021-11-05 16:17:49 +01:00
|
|
|
|
|
|
|
|
|
outputs = a: {
|
2022-02-11 18:11:08 +01:00
|
|
|
|
packages.$system.default = import ./simple.nix;
|
2021-11-05 16:17:49 +01:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
EOF
|
|
|
|
|
|
2021-11-18 13:32:52 +01:00
|
|
|
|
# Without --accept-flake-config, the post hook should not run.
|
|
|
|
|
nix build < /dev/null
|
|
|
|
|
(! [[ -f post-hook-ran ]])
|
|
|
|
|
clearStore
|
|
|
|
|
|
2024-06-29 20:23:17 +02:00
|
|
|
|
# likewise with no-accept-flake-config
|
|
|
|
|
nix build --no-accept-flake-config
|
|
|
|
|
(! [[ -f post-hook-ran ]])
|
|
|
|
|
clearStore
|
|
|
|
|
|
2021-11-12 16:02:32 +01:00
|
|
|
|
nix build --accept-flake-config
|
2021-11-05 16:17:49 +01:00
|
|
|
|
test -f post-hook-ran || fail "The post hook should have ran"
|
2021-11-12 16:28:39 +01:00
|
|
|
|
|
|
|
|
|
# Make sure that the path to the post hook doesn’t change if we change
|
|
|
|
|
# something in the flake.
|
|
|
|
|
# Otherwise the user would have to re-validate the setting each time.
|
|
|
|
|
mv post-hook-ran previous-post-hook-run
|
|
|
|
|
echo "# Dummy comment" >> flake.nix
|
|
|
|
|
clearStore
|
|
|
|
|
nix build --accept-flake-config
|
|
|
|
|
diff -q post-hook-ran previous-post-hook-run || \
|
|
|
|
|
fail "Both post hook runs should report the same filename"
|