nixos/stage-1-init: Merge mdraid module into swraid

main
Janne Heß 2 years ago
parent 0efb6720a4
commit 01bc138a8e
No known key found for this signature in database
GPG Key ID: 69165158F05265DF
  1. 1
      nixos/modules/module-list.nix
  2. 4
      nixos/modules/system/boot/stage-1.nix
  3. 32
      nixos/modules/system/boot/systemd/initrd-mdraid.nix
  4. 44
      nixos/modules/tasks/swraid.nix
  5. 2
      nixos/tests/all-tests.nix
  6. 8
      nixos/tests/systemd-initrd-swraid.nix

@ -1186,7 +1186,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

@ -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" ])
];
}

@ -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 <filename>/etc/mdadm.conf</filename> 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" ];
};
}

@ -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 <filename>/etc/mdadm.conf</filename> 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 ];
};
}

@ -520,8 +520,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 {};

@ -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")
Loading…
Cancel
Save