@@ -5,7 +5,7 @@ with lib;
55let
66 luks = config.boot.initrd.luks;
77
8− openCommand = { name, device, header, keyFile, keyFileSize, allowDiscards, yubikey, ... }: ''
8+ openCommand = name': { name, device, header, keyFile, keyFileSize, allowDiscards, yubikey, ... }: assert name' == name; ''
99 # Wait for luksRoot to appear, e.g. if on a usb drive.
1010 # XXX: copied and adapted from stage-1-init.sh - should be
1111 # available as a function.
@@ -192,9 +192,8 @@ let
192192 ''}
193193 '';
194194
195− isPreLVM = f: f.preLVM;
196− preLVM = filter isPreLVM luks.devices;
197− postLVM = filter (f: !(isPreLVM f)) luks.devices;
195+ preLVM = filterAttrs (n: v: v.preLVM) luks.devices;
196+ postLVM = filterAttrs (n: v: !v.preLVM) luks.devices;
198197
199198in
200199{
@@ -228,31 +227,31 @@ in
228227 };
229228
230229 boot.initrd.luks.devices = mkOption {
231− default = [ ];
232− example = literalExample ''[ { name = "luksroot"; device = "/dev/sda3"; preLVM = true; } ]'';
230+ default = { };
231+ example = { "luksroot".device = "/dev/disk/by-uuid/430e9eff-d852-4f68-aa3b-2fa3599ebe08"; };
233232 description = ''
234− The list of devices that should be decrypted using LUKS before trying to mount the
235− root partition. This works for both LVM-over-LUKS and LUKS-over-LVM setups.
236−
237− The devices are decrypted to the device mapper names defined.
238−
239− Make sure that initrd has the crypto modules needed for decryption.
233+ The encrypted disk that should be opened before the root
234+ filesystem is mounted. Both LVM-over-LUKS and LUKS-over-LVM
235+ setups are sypported. The unencrypted devices can be accessed as
236+ <filename>/dev/mapper/<replaceable>name</replaceable></filename>.
240237 '';
241238
242− type = types.listOf types.optionSet;
239+ type = types.loaOf types.optionSet;
243240
244− options = {
241+ options = { name, ... }: { options = {
245242
246243 name = mkOption {
244+ visible = false;
245+ default = name;
247246 example = "luksroot";
248247 type = types.str;
249− description = "Named to be used for the generated device in /dev/mapper.";
248+ description = "Name of the unencrypted device in <filename>/dev/mapper</filename>.";
250249 };
251250
252251 device = mkOption {
253− example = "/dev/sda2";
252+ example = "/dev/disk/by-uuid/430e9eff-d852-4f68-aa3b-2fa3599ebe08";
254253 type = types.str;
255− description = "Path of the underlying block device.";
254+ description = "Path of the underlying encrypted block device.";
256255 };
257256
258257 header = mkOption {
@@ -289,6 +288,7 @@ in
289288 '';
290289 };
291290
291+ # FIXME: get rid of this option.
292292 preLVM = mkOption {
293293 default = true;
294294 type = types.bool;
@@ -394,7 +394,7 @@ in
394394 };
395395 };
396396
397− };
397+ }; };
398398 };
399399
400400 boot.initrd.luks.yubikeySupport = mkOption {
@@ -408,7 +408,7 @@ in
408408 };
409409 };
410410
411− config = mkIf (luks.devices != []) {
411+ config = mkIf (luks.devices != {}) {
412412
413413 # actually, sbp2 driver is the one enabling the DMA attack, but this needs to be tested
414414 boot.blacklistedKernelModules = optionals luks.mitigateDMAAttacks
@@ -463,8 +463,8 @@ in
463463 ''}
464464 '';
465465
466− boot.initrd.preLVMCommands = concatMapStrings openCommand preLVM;
467− boot.initrd.postDeviceCommands = concatMapStrings openCommand postLVM;
466+ boot.initrd.preLVMCommands = concatStrings (mapAttrsToList openCommand preLVM);
467+ boot.initrd.postDeviceCommands = concatStrings (mapAttrsToList openCommand postLVM);
468468
469469 environment.systemPackages = [ pkgs.cryptsetup ];
470470 };