2018-10-30 13:38:36 +01:00
|
|
|
{ lib
|
|
|
|
, config
|
|
|
|
, ... }:
|
2018-11-10 19:24:24 +01:00
|
|
|
with lib;
|
2018-10-30 13:38:36 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.hardware.encryptedDisk;
|
2018-11-10 19:24:24 +01:00
|
|
|
ownLib = import ../lib/default.nix { };
|
2018-10-30 13:38:36 +01:00
|
|
|
in {
|
|
|
|
options.hardware.encryptedDisk = {
|
|
|
|
enable = mkEnableOption "Enable encrypted filesystem layout";
|
|
|
|
diskId = mkOption {
|
2020-10-17 00:52:33 +02:00
|
|
|
type = types.str;
|
2018-10-30 13:38:36 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2018-11-10 19:24:24 +01:00
|
|
|
fileSystems."/boot" = {
|
|
|
|
device = (ownLib.disk.bootFsDevice cfg.diskId);
|
2018-10-30 13:38:36 +01:00
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
|
|
|
|
fileSystems."/" = {
|
2018-11-10 19:24:24 +01:00
|
|
|
device = (ownLib.disk.rootFsDevice cfg.diskId);
|
2018-10-30 13:38:36 +01:00
|
|
|
fsType = "btrfs";
|
|
|
|
options = [ "subvol=nixos" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
fileSystems."/home" = {
|
2018-11-10 19:24:24 +01:00
|
|
|
device = (ownLib.disk.rootFsDevice cfg.diskId);
|
2018-10-30 13:38:36 +01:00
|
|
|
fsType = "btrfs";
|
|
|
|
options = [ "subvol=home" ];
|
|
|
|
};
|
|
|
|
|
2018-11-10 19:24:24 +01:00
|
|
|
swapDevices = [ { device = (ownLib.disk.swapFsDevice cfg.diskId); } ];
|
2018-10-30 13:38:36 +01:00
|
|
|
|
|
|
|
boot.loader.grub = {
|
2018-11-10 19:24:24 +01:00
|
|
|
device = (ownLib.disk.bootGrubDevice cfg.diskId);
|
2018-10-31 19:52:39 +01:00
|
|
|
enableCryptodisk = true;
|
2018-10-30 13:38:36 +01:00
|
|
|
};
|
|
|
|
|
2020-06-10 20:40:15 +02:00
|
|
|
boot.initrd.luks.devices = builtins.listToAttrs [
|
2018-10-30 13:38:36 +01:00
|
|
|
{
|
2018-11-10 19:24:24 +01:00
|
|
|
name =
|
|
|
|
let
|
|
|
|
splitstring = builtins.split "/" (ownLib.disk.bootLuksDevice cfg.diskId);
|
2018-10-30 13:38:36 +01:00
|
|
|
lastelem = (builtins.length splitstring)-1;
|
2018-11-10 19:24:24 +01:00
|
|
|
in
|
|
|
|
builtins.elemAt splitstring lastelem;
|
2020-06-10 20:40:15 +02:00
|
|
|
value = {
|
|
|
|
device = (ownLib.disk.bootLuksDevice cfg.diskId);
|
|
|
|
preLVM = true;
|
|
|
|
allowDiscards = true;
|
|
|
|
};
|
2018-10-30 13:38:36 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|