infra/nix/os/modules/opinionatedDisk.nix

63 lines
1.5 KiB
Nix
Raw Normal View History

{ lib
, config
, ... }:
2018-11-10 19:24:24 +01:00
with lib;
let
2020-12-31 02:12:29 +01:00
cfg = config.hardware.opinionatedDisk;
2018-11-10 19:24:24 +01:00
ownLib = import ../lib/default.nix { };
in {
2020-12-31 02:12:29 +01:00
options.hardware.opinionatedDisk = {
enable = mkEnableOption "Enable opinionated filesystem layout";
diskId = mkOption {
type = types.str;
};
2020-12-31 02:12:29 +01:00
encrypted = mkOption {
default = true;
type = types.bool;
};
};
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);
2020-12-31 02:12:29 +01:00
enableCryptodisk = cfg.encrypted;
};
2020-12-31 02:12:29 +01:00
boot.initrd.luks.devices = lib.optionalAttrs cfg.encrypted (builtins.listToAttrs [
{
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;
value = {
device = (ownLib.disk.bootLuksDevice cfg.diskId);
preLVM = true;
allowDiscards = true;
};
}
2020-12-31 02:12:29 +01:00
]);
};
}