nixosTests.installer.switchToFlake: Adjust for workaround in #323613

This commit is contained in:
Robert Hensing 2024-07-16 21:34:09 +02:00
parent 34fee8c804
commit 46df92b270

View File

@ -350,7 +350,32 @@ let
""")
with subtest("Switch to flake based config"):
target.succeed("nixos-rebuild switch --flake /root/my-config#xyz")
target.succeed("nixos-rebuild switch --flake /root/my-config#xyz 2>&1 | tee activation-log >&2")
target.succeed("""
cat -n activation-log >&2
""")
target.succeed("""
grep -F '/root/.nix-defexpr/channels exists, but channels have been disabled.' activation-log
""")
target.succeed("""
grep -F '/nix/var/nix/profiles/per-user/root/channels exists, but channels have been disabled.' activation-log
""")
target.succeed("""
grep -F '/root/.nix-defexpr/channels exists, but channels have been disabled.' activation-log
""")
target.succeed("""
grep -F 'Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset.' activation-log
""")
target.succeed("rm activation-log")
# Perform the suggested cleanups we've just seen in the log
# TODO after https://github.com/NixOS/nix/issues/9574: don't remove them yet
target.succeed("""
rm -rf /root/.nix-defexpr/channels /nix/var/nix/profiles/per-user/root/channels /root/.nix-defexpr/channels
""")
target.shutdown()
@ -361,10 +386,19 @@ let
# Note that the channel profile is still present on disk, but configured
# not to be used.
with subtest("builtins.nixPath is now empty"):
target.succeed("""
[[ "[ ]" == "$(nix-instantiate builtins.nixPath --eval --expr)" ]]
""")
# TODO after issue https://github.com/NixOS/nix/issues/9574: re-enable this assertion
# I believe what happens is
# - because of the issue, we've removed the `nix-path =` line from nix.conf
# - the "backdoor" shell is not a proper session and does not have `NIX_PATH=""` set
# - seeing no nix path settings at all, Nix loads its hardcoded default value,
# which is unfortunately non-empty
# with subtest("builtins.nixPath is now empty"):
# target.succeed("""
# (
# set -x;
# [[ "[ ]" == "$(nix-instantiate builtins.nixPath --eval --expr)" ]];
# )
# """)
with subtest("<nixpkgs> does not resolve"):
target.succeed("""
@ -378,12 +412,16 @@ let
target.succeed("""
(
exec 1>&2
rm -v /root/.nix-channels
rm -vf /root/.nix-channels
rm -vrf ~/.nix-defexpr
rm -vrf /nix/var/nix/profiles/per-user/root/channels*
)
""")
target.succeed("nixos-rebuild switch --flake /root/my-config#xyz")
target.succeed("nixos-rebuild switch --flake /root/my-config#xyz | tee activation-log >&2")
target.succeed("cat -n activation-log >&2")
target.succeed("! grep -F '/root/.nix-defexpr/channels' activation-log")
target.succeed("! grep -F 'but channels have been disabled' activation-log")
target.succeed("! grep -F 'https://github.com/NixOS/nix/issues/9574' activation-log")
target.shutdown()
'';