lol

Merge pull request #183314 from DeterminateSystems/optional-swraid

Make swraid optional

authored by

Will Fancher and committed by
GitHub
11fec977 3d0e323b

+63 -36
+2
nixos/doc/manual/release-notes/rl-2311.section.md
··· 80 80 81 81 - The Caddy module gained a new option named `services.caddy.enableReload` which is enabled by default. It allows reloading the service instead of restarting it, if only a config file has changed. This option must be disabled if you have turned off the [Caddy admin API](https://caddyserver.com/docs/caddyfile/options#admin). If you keep this option enabled, you should consider setting [`grace_period`](https://caddyserver.com/docs/caddyfile/options#grace-period) to a non-infinite value to prevent Caddy from delaying the reload indefinitely. 82 82 83 + - mdraid support is now optional. This reduces initramfs size and prevents the potentially undesired automatic detection and activation of software RAID pools. It is disabled by default in new configurations (determined by `stateVersion`), but the appropriate settings will be generated by `nixos-generate-config` when installing to a software RAID device, so the standard installation procedure should be unaffected. If you have custom configs relying on mdraid, ensure that you use `stateVersion` correctly or set `boot.swraid.enable` manually. 84 + 83 85 ## Other Notable Changes {#sec-release-23.11-notable-changes} 84 86 85 87 - The Cinnamon module now enables XDG desktop integration by default. If you are experiencing collisions related to xdg-desktop-portal-gtk you can safely remove `xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];` from your NixOS configuration.
+9 -2
nixos/modules/installer/tools/nixos-generate-config.pl
··· 381 381 382 382 my $fileSystems; 383 383 my %fsByDev; 384 + my $useSwraid = 0; 384 385 foreach my $fs (read_file("/proc/self/mountinfo")) { 385 386 chomp $fs; 386 387 my @fields = split / /, $fs; ··· 510 511 # boot.initrd.luks.devices entry. 511 512 if (-e $device) { 512 513 my $deviceName = basename(abs_path($device)); 513 - if (-e "/sys/class/block/$deviceName" 514 - && read_file("/sys/class/block/$deviceName/dm/uuid", err_mode => 'quiet') =~ /^CRYPT-LUKS/) 514 + my $dmUuid = read_file("/sys/class/block/$deviceName/dm/uuid", err_mode => 'quiet'); 515 + if ($dmUuid =~ /^CRYPT-LUKS/) 515 516 { 516 517 my @slaves = glob("/sys/class/block/$deviceName/slaves/*"); 517 518 if (scalar @slaves == 1) { ··· 527 528 } 528 529 } 529 530 } 531 + if (-e "/sys/class/block/$deviceName/md/uuid") { 532 + $useSwraid = 1; 533 + } 530 534 } 535 + } 536 + if ($useSwraid) { 537 + push @attrs, "boot.swraid.enable = true;\n\n"; 531 538 } 532 539 533 540
+2
nixos/modules/profiles/installation-device.nix
··· 106 106 systemdStage1Network 107 107 ]; 108 108 109 + boot.swraid.enable = true; 110 + 109 111 # Show all debug messages from the kernel but don't log refused packets 110 112 # because we have the firewall enabled. This makes installs from the 111 113 # console less cumbersome if the machine has a public IP.
+1 -9
nixos/modules/system/boot/stage-1.nix
··· 133 133 copy_bin_and_libs ${getBin pkgs.lvm2}/bin/dmsetup 134 134 copy_bin_and_libs ${getBin pkgs.lvm2}/bin/lvm 135 135 136 - # Add RAID mdadm tool. 137 - copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm 138 - copy_bin_and_libs ${pkgs.mdadm}/sbin/mdmon 139 - 140 136 # Copy udev. 141 137 copy_bin_and_libs ${udev}/bin/udevadm 142 138 copy_bin_and_libs ${udev}/lib/systemd/systemd-sysctl ··· 225 221 $out/bin/udevadm --version 226 222 $out/bin/dmsetup --version 2>&1 | tee -a log | grep -q "version:" 227 223 LVM_SYSTEM_DIR=$out $out/bin/lvm version 2>&1 | tee -a log | grep -q "LVM" 228 - $out/bin/mdadm --version 229 224 ${optionalString config.services.multipath.enable '' 230 225 ($out/bin/multipath || true) 2>&1 | grep -q 'need to be root' 231 226 ($out/bin/multipathd || true) 2>&1 | grep -q 'need to be root' ··· 353 348 contents = 354 349 [ { object = bootStage1; 355 350 symlink = "/init"; 356 - } 357 - { object = pkgs.writeText "mdadm.conf" config.boot.initrd.services.swraid.mdadmConf; 358 - symlink = "/etc/mdadm.conf"; 359 351 } 360 352 { object = pkgs.runCommand "initrd-kmod-blacklist-ubuntu" { 361 353 src = "${pkgs.kmod-blacklist-ubuntu}/modprobe.conf"; ··· 727 719 }; 728 720 729 721 imports = [ 730 - (mkRenamedOptionModule [ "boot" "initrd" "mdadmConf" ] [ "boot" "initrd" "services" "swraid" "mdadmConf" ]) 722 + (mkRenamedOptionModule [ "boot" "initrd" "mdadmConf" ] [ "boot" "swraid" "mdadmConf" ]) 731 723 ]; 732 724 }
+42 -18
nixos/modules/tasks/swraid.nix
··· 1 1 { config, pkgs, lib, ... }: let 2 2 3 - cfg = config.boot.initrd.services.swraid; 3 + cfg = config.boot.swraid; 4 4 5 5 in { 6 6 7 - options.boot.initrd.services.swraid = { 7 + options.boot.swraid = { 8 8 enable = lib.mkEnableOption (lib.mdDoc "swraid support using mdadm") // { 9 - description = '' 10 - *This will only be used when systemd is used in stage 1.* 9 + description = lib.mdDoc '' 10 + Whether to enable support for Linux MD RAID arrays. 11 + 12 + When this is enabled, mdadm will be added to the system path, 13 + and MD RAID arrays will be detected and activated 14 + automatically, both in stage-1 (initramfs) and in stage-2 (the 15 + final NixOS system). 11 16 12 - Whether to enable swraid support using mdadm. 17 + This should be enabled if you want to be able to access and/or 18 + boot from MD RAID arrays. {command}`nixos-generate-config` 19 + should detect it correctly in the standard installation 20 + procedure. 13 21 ''; 22 + default = lib.versionOlder config.system.stateVersion "23.11"; 23 + defaultText = lib.mdDoc "`true` if stateVersion is older than 23.11"; 14 24 }; 15 25 16 26 mdadmConf = lib.mkOption { 17 - description = lib.mdDoc "Contents of {file}`/etc/mdadm.conf` in initrd."; 27 + description = lib.mdDoc "Contents of {file}`/etc/mdadm.conf`."; 18 28 type = lib.types.lines; 19 29 default = ""; 20 30 }; 21 31 }; 22 32 23 - config = { 33 + config = lib.mkIf cfg.enable { 24 34 environment.systemPackages = [ pkgs.mdadm ]; 25 35 26 36 services.udev.packages = [ pkgs.mdadm ]; 27 37 28 38 systemd.packages = [ pkgs.mdadm ]; 29 39 30 - boot.initrd.availableKernelModules = lib.mkIf (config.boot.initrd.systemd.enable -> cfg.enable) [ "md_mod" "raid0" "raid1" "raid10" "raid456" ]; 40 + boot.initrd = { 41 + availableKernelModules = [ "md_mod" "raid0" "raid1" "raid10" "raid456" ]; 31 42 32 - boot.initrd.extraUdevRulesCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' 33 - cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/ 34 - ''; 43 + extraUdevRulesCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' 44 + cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/ 45 + ''; 35 46 36 - boot.initrd.systemd = lib.mkIf cfg.enable { 37 - contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") { 38 - text = cfg.mdadmConf; 47 + extraUtilsCommands = '' 48 + # Add RAID mdadm tool. 49 + copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm 50 + copy_bin_and_libs ${pkgs.mdadm}/sbin/mdmon 51 + ''; 52 + 53 + extraUtilsCommandsTest = '' 54 + $out/bin/mdadm --version 55 + ''; 56 + 57 + extraFiles."/etc/mdadm.conf".source = pkgs.writeText "mdadm.conf" config.boot.swraid.mdadmConf; 58 + 59 + systemd = { 60 + contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") { 61 + text = cfg.mdadmConf; 62 + }; 63 + 64 + packages = [ pkgs.mdadm ]; 65 + initrdBin = [ pkgs.mdadm ]; 39 66 }; 40 67 41 - packages = [ pkgs.mdadm ]; 42 - initrdBin = [ pkgs.mdadm ]; 68 + services.udev.packages = [ pkgs.mdadm ]; 43 69 }; 44 - 45 - boot.initrd.services.udev.packages = lib.mkIf cfg.enable [ pkgs.mdadm ]; 46 70 }; 47 71 }
+1 -1
nixos/tests/installer-systemd-stage-1.nix
··· 28 28 simpleUefiGrubSpecialisation 29 29 simpleUefiSystemdBoot 30 30 stratisRoot 31 - # swraid 31 + swraid 32 32 zfsroot 33 33 ; 34 34
+6 -6
nixos/tests/systemd-initrd-swraid.nix
··· 14 14 boot.loader.efi.canTouchEfiVariables = true; 15 15 16 16 environment.systemPackages = with pkgs; [ mdadm e2fsprogs ]; # for mdadm and mkfs.ext4 17 + boot.swraid = { 18 + enable = true; 19 + mdadmConf = '' 20 + ARRAY /dev/md0 devices=/dev/vdb,/dev/vdc 21 + ''; 22 + }; 17 23 boot.initrd = { 18 24 systemd = { 19 25 enable = true; 20 26 emergencyAccess = true; 21 - }; 22 - services.swraid = { 23 - enable = true; 24 - mdadmConf = '' 25 - ARRAY /dev/md0 devices=/dev/vdb,/dev/vdc 26 - ''; 27 27 }; 28 28 kernelModules = [ "raid0" ]; 29 29 };