nixos/swraid: make entire module optional

swraid support will now only be enabled by default if stateVersion is
older than 23.11. nixos-generate-config will now generate explicit
config for enabling support if needed.
This commit is contained in:
Linus Heckemann 2022-07-28 14:34:44 +02:00
parent 408c0e8c15
commit 0b277bcc2b
5 changed files with 23 additions and 10 deletions

View File

@ -78,6 +78,8 @@
- 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.
- mdraid support is now optional. This reduces initramfs size and prevents automatic import of software RAID pools, which may not be desired. 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.
## Other Notable Changes {#sec-release-23.11-notable-changes}
- 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.

View File

@ -381,6 +381,7 @@ sub in {
my $fileSystems;
my %fsByDev;
my $useSwraid = 0;
foreach my $fs (read_file("/proc/self/mountinfo")) {
chomp $fs;
my @fields = split / /, $fs;
@ -510,8 +511,8 @@ EOF
# boot.initrd.luks.devices entry.
if (-e $device) {
my $deviceName = basename(abs_path($device));
if (-e "/sys/class/block/$deviceName"
&& read_file("/sys/class/block/$deviceName/dm/uuid", err_mode => 'quiet') =~ /^CRYPT-LUKS/)
my $dmUuid = read_file("/sys/class/block/$deviceName/dm/uuid", err_mode => 'quiet');
if ($dmUuid =~ /^CRYPT-LUKS/)
{
my @slaves = glob("/sys/class/block/$deviceName/slaves/*");
if (scalar @slaves == 1) {
@ -527,8 +528,14 @@ EOF
}
}
}
if (-e "/sys/class/block/$deviceName/md/uuid") {
$useSwraid = 1;
}
}
}
if ($useSwraid) {
push @attrs, "boot.initrd.services.swraid.enable = true;\n\n";
}
# Generate the hardware configuration file.

View File

@ -106,6 +106,10 @@ with lib;
systemdStage1Network
];
boot.initrd.services = {
swraid.enable = true;
};
# Show all debug messages from the kernel but don't log refused packets
# because we have the firewall enabled. This makes installs from the
# console less cumbersome if the machine has a public IP.

View File

@ -6,11 +6,11 @@ in {
options.boot.initrd.services.swraid = {
enable = lib.mkEnableOption (lib.mdDoc "swraid support using mdadm") // {
description = ''
*This will only be used when systemd is used in stage 1.*
description = lib.mdDoc ''
Whether to enable swraid support using mdadm.
'';
default = lib.versionOlder config.system.stateVersion "23.11";
defaultText = lib.mdDoc "`true` if stateVersion is older than 23.11";
};
mdadmConf = lib.mkOption {
@ -20,20 +20,20 @@ in {
};
};
config = {
config = lib.mkIf cfg.enable {
environment.systemPackages = [ pkgs.mdadm ];
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.availableKernelModules = [ "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 {
boot.initrd.systemd = {
contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") {
text = cfg.mdadmConf;
};
@ -42,6 +42,6 @@ in {
initrdBin = [ pkgs.mdadm ];
};
boot.initrd.services.udev.packages = lib.mkIf cfg.enable [ pkgs.mdadm ];
boot.initrd.services.udev.packages = [ pkgs.mdadm ];
};
}

View File

@ -28,7 +28,7 @@
simpleUefiGrubSpecialisation
simpleUefiSystemdBoot
stratisRoot
# swraid
swraid
zfsroot
;