mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
nixos/tests/installer: add testByAttrSwitch
This commit is contained in:
parent
c7b66353bf
commit
d77469c442
@ -81,7 +81,7 @@ let
|
||||
# partitions and filesystems.
|
||||
testScriptFun = { bootLoader, createPartitions, grubDevice, grubUseEfi, grubIdentifier
|
||||
, postInstallCommands, postBootCommands, extraConfig
|
||||
, testSpecialisationConfig, testFlakeSwitch, clevisTest, clevisFallbackTest
|
||||
, testSpecialisationConfig, testFlakeSwitch, testByAttrSwitch, clevisTest, clevisFallbackTest
|
||||
, disableFileSystems
|
||||
}:
|
||||
let
|
||||
@ -316,6 +316,119 @@ let
|
||||
|
||||
target.shutdown()
|
||||
''
|
||||
+ optionalString testByAttrSwitch ''
|
||||
with subtest("Configure system with attribute set"):
|
||||
target.succeed("""
|
||||
mkdir /root/my-config
|
||||
mv /etc/nixos/hardware-configuration.nix /root/my-config/
|
||||
rm /etc/nixos/configuration.nix
|
||||
""")
|
||||
target.copy_from_host_via_shell(
|
||||
"${makeConfig {
|
||||
inherit bootLoader grubDevice grubIdentifier grubUseEfi extraConfig clevisTest;
|
||||
forceGrubReinstallCount = 1;
|
||||
withTestInstrumentation = false;
|
||||
}}",
|
||||
"/root/my-config/configuration.nix",
|
||||
)
|
||||
target.copy_from_host_via_shell(
|
||||
"${./installer/byAttrWithChannel.nix}",
|
||||
"/root/my-config/default.nix",
|
||||
)
|
||||
with subtest("Switch to attribute set based config with channels"):
|
||||
target.succeed("nixos-rebuild switch --file /root/my-config/default.nix")
|
||||
|
||||
target.shutdown()
|
||||
|
||||
${startTarget}
|
||||
|
||||
target.succeed("""
|
||||
rm /root/my-config/default.nix
|
||||
""")
|
||||
target.copy_from_host_via_shell(
|
||||
"${./installer/byAttrNoChannel.nix}",
|
||||
"/root/my-config/default.nix",
|
||||
)
|
||||
|
||||
target.succeed("""
|
||||
pkgs=$(readlink -f /nix/var/nix/profiles/per-user/root/channels)/nixos
|
||||
if ! [[ -e $pkgs/pkgs/top-level/default.nix ]]; then
|
||||
echo 1>&2 "$pkgs does not seem to be a nixpkgs source. Please fix the test so that pkgs points to a nixpkgs source.";
|
||||
exit 1;
|
||||
fi
|
||||
sed -e s^@nixpkgs@^$pkgs^ -i /root/my-config/default.nix
|
||||
|
||||
""")
|
||||
|
||||
with subtest("Switch to attribute set based config without channels"):
|
||||
target.succeed("nixos-rebuild switch --file /root/my-config/default.nix")
|
||||
|
||||
target.shutdown()
|
||||
|
||||
${startTarget}
|
||||
|
||||
with subtest("nix-channel command is not available anymore"):
|
||||
target.succeed("! which nix-channel")
|
||||
|
||||
with subtest("builtins.nixPath is now empty"):
|
||||
target.succeed("""
|
||||
[[ "[ ]" == "$(nix-instantiate builtins.nixPath --eval --expr)" ]]
|
||||
""")
|
||||
|
||||
with subtest("<nixpkgs> does not resolve"):
|
||||
target.succeed("""
|
||||
! nix-instantiate '<nixpkgs>' --eval --expr
|
||||
""")
|
||||
|
||||
with subtest("Evaluate attribute set based config in fresh env without nix-channel"):
|
||||
target.succeed("nixos-rebuild switch --file /root/my-config/default.nix")
|
||||
|
||||
with subtest("Evaluate attribute set based config in fresh env without channel profiles"):
|
||||
target.succeed("""
|
||||
(
|
||||
exec 1>&2
|
||||
mkdir -p /root/restore
|
||||
mv -v /root/.nix-channels /root/restore/
|
||||
mv -v ~/.nix-defexpr /root/restore/
|
||||
mkdir -p /root/restore/channels
|
||||
mv -v /nix/var/nix/profiles/per-user/root/channels* /root/restore/channels/
|
||||
)
|
||||
""")
|
||||
target.succeed("nixos-rebuild switch --file /root/my-config/default.nix")
|
||||
''
|
||||
+ optionalString (testByAttrSwitch && testFlakeSwitch) ''
|
||||
with subtest("Restore channel profiles"):
|
||||
target.succeed("""
|
||||
(
|
||||
exec 1>&2
|
||||
mv -v /root/restore/.nix-channels /root/
|
||||
mv -v /root/restore/.nix-defexpr ~/.nix-defexpr
|
||||
mv -v /root/restore/channels/* /nix/var/nix/profiles/per-user/root/
|
||||
rm -vrf /root/restore
|
||||
)
|
||||
""")
|
||||
|
||||
with subtest("Restore /etc/nixos"):
|
||||
target.succeed("""
|
||||
mv -v /root/my-config/hardware-configuration.nix /etc/nixos/
|
||||
""")
|
||||
target.copy_from_host_via_shell(
|
||||
"${makeConfig {
|
||||
inherit bootLoader grubDevice grubIdentifier grubUseEfi extraConfig clevisTest;
|
||||
forceGrubReinstallCount = 1;
|
||||
}}",
|
||||
"/etc/nixos/configuration.nix",
|
||||
)
|
||||
|
||||
with subtest("Restore /root/my-config"):
|
||||
target.succeed("""
|
||||
rm -vrf /root/my-config
|
||||
""")
|
||||
|
||||
''
|
||||
+ optionalString (testByAttrSwitch && !testFlakeSwitch) ''
|
||||
target.shutdown()
|
||||
''
|
||||
+ optionalString testFlakeSwitch ''
|
||||
${startTarget}
|
||||
|
||||
@ -399,6 +512,7 @@ let
|
||||
, enableOCR ? false, meta ? {}
|
||||
, testSpecialisationConfig ? false
|
||||
, testFlakeSwitch ? false
|
||||
, testByAttrSwitch ? false
|
||||
, clevisTest ? false
|
||||
, clevisFallbackTest ? false
|
||||
, disableFileSystems ? false
|
||||
@ -533,7 +647,7 @@ let
|
||||
testScript = testScriptFun {
|
||||
inherit bootLoader createPartitions postInstallCommands postBootCommands
|
||||
grubDevice grubIdentifier grubUseEfi extraConfig
|
||||
testSpecialisationConfig testFlakeSwitch clevisTest clevisFallbackTest
|
||||
testSpecialisationConfig testFlakeSwitch testByAttrSwitch clevisTest clevisFallbackTest
|
||||
disableFileSystems;
|
||||
};
|
||||
};
|
||||
@ -589,6 +703,15 @@ let
|
||||
testFlakeSwitch = true;
|
||||
};
|
||||
|
||||
simple-test-config-by-attr = simple-test-config // {
|
||||
testByAttrSwitch = true;
|
||||
};
|
||||
|
||||
simple-test-config-from-by-attr-to-flake = simple-test-config // {
|
||||
testByAttrSwitch = true;
|
||||
testFlakeSwitch = true;
|
||||
};
|
||||
|
||||
simple-uefi-grub-config = {
|
||||
createPartitions = ''
|
||||
installer.succeed(
|
||||
@ -772,6 +895,10 @@ in {
|
||||
|
||||
switchToFlake = makeInstallerTest "switch-to-flake" simple-test-config-flake;
|
||||
|
||||
switchToByAttr = makeInstallerTest "switch-to-by-attr" simple-test-config-by-attr;
|
||||
|
||||
switchFromByAttrToFlake = makeInstallerTest "switch-from-by-attr-to-flake" simple-test-config-from-by-attr-to-flake;
|
||||
|
||||
# Test cloned configurations with the simple grub configuration
|
||||
simpleSpecialised = makeInstallerTest "simpleSpecialised" (simple-test-config // specialisation-test-extraconfig);
|
||||
|
||||
|
18
nixos/tests/installer/byAttrNoChannel.nix
Normal file
18
nixos/tests/installer/byAttrNoChannel.nix
Normal file
@ -0,0 +1,18 @@
|
||||
# This file gets copied into the installation
|
||||
|
||||
let
|
||||
nixpkgs = "@nixpkgs@";
|
||||
in
|
||||
|
||||
{ evalConfig ? import "${nixpkgs}/nixos/lib/eval-config.nix" }:
|
||||
|
||||
evalConfig {
|
||||
modules = [
|
||||
./configuration.nix
|
||||
( import "${nixpkgs}/nixos/modules/testing/test-instrumentation.nix" )
|
||||
{
|
||||
# Disable nix channels
|
||||
nix.channel.enable = false;
|
||||
}
|
||||
];
|
||||
}
|
10
nixos/tests/installer/byAttrWithChannel.nix
Normal file
10
nixos/tests/installer/byAttrWithChannel.nix
Normal file
@ -0,0 +1,10 @@
|
||||
# This file gets copied into the installation
|
||||
|
||||
{ evalConfig ? import <nixpkgs/nixos/lib/eval-config.nix> }:
|
||||
|
||||
evalConfig {
|
||||
modules = [
|
||||
./configuration.nix
|
||||
( import <nixpkgs/nixos/modules/testing/test-instrumentation.nix> )
|
||||
];
|
||||
}
|
Loading…
Reference in New Issue
Block a user