diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index f368a1b79e91..05cef36c7820 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1187,7 +1187,6 @@ ./system/boot/systemd/tmpfiles.nix ./system/boot/systemd/user.nix ./system/boot/systemd/initrd.nix - ./system/boot/systemd/initrd-mdraid.nix ./system/boot/timesyncd.nix ./system/boot/tmp.nix ./system/etc/etc-activation.nix diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index 3ab873604d3a..5e42eda3875b 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -355,7 +355,7 @@ let [ { object = bootStage1; symlink = "/init"; } - { object = pkgs.writeText "mdadm.conf" config.boot.initrd.services.mdraid.mdadmConf; + { object = pkgs.writeText "mdadm.conf" config.boot.initrd.services.swraid.mdadmConf; symlink = "/etc/mdadm.conf"; } { object = pkgs.runCommand "initrd-kmod-blacklist-ubuntu" { @@ -731,6 +731,6 @@ in }; imports = [ - (mkRenamedOptionModule [ "boot" "initrd" "mdadmConf" ] [ "boot" "initrd" "services" "mdraid" "mdadmConf" ]) + (mkRenamedOptionModule [ "boot" "initrd" "mdadmConf" ] [ "boot" "initrd" "services" "swraid" "mdadmConf" ]) ]; } diff --git a/nixos/modules/system/boot/systemd/initrd-mdraid.nix b/nixos/modules/system/boot/systemd/initrd-mdraid.nix deleted file mode 100644 index b30f2e083fd0..000000000000 --- a/nixos/modules/system/boot/systemd/initrd-mdraid.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ config, pkgs, lib, ... }: let - - cfg = config.boot.initrd.services.mdraid; - -in { - options.boot.initrd.services.mdraid = { - enable = (lib.mkEnableOption "mdraid support in initrd") // { - visible = false; - }; - - mdadmConf = lib.mkOption { - description = "Contents of /etc/mdadm.conf in initrd."; - type = lib.types.lines; - default = ""; - }; - }; - - config = lib.mkIf (config.boot.initrd.systemd.enable && cfg.enable) { - boot.initrd.systemd = { - contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") { - text = cfg.mdadmConf; - }; - - initrdBin = [ pkgs.mdadm ]; - }; - - boot.initrd.services.udev.packages = [ pkgs.mdadm ]; - boot.initrd.systemd.packages = [ pkgs.mdadm ]; - - boot.kernelModules = [ "dm-raid" ]; - }; -} diff --git a/nixos/modules/tasks/swraid.nix b/nixos/modules/tasks/swraid.nix index 8fa19194bed4..0b53a6d152d0 100644 --- a/nixos/modules/tasks/swraid.nix +++ b/nixos/modules/tasks/swraid.nix @@ -1,17 +1,43 @@ -{ pkgs, ... }: +{ config, pkgs, lib, ... }: let -{ + cfg = config.boot.initrd.services.swraid; - environment.systemPackages = [ pkgs.mdadm ]; +in { - services.udev.packages = [ pkgs.mdadm ]; + options.boot.initrd.services.swraid = { + enable = (lib.mkEnableOption "swraid support using mdadm") // { + visible = false; # only has effect when the new stage 1 is in place + }; - systemd.packages = [ pkgs.mdadm ]; + mdadmConf = lib.mkOption { + description = "Contents of /etc/mdadm.conf in initrd."; + type = lib.types.lines; + default = ""; + }; + }; - boot.initrd.availableKernelModules = [ "md_mod" "raid0" "raid1" "raid10" "raid456" ]; + config = { + environment.systemPackages = [ pkgs.mdadm ]; - boot.initrd.extraUdevRulesCommands = '' - cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/ - ''; + services.udev.packages = [ pkgs.mdadm ]; + systemd.packages = [ pkgs.mdadm ]; + + boot.initrd.availableKernelModules = lib.mkIf (config.boot.initrd.systemd.enable -> cfg.enable) [ "md_mod" "raid0" "raid1" "raid10" "raid456" ]; + + boot.initrd.extraUdevRulesCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' + cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/ + ''; + + boot.initrd.systemd = lib.mkIf cfg.enable { + contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") { + text = cfg.mdadmConf; + }; + + packages = [ pkgs.mdadm ]; + initrdBin = [ pkgs.mdadm ]; + }; + + boot.initrd.services.udev.packages = lib.mkIf cfg.enable [ pkgs.mdadm ]; + }; } diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index daef79e684d9..cb68ef685300 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -521,8 +521,8 @@ in systemd-confinement = handleTest ./systemd-confinement.nix {}; systemd-cryptenroll = handleTest ./systemd-cryptenroll.nix {}; systemd-escaping = handleTest ./systemd-escaping.nix {}; - systemd-initrd-mdraid = handleTest ./systemd-initrd-mdraid.nix {}; systemd-initrd-simple = handleTest ./systemd-initrd-simple.nix {}; + systemd-initrd-swraid = handleTest ./systemd-initrd-swraid.nix {}; systemd-journal = handleTest ./systemd-journal.nix {}; systemd-machinectl = handleTest ./systemd-machinectl.nix {}; systemd-networkd = handleTest ./systemd-networkd.nix {}; diff --git a/nixos/tests/systemd-initrd-mdraid.nix b/nixos/tests/systemd-initrd-swraid.nix similarity index 90% rename from nixos/tests/systemd-initrd-mdraid.nix rename to nixos/tests/systemd-initrd-swraid.nix index 0d8827558fbb..28a0fb3192ae 100644 --- a/nixos/tests/systemd-initrd-mdraid.nix +++ b/nixos/tests/systemd-initrd-swraid.nix @@ -1,5 +1,5 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: { - name = "systemd-initrd-mdraid"; + name = "systemd-initrd-swraid"; nodes.machine = { pkgs, ... }: { # Use systemd-boot @@ -17,7 +17,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: { enable = true; emergencyAccess = true; }; - services.mdraid = { + services.swraid = { enable = true; mdadmConf = '' ARRAY /dev/md0 devices=/dev/vdc,/dev/vdd @@ -26,7 +26,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: { kernelModules = [ "raid0" ]; }; - specialisation.boot-mdraid.configuration.virtualisation.bootDevice = "/dev/disk/by-label/testraid"; + specialisation.boot-swraid.configuration.virtualisation.bootDevice = "/dev/disk/by-label/testraid"; }; testScript = '' @@ -36,7 +36,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: { machine.succeed("mkdir -p /mnt && mount /dev/md0 /mnt && echo hello > /mnt/test && umount /mnt") # Boot from the RAID - machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-mdraid.conf") + machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-swraid.conf") machine.succeed("sync") machine.crash() machine.wait_for_unit("multi-user.target")