diff --git a/flake.nix b/flake.nix index 6b9ea152..c5a2615c 100644 --- a/flake.nix +++ b/flake.nix @@ -139,6 +139,8 @@ "/dev/disk/by-uuid/55fdd19f-0f1d-4c37-bd4e-6df44fc31f26" = { mapper = "root"; ssd = true; }; "/dev/md/swap" = { mapper = "swap"; ssd = true; }; }; + mdadm = + "ARRAY /dev/md/swap metadata=1.2 name=chn-PC:swap UUID=2b546b8d:e38007c8:02990dd1:df9e23a4"; }; };} ) diff --git a/modules/boot/chn-PC.nix b/modules/boot/chn-PC.nix index 1b0fa3d6..36098d5a 100644 --- a/modules/boot/chn-PC.nix +++ b/modules/boot/chn-PC.nix @@ -124,11 +124,6 @@ inputs: ''; }; }; - services.swraid = - { - enable = true; - mdadmConf = "ARRAY /dev/md/swap metadata=1.2 name=chn-PC:swap UUID=2b546b8d:e38007c8:02990dd1:df9e23a4"; - }; # modules in initrd # modprobe --show-depends availableKernelModules = diff --git a/modules/boot/fileSystems.nix b/modules/boot/fileSystems.nix index 4ecfc780..8256f1ba 100644 --- a/modules/boot/fileSystems.nix +++ b/modules/boot/fileSystems.nix @@ -11,6 +11,7 @@ inputs: }; decrypt.auto = mkOption { type = types.attrsOf (types.submodule { options = { mapper = mkOption { type = types.nonEmptyStr; }; ssd = mkOption { type = types.bool; }; }; }); }; + mdadm = mkOption { type = types.nullOr types.str; }; # swap and resume # swap != resume.device if swap is a file @@ -51,23 +52,31 @@ inputs: ) (inputs.localLib.attrsToList inputs.config.nixos.fileSystems.mount.btrfs))) ); - boot.initrd.luks.devices = - ( - builtins.listToAttrs (builtins.map - ( - device: - { - name = device.value.mapper; - value = + boot.initrd = + { + luks.devices = + ( + builtins.listToAttrs (builtins.map + ( + device: { - device = device.name; - allowDiscards = device.value.ssd; - bypassWorkqueues = device.value.ssd; - crypttabExtraOpts = [ "fido2-device=auto" ]; - }; - } - ) - (inputs.localLib.attrsToList inputs.config.nixos.fileSystems.decrypt.auto)) + name = device.value.mapper; + value = + { + device = device.name; + allowDiscards = device.value.ssd; + bypassWorkqueues = device.value.ssd; + crypttabExtraOpts = [ "fido2-device=auto" ]; + }; + } + ) + (inputs.localLib.attrsToList inputs.config.nixos.fileSystems.decrypt.auto)) + ); + } + // ( + if inputs.config.nixos.fileSystems.mdadm != null then + { services.swraid = { enable = true; mdadmConf = inputs.config.nixos.fileSystems.mdadm; }; } + else {} ); }; }