2022-10-31 11:04:38 +01:00
|
|
|
{ lib, config, ... }:
|
|
|
|
with lib;
|
2018-10-30 13:38:36 +01:00
|
|
|
|
|
|
|
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 { };
|
2018-10-30 13:38:36 +01:00
|
|
|
in {
|
2020-12-31 02:12:29 +01:00
|
|
|
options.hardware.opinionatedDisk = {
|
|
|
|
enable = mkEnableOption "Enable opinionated filesystem layout";
|
2022-10-31 11:04:38 +01:00
|
|
|
diskId = mkOption { type = types.str; };
|
2020-12-31 02:12:29 +01:00
|
|
|
encrypted = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
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" ];
|
|
|
|
};
|
|
|
|
|
2022-10-31 11:04:38 +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);
|
2020-12-31 02:12:29 +01:00
|
|
|
enableCryptodisk = cfg.encrypted;
|
2018-10-30 13:38:36 +01:00
|
|
|
};
|
|
|
|
|
2022-10-31 11:04:38 +01:00
|
|
|
boot.initrd.luks.devices = lib.optionalAttrs cfg.encrypted
|
|
|
|
(builtins.listToAttrs [{
|
|
|
|
name = let
|
|
|
|
splitstring =
|
|
|
|
builtins.split "/" (ownLib.disk.bootLuksDevice cfg.diskId);
|
|
|
|
lastelem = (builtins.length splitstring) - 1;
|
|
|
|
in builtins.elemAt splitstring lastelem;
|
2020-06-10 20:40:15 +02:00
|
|
|
value = {
|
|
|
|
device = (ownLib.disk.bootLuksDevice cfg.diskId);
|
|
|
|
preLVM = true;
|
|
|
|
allowDiscards = true;
|
|
|
|
};
|
2022-10-31 11:04:38 +01:00
|
|
|
}]);
|
2018-10-30 13:38:36 +01:00
|
|
|
};
|
|
|
|
}
|