1 { pkgs, nixVersions, ... }:
5 fallback-paths-external = pkgs.writeTextDir "fallback-paths.nix" ''
7 ${pkgs.system} = "${nixVersions.latest}";
10 inputDrv = import ../.. {
12 imports = [ nixos-module ];
13 nix.package = nixVersions.latest;
14 boot.isContainer = true;
16 users.users.alice.isNormalUser = true;
21 nixos-module = builtins.toFile "nixos-module.nix" ''
22 { lib, pkgs, modulesPath, ... }:
25 (modulesPath + "/profiles/minimal.nix")
26 (modulesPath + "/testing/test-instrumentation.nix")
29 hardware.enableAllFirmware = lib.mkForce false;
31 nix.settings.substituters = lib.mkForce [];
32 nix.settings.hashed-mirrors = null;
33 nix.settings.connect-timeout = 1;
34 nix.extraOptions = "experimental-features = nix-command";
36 environment.localBinInPath = true;
39 packages = [ pkgs.nixVersions.latest ];
41 documentation.enable = false;
46 pkgs.testers.nixosTest {
47 name = "nix-upgrade-${nixVersions.stable.version}-${nixVersions.latest.version}";
48 meta.maintainers = with lib.maintainers; [ tomberek ];
51 imports = [ nixos-module ];
53 nix.package = nixVersions.stable;
54 system.extraDependencies = [
55 fallback-paths-external
62 machine.wait_for_unit("multi-user.target")
64 with subtest("nix-current"):
65 # Create a profile to pretend we are on non-NixOS
67 print(machine.succeed("nix --version"))
68 print(machine.succeed("nix-env -i /run/current-system/sw/bin/nix -p /root/.local"))
70 with subtest("nix-upgrade"):
71 print(machine.succeed("nix upgrade-nix --nix-store-paths-url file://${fallback-paths-external}/fallback-paths.nix --profile /root/.local"))
72 result = machine.succeed("nix --version")
76 match = re.match(r".*${nixVersions.latest.version}$",result)
77 if not match: raise Exception("Couldn't find new version in output: " + result)
79 with subtest("nix-build-with-mismatch-daemon"):
80 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")
83 with subtest("remove-new-nix"):
84 machine.succeed("rm -rf /root/.local")
86 result = machine.succeed("nix --version")
90 match = re.match(r".*${nixVersions.stable.version}$",result)
92 with subtest("upgrade-via-switch-to-configuration"):
93 # not using nixos-rebuild due to nix-instantiate being called and forcing all drv's to be rebuilt
94 print(machine.succeed("${inputDrv.system.outPath}/bin/switch-to-configuration switch"))
95 result = machine.succeed("nix --version")
99 match = re.match(r".*${nixVersions.latest.version}$",result)
100 if not match: raise Exception("Couldn't find new version in output: " + result)
102 with subtest("nix-build-with-new-daemon"):
103 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")
105 with subtest("nix-collect-garbage-with-old-nix"):
106 machine.succeed("${nixVersions.stable}/bin/nix-collect-garbage")