infra/nix/os/modules/encryptedDisk.nix

57 lines
1.3 KiB
Nix
Raw Normal View History

{ lib
, config
, ... }:
2018-11-10 19:24:24 +01:00
with lib;
let
cfg = config.hardware.encryptedDisk;
2018-11-10 19:24:24 +01:00
ownLib = import ../lib/default.nix { };
in {
options.hardware.encryptedDisk = {
enable = mkEnableOption "Enable encrypted filesystem layout";
diskId = mkOption {
type = types.string;
};
};
config = lib.mkIf cfg.enable {
2018-11-10 19:24:24 +01:00
fileSystems."/boot" = {
device = (ownLib.disk.bootFsDevice cfg.diskId);
fsType = "vfat";
};
fileSystems."/" = {
2018-11-10 19:24:24 +01:00
device = (ownLib.disk.rootFsDevice cfg.diskId);
fsType = "btrfs";
options = [ "subvol=nixos" ];
};
fileSystems."/home" = {
2018-11-10 19:24:24 +01:00
device = (ownLib.disk.rootFsDevice cfg.diskId);
fsType = "btrfs";
options = [ "subvol=home" ];
};
2018-11-10 19:24:24 +01:00
swapDevices = [ { device = (ownLib.disk.swapFsDevice cfg.diskId); } ];
boot.loader.grub = {
2018-11-10 19:24:24 +01:00
device = (ownLib.disk.bootGrubDevice cfg.diskId);
enableCryptodisk = true;
};
2018-11-10 19:24:24 +01:00
boot.initrd.luks.devices = [
{
2018-11-10 19:24:24 +01:00
name =
let
splitstring = builtins.split "/" (ownLib.disk.bootLuksDevice cfg.diskId);
lastelem = (builtins.length splitstring)-1;
2018-11-10 19:24:24 +01:00
in
builtins.elemAt splitstring lastelem;
device = (ownLib.disk.bootLuksDevice cfg.diskId);
preLVM = true;
allowDiscards = true;
}
];
};
}