2024-05-28 16:43:04 +00:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2022-07-13 12:09:35 +00:00
|
|
|
|
source ../common.sh
|
2022-03-25 17:36:41 +00:00
|
|
|
|
|
2024-06-16 10:51:46 +00:00
|
|
|
|
TODO_NixOS
|
|
|
|
|
|
2022-03-25 17:36:41 +00:00
|
|
|
|
clearStore
|
|
|
|
|
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
|
2024-11-01 13:56:50 +00:00
|
|
|
|
|
|
|
|
|
cp ../shell-hello.nix "${config_nix}" $TEST_HOME
|
2022-03-25 17:36:41 +00:00
|
|
|
|
cd $TEST_HOME
|
|
|
|
|
|
|
|
|
|
cat <<EOF > flake.nix
|
|
|
|
|
{
|
|
|
|
|
outputs = {self}: {
|
2022-04-19 10:09:12 +00:00
|
|
|
|
packages.$system.pkgAsPkg = (import ./shell-hello.nix).hello;
|
|
|
|
|
packages.$system.appAsApp = self.packages.$system.appAsApp;
|
2022-03-25 17:36:41 +00:00
|
|
|
|
|
2022-04-19 10:09:12 +00:00
|
|
|
|
apps.$system.pkgAsApp = self.packages.$system.pkgAsPkg;
|
|
|
|
|
apps.$system.appAsApp = {
|
2022-03-25 17:36:41 +00:00
|
|
|
|
type = "app";
|
|
|
|
|
program = "\${(import ./shell-hello.nix).hello}/bin/hello";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
EOF
|
2022-04-19 10:09:12 +00:00
|
|
|
|
nix run --no-write-lock-file .#appAsApp
|
|
|
|
|
nix run --no-write-lock-file .#pkgAsPkg
|
2022-03-25 17:36:41 +00:00
|
|
|
|
|
2022-04-19 10:09:12 +00:00
|
|
|
|
! nix run --no-write-lock-file .#pkgAsApp || fail "'nix run' shouldn’t accept an 'app' defined under 'packages'"
|
|
|
|
|
! nix run --no-write-lock-file .#appAsPkg || fail "elements of 'apps' should be of type 'app'"
|
2022-03-25 17:36:41 +00:00
|
|
|
|
|
2024-06-10 09:39:06 +00:00
|
|
|
|
# Test that we're not setting any more environment variables than necessary.
|
|
|
|
|
# For instance, we might set an environment variable temporarily to affect some
|
|
|
|
|
# initialization or whatnot, but this must not leak into the environment of the
|
|
|
|
|
# command being run.
|
|
|
|
|
env > $TEST_ROOT/expected-env
|
|
|
|
|
nix run -f shell-hello.nix env > $TEST_ROOT/actual-env
|
|
|
|
|
# Remove/reset variables we expect to be different.
|
|
|
|
|
# - PATH is modified by nix shell
|
2024-09-30 11:02:51 +00:00
|
|
|
|
# - we unset TMPDIR on macOS if it contains /var/folders. bad. https://github.com/NixOS/nix/issues/7731
|
2024-06-10 09:39:06 +00:00
|
|
|
|
# - _ is set by bash and is expected to differ because it contains the original command
|
|
|
|
|
# - __CF_USER_TEXT_ENCODING is set by macOS and is beyond our control
|
|
|
|
|
sed -i \
|
|
|
|
|
-e 's/PATH=.*/PATH=.../' \
|
|
|
|
|
-e 's/_=.*/_=.../' \
|
2024-09-27 09:07:50 +00:00
|
|
|
|
-e '/^TMPDIR=\/var\/folders\/.*/d' \
|
2024-06-10 09:39:06 +00:00
|
|
|
|
-e '/^__CF_USER_TEXT_ENCODING=.*$/d' \
|
|
|
|
|
$TEST_ROOT/expected-env $TEST_ROOT/actual-env
|
|
|
|
|
sort $TEST_ROOT/expected-env | uniq > $TEST_ROOT/expected-env.sorted
|
|
|
|
|
# nix run appears to clear _. I don't understand why. Is this ok?
|
|
|
|
|
echo "_=..." >> $TEST_ROOT/actual-env
|
|
|
|
|
sort $TEST_ROOT/actual-env | uniq > $TEST_ROOT/actual-env.sorted
|
|
|
|
|
diff $TEST_ROOT/expected-env.sorted $TEST_ROOT/actual-env.sorted
|
|
|
|
|
|
2022-03-25 17:36:41 +00:00
|
|
|
|
clearStore
|
|
|
|
|
|