{ config, lib, ... }: with lib; let fileSystems = config.system.build.fileSystems ++ config.swapDevices; encDevs = filter (dev: dev.encrypted.enable) fileSystems; # With scripted initrd, devices with a keyFile have to be opened # late, after file systems are mounted, because that could be where # the keyFile is located. With systemd initrd, each individual # systemd-cryptsetup@ unit has RequiresMountsFor= to delay until all # the mount units for the key file are done; i.e. no special # treatment is needed. lateEncDevs = if config.boot.initrd.systemd.enable then { } else filter (dev: dev.encrypted.keyFile != null) encDevs; earlyEncDevs = if config.boot.initrd.systemd.enable then encDevs else filter (dev: dev.encrypted.keyFile == null) encDevs; anyEncrypted = foldr (j: v: v || j.encrypted.enable) false encDevs; encryptedFSOptions = { options.encrypted = { enable = mkOption { default = false; type = types.bool; description = lib.mdDoc "The block device is backed by an encrypted one, adds this device as a initrd luks entry."; }; blkDev = mkOption { default = null; example = "/dev/sda1"; type = types.nullOr types.str; description = lib.mdDoc "Location of the backing encrypted device."; }; label = mkOption { default = null; example = "rootfs"; type = types.nullOr types.str; description = lib.mdDoc "Label of the unlocked encrypted device. Set `fileSystems..device` to `/dev/mapper/