1{
2 pkgs,
3 nixVersions,
4 system,
5 ...
6}:
7let
8 lib = pkgs.lib;
9
10 fallback-paths-external = pkgs.writeTextDir "fallback-paths.nix" ''
11 {
12 ${system} = "${nixVersions.latest}";
13 }'';
14
15 nixos-module = builtins.toFile "nixos-module.nix" ''
16 { lib, pkgs, modulesPath, ... }:
17 {
18 imports = [
19 (modulesPath + "/profiles/minimal.nix")
20 (modulesPath + "/testing/test-instrumentation.nix")
21 ];
22
23 hardware.enableAllFirmware = lib.mkForce false;
24
25 nix.settings.substituters = lib.mkForce [];
26 nix.settings.hashed-mirrors = null;
27 nix.settings.connect-timeout = 1;
28 nix.extraOptions = "experimental-features = nix-command";
29
30 environment.localBinInPath = true;
31 users.users.alice = {
32 isNormalUser = true;
33 packages = [ pkgs.nixVersions.latest ];
34 };
35 documentation.enable = false;
36 }
37 '';
38in
39
40pkgs.testers.nixosTest {
41 name = "nix-upgrade-${nixVersions.stable.version}-${nixVersions.latest.version}";
42 meta.maintainers = with lib.maintainers; [ tomberek ];
43
44 nodes.machine = {
45 imports = [ nixos-module ];
46
47 nix.package = nixVersions.stable;
48 system.extraDependencies = [
49 fallback-paths-external
50 ];
51
52 specialisation.newer-nix.configuration = {
53 nix.package = lib.mkForce nixVersions.latest;
54
55 users.users.alice.isNormalUser = true;
56 };
57 };
58
59 testScript = ''
60 machine.start()
61 machine.wait_for_unit("multi-user.target")
62
63 with subtest("nix-current"):
64 # Create a profile to pretend we are on non-NixOS
65
66 print(machine.succeed("nix --version"))
67 print(machine.succeed("nix-env -i /run/current-system/sw/bin/nix -p /root/.local"))
68
69 with subtest("nix-upgrade"):
70 print(machine.succeed("nix upgrade-nix --nix-store-paths-url file://${fallback-paths-external}/fallback-paths.nix --profile /root/.local"))
71 result = machine.succeed("nix --version")
72 print(result)
73
74 import re
75 match = re.match(r".*${nixVersions.latest.version}$",result)
76 if not match: raise Exception("Couldn't find new version in output: " + result)
77
78 with subtest("nix-build-with-mismatch-daemon"):
79 machine.succeed("runuser -u alice -- nix build --expr 'derivation {name =\"test\"; system = \"${system}\";builder = \"/bin/sh\"; args = [\"-c\" \"echo test > $out\"];}' --print-out-paths")
80
81
82 with subtest("remove-new-nix"):
83 machine.succeed("rm -rf /root/.local")
84
85 result = machine.succeed("nix --version")
86 print(result)
87
88 import re
89 match = re.match(r".*${nixVersions.stable.version}$",result)
90
91 with subtest("upgrade-via-switch-to-configuration"):
92 # not using nixos-rebuild due to nix-instantiate being called and forcing all drv's to be rebuilt
93 print(machine.succeed("/run/current-system/specialisation/newer-nix/bin/switch-to-configuration switch"))
94 result = machine.succeed("nix --version")
95 print(result)
96
97 import re
98 match = re.match(r".*${nixVersions.latest.version}$",result)
99 if not match: raise Exception("Couldn't find new version in output: " + result)
100
101 with subtest("nix-build-with-new-daemon"):
102 machine.succeed("runuser -u alice -- nix build --expr 'derivation {name =\"test-new\"; system = \"${system}\";builder = \"/bin/sh\"; args = [\"-c\" \"echo test > $out\"];}' --print-out-paths")
103
104 with subtest("nix-collect-garbage-with-old-nix"):
105 machine.succeed("${nixVersions.stable}/bin/nix-collect-garbage")
106 '';
107}