1 { pkgs, nixVersions, ... }:
5 fallback-paths-external = pkgs.writeTextDir "fallback-paths.nix" ''
7 ${pkgs.system} = "${nixVersions.latest}";
10 nixos-module = builtins.toFile "nixos-module.nix" ''
11 { lib, pkgs, modulesPath, ... }:
14 (modulesPath + "/profiles/minimal.nix")
15 (modulesPath + "/testing/test-instrumentation.nix")
18 hardware.enableAllFirmware = lib.mkForce false;
20 nix.settings.substituters = lib.mkForce [];
21 nix.settings.hashed-mirrors = null;
22 nix.settings.connect-timeout = 1;
23 nix.extraOptions = "experimental-features = nix-command";
25 environment.localBinInPath = true;
28 packages = [ pkgs.nixVersions.latest ];
30 documentation.enable = false;
35 pkgs.testers.nixosTest {
36 name = "nix-upgrade-${nixVersions.stable.version}-${nixVersions.latest.version}";
37 meta.maintainers = with lib.maintainers; [ tomberek ];
40 imports = [ nixos-module ];
42 nix.package = nixVersions.stable;
43 system.extraDependencies = [
44 fallback-paths-external
47 specialisation.newer-nix.configuration = {
48 nix.package = lib.mkForce nixVersions.latest;
50 users.users.alice.isNormalUser = true;
56 machine.wait_for_unit("multi-user.target")
58 with subtest("nix-current"):
59 # Create a profile to pretend we are on non-NixOS
61 print(machine.succeed("nix --version"))
62 print(machine.succeed("nix-env -i /run/current-system/sw/bin/nix -p /root/.local"))
64 with subtest("nix-upgrade"):
65 print(machine.succeed("nix upgrade-nix --nix-store-paths-url file://${fallback-paths-external}/fallback-paths.nix --profile /root/.local"))
66 result = machine.succeed("nix --version")
70 match = re.match(r".*${nixVersions.latest.version}$",result)
71 if not match: raise Exception("Couldn't find new version in output: " + result)
73 with subtest("nix-build-with-mismatch-daemon"):
74 machine.succeed("runuser -u alice -- nix build --expr 'derivation {name =\"test\"; system = \"${pkgs.system}\";builder = \"/bin/sh\"; args = [\"-c\" \"echo test > $out\"];}' --print-out-paths")
77 with subtest("remove-new-nix"):
78 machine.succeed("rm -rf /root/.local")
80 result = machine.succeed("nix --version")
84 match = re.match(r".*${nixVersions.stable.version}$",result)
86 with subtest("upgrade-via-switch-to-configuration"):
87 # not using nixos-rebuild due to nix-instantiate being called and forcing all drv's to be rebuilt
88 print(machine.succeed("/run/current-system/specialisation/newer-nix/bin/switch-to-configuration switch"))
89 result = machine.succeed("nix --version")
93 match = re.match(r".*${nixVersions.latest.version}$",result)
94 if not match: raise Exception("Couldn't find new version in output: " + result)
96 with subtest("nix-build-with-new-daemon"):
97 machine.succeed("runuser -u alice -- nix build --expr 'derivation {name =\"test-new\"; system = \"${pkgs.system}\";builder = \"/bin/sh\"; args = [\"-c\" \"echo test > $out\"];}' --print-out-paths")
99 with subtest("nix-collect-garbage-with-old-nix"):
100 machine.succeed("${nixVersions.stable}/bin/nix-collect-garbage")