2024-05-28 19:43:04 +03:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2021-11-05 17:17:49 +02:00
|
|
|
|
source common.sh
|
|
|
|
|
|
2024-11-01 15:56:50 +02:00
|
|
|
|
cp ../simple.nix ../simple.builder.sh "${config_nix}" $TEST_HOME
|
2021-11-05 17:17:49 +02:00
|
|
|
|
|
|
|
|
|
cd $TEST_HOME
|
|
|
|
|
|
|
|
|
|
rm -f post-hook-ran
|
|
|
|
|
cat <<EOF > echoing-post-hook.sh
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
2021-11-12 17:28:39 +02:00
|
|
|
|
echo "ThePostHookRan as \$0" > $PWD/post-hook-ran
|
2021-11-05 17:17:49 +02:00
|
|
|
|
EOF
|
|
|
|
|
chmod +x echoing-post-hook.sh
|
|
|
|
|
|
|
|
|
|
cat <<EOF > flake.nix
|
|
|
|
|
{
|
2021-11-12 17:28:39 +02:00
|
|
|
|
nixConfig.post-build-hook = ./echoing-post-hook.sh;
|
2021-12-14 10:15:24 +02:00
|
|
|
|
nixConfig.allow-dirty = false; # See #5621
|
2021-11-05 17:17:49 +02:00
|
|
|
|
|
|
|
|
|
outputs = a: {
|
2022-02-11 19:11:08 +02:00
|
|
|
|
packages.$system.default = import ./simple.nix;
|
2021-11-05 17:17:49 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
EOF
|
|
|
|
|
|
2021-11-18 14:32:52 +02:00
|
|
|
|
# Without --accept-flake-config, the post hook should not run.
|
2024-11-06 16:05:32 +02:00
|
|
|
|
# To test variations in stderr tty-ness, we run the command in different ways,
|
|
|
|
|
# none of which should block on stdin or accept the `nixConfig`s.
|
2021-11-18 14:32:52 +02:00
|
|
|
|
nix build < /dev/null
|
2024-11-06 16:05:32 +02:00
|
|
|
|
nix build < /dev/null 2>&1 | cat
|
|
|
|
|
# EOF counts as no, even when interactive (throw EOF error before)
|
|
|
|
|
if type -p script >/dev/null && script -q -c true /dev/null; then
|
|
|
|
|
echo "script is available and GNU-like, so we can ensure a tty"
|
|
|
|
|
script -q -c 'nix build < /dev/null' /dev/null
|
|
|
|
|
else
|
|
|
|
|
echo "script is not available or not GNU-like, so we skip testing with an added tty"
|
|
|
|
|
fi
|
2021-11-18 14:32:52 +02:00
|
|
|
|
(! [[ -f post-hook-ran ]])
|
2024-06-16 13:51:46 +03:00
|
|
|
|
TODO_NixOS
|
2021-11-18 14:32:52 +02:00
|
|
|
|
clearStore
|
|
|
|
|
|
2021-11-12 17:02:32 +02:00
|
|
|
|
nix build --accept-flake-config
|
2021-11-05 17:17:49 +02:00
|
|
|
|
test -f post-hook-ran || fail "The post hook should have ran"
|
2021-11-12 17:28:39 +02: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"
|