From 9e8b463cce747c63884f911113fd3dd943d04278 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Sun, 17 Apr 2022 18:27:39 -0400 Subject: [PATCH 1/3] nixos: Handle panic_on_fail in systemd stage 1 --- nixos/modules/system/boot/systemd/initrd.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix index 6c1b42da1c41..2e8766540f19 100644 --- a/nixos/modules/system/boot/systemd/initrd.nix +++ b/nixos/modules/system/boot/systemd/initrd.nix @@ -504,6 +504,21 @@ in { ''systemctl --no-block switch-root /sysroot "''${NEW_INIT}"'' ]; }; + + services.panic-on-fail = { + wantedBy = ["emergency.target"]; + unitConfig = { + DefaultDependencies = false; + ConditionKernelCommandLine = [ + "|boot.panic_on_fail" + "|stage1panic" + ]; + }; + script = '' + echo c > /proc/sysrq-trigger + ''; + serviceConfig.Type = "oneshot"; + }; }; boot.kernelParams = lib.mkIf (config.boot.resumeDevice != "") [ "resume=${config.boot.resumeDevice}" ]; From 9ee5d61a16c1a00ae4864a632aba2c297faa81c3 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Sun, 17 Apr 2022 17:24:13 -0400 Subject: [PATCH 2/3] nixos: Installer tests for systemd stage 1 --- .../modules/profiles/installation-device.nix | 4 +++ nixos/tests/all-tests.nix | 1 + nixos/tests/installer-systemd-stage-1.nix | 33 +++++++++++++++++++ nixos/tests/installer.nix | 7 +++- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/installer-systemd-stage-1.nix diff --git a/nixos/modules/profiles/installation-device.nix b/nixos/modules/profiles/installation-device.nix index 3c503fba2a39..a8601a9e2c06 100644 --- a/nixos/modules/profiles/installation-device.nix +++ b/nixos/modules/profiles/installation-device.nix @@ -99,6 +99,10 @@ with lib; stdenvNoCC # for runCommand busybox jq # for closureInfo + # For boot.initrd.systemd + makeInitrdNGTool + systemdStage1 + systemdStage1Network ]; # Show all debug messages from the kernel but don't log refused packets diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index cb68ef685300..f75ff1d02320 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -232,6 +232,7 @@ in input-remapper = handleTest ./input-remapper.nix {}; inspircd = handleTest ./inspircd.nix {}; installer = handleTest ./installer.nix {}; + installer-systemd-stage-1 = handleTest ./installer-systemd-stage-1.nix {}; invoiceplane = handleTest ./invoiceplane.nix {}; iodine = handleTest ./iodine.nix {}; ipfs = handleTest ./ipfs.nix {}; diff --git a/nixos/tests/installer-systemd-stage-1.nix b/nixos/tests/installer-systemd-stage-1.nix new file mode 100644 index 000000000000..a8b418626e66 --- /dev/null +++ b/nixos/tests/installer-systemd-stage-1.nix @@ -0,0 +1,33 @@ +{ system ? builtins.currentSystem +, config ? {} +, pkgs ? import ../.. { inherit system config; } +}: + +{ + # Some of these tests don't work with systemd stage 1 yet. Uncomment + # them when fixed. + inherit (import ./installer.nix { inherit system config pkgs; systemdStage1 = true; }) + # bcache + # btrfsSimple + # btrfsSubvolDefault + # btrfsSubvols + # encryptedFSWithKeyfile + # grub1 + # luksroot + # luksroot-format1 + # luksroot-format2 + # lvm + separateBoot + separateBootFat + simple + simpleLabels + simpleProvided + simpleSpecialised + simpleUefiGrub + simpleUefiGrubSpecialisation + simpleUefiSystemdBoot + # swraid + # zfsroot + ; + +} diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix index 30a5b5c45b36..e040584bdb6d 100644 --- a/nixos/tests/installer.nix +++ b/nixos/tests/installer.nix @@ -1,6 +1,7 @@ { system ? builtins.currentSystem, config ? {}, - pkgs ? import ../.. { inherit system config; } + pkgs ? import ../.. { inherit system config; }, + systemdStage1 ? false }: with import ../lib/testing-python.nix { inherit system pkgs; }; @@ -23,6 +24,8 @@ let # To ensure that we can rebuild the grub configuration on the nixos-rebuild system.extraDependencies = with pkgs; [ stdenvNoCC ]; + ${optionalString systemdStage1 "boot.initrd.systemd.enable = true;"} + ${optionalString (bootLoader == "grub") '' boot.loader.grub.version = ${toString grubVersion}; ${optionalString (grubVersion == 1) '' @@ -290,6 +293,8 @@ let virtualisation.cores = 8; virtualisation.memorySize = 1536; + boot.initrd.systemd.enable = systemdStage1; + # Use a small /dev/vdb as the root disk for the # installer. This ensures the target disk (/dev/vda) is # the same during and after installation. From f3f2e55e594f6b1e6bd75d41125fea13d3889896 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Sun, 17 Apr 2022 18:30:44 -0400 Subject: [PATCH 3/3] nixos: Fix channel copying in installer tests with systemd stage 1 --- nixos/modules/installer/cd-dvd/channel.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/installer/cd-dvd/channel.nix b/nixos/modules/installer/cd-dvd/channel.nix index 92164d65e533..2f91cd39881d 100644 --- a/nixos/modules/installer/cd-dvd/channel.nix +++ b/nixos/modules/installer/cd-dvd/channel.nix @@ -39,7 +39,8 @@ in echo "unpacking the NixOS/Nixpkgs sources..." mkdir -p /nix/var/nix/profiles/per-user/root ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/per-user/root/channels \ - -i ${channelSources} --quiet --option build-use-substitutes false + -i ${channelSources} --quiet --option build-use-substitutes false \ + ${optionalString config.boot.initrd.systemd.enable "--option sandbox false"} # There's an issue with pivot_root mkdir -m 0700 -p /root/.nix-defexpr ln -s /nix/var/nix/profiles/per-user/root/channels /root/.nix-defexpr/channels mkdir -m 0755 -p /var/lib/nixos