diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix index df8db7f34d0..f016fff824c 100644 --- a/nixos/modules/system/activation/top-level.nix +++ b/nixos/modules/system/activation/top-level.nix @@ -59,7 +59,10 @@ let ${if config.boot.initrd.systemd.enable then '' cp ${config.system.build.bootStage2} $out/prepare-root substituteInPlace $out/prepare-root --subst-var-by systemConfig $out - ln -s "$systemd/lib/systemd/systemd" $out/init + # This must not be a symlink or the abs_path of the grub builder for the tests + # will resolve the symlink and we end up with a path that doesn't point to a + # system closure. + cp "$systemd/lib/systemd/systemd" $out/init '' else '' cp ${config.system.build.bootStage2} $out/init substituteInPlace $out/init --subst-var-by systemConfig $out diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix index 3af124d06a9..c900348619c 100644 --- a/nixos/modules/system/boot/systemd/initrd.nix +++ b/nixos/modules/system/boot/systemd/initrd.nix @@ -503,5 +503,8 @@ in { ]; }; }; + + boot.kernelParams = lib.mkIf (config.boot.resumeDevice != "") [ "resume=${config.boot.resumeDevice}" ]; + }; } diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index a1d4e284657..56629ad7773 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -208,6 +208,7 @@ in # hibernation. This test happens to work on x86_64-linux but # not on other platforms. hibernate = handleTestOn ["x86_64-linux"] ./hibernate.nix {}; + hibernate-systemd-stage-1 = handleTestOn ["x86_64-linux"] ./hibernate.nix { systemdStage1 = true; }; hitch = handleTest ./hitch {}; hledger-web = handleTest ./hledger-web.nix {}; hocker-fetchdocker = handleTest ./hocker-fetchdocker {}; diff --git a/nixos/tests/hibernate.nix b/nixos/tests/hibernate.nix index 032ac6527bc..7a4b331169a 100644 --- a/nixos/tests/hibernate.nix +++ b/nixos/tests/hibernate.nix @@ -3,6 +3,7 @@ { system ? builtins.currentSystem , config ? {} , pkgs ? import ../.. { inherit system config; } +, systemdStage1 ? false }: with import ../lib/testing-python.nix { inherit system pkgs; }; @@ -29,6 +30,11 @@ let "/".device = "/dev/vda2"; }; swapDevices = mkOverride 0 [ { device = "/dev/vda1"; } ]; + boot.resumeDevice = mkIf systemdStage1 "/dev/vda1"; + boot.initrd.systemd = mkIf systemdStage1 { + enable = true; + emergencyAccess = true; + }; }; installedSystem = (import ../lib/eval-config.nix { inherit system;