nixos/global/fs/default.nix

128 lines
3.1 KiB
Nix
Raw Normal View History

2025-01-13 11:52:09 +08:00
{
pkgs,
lib,
config,
...
}:
with lib;
let
2024-01-07 22:01:31 +08:00
cfg = config.global.fs;
2025-01-13 11:52:09 +08:00
in
{
imports = [
./ext4.nix
2024-01-09 13:17:47 +08:00
./f2fs.nix
./xfs.nix
2024-01-24 08:59:12 +08:00
./bcachefs.nix
2024-02-10 00:16:09 +08:00
./zfs
];
2024-01-07 22:01:31 +08:00
options.global.fs = {
type = mkOption {
2025-01-13 11:52:09 +08:00
type =
with types;
enum [
"ext4"
"f2fs"
"xfs"
"zfs"
"bcachefs"
];
default = "bcachefs";
description = "filesystem type to use for persistent state storage";
};
store = mkOption {
type = with types; str;
2024-01-09 13:17:47 +08:00
default = config.networking.hostName;
description = "UUID/dataset of nix store backing device";
};
esp = {
2025-01-13 11:52:09 +08:00
enable = mkEnableOption "EFI system partition" // {
default = true;
};
uuid = mkOption {
type = with types; str;
default = "CAFE-BABE";
description = "vfat serial number of EFI system partition";
};
};
2024-01-21 20:43:50 +08:00
external = {
enable = mkEnableOption "external persist filesystem";
# this wraps the standard fileSystems module
# since some attrs have to be unconditionally set
device = mkOption {
default = null;
type = with types; nullOr str;
description = "Location of the device.";
};
fsType = mkOption {
default = "auto";
type = with types; str;
description = "Type of the file system.";
};
options = mkOption {
default = [ "defaults" ];
description = "Options used to mount the file system.";
type = with types; nonEmptyListOf str;
};
};
cryptsetup = {
enable = mkEnableOption "full disk encryption device early setup";
2025-01-13 11:52:09 +08:00
allowDiscards = mkEnableOption "allow discards via device-mapper" // {
default = true;
};
bypassWorkqueues = mkEnableOption "bypass dm-crypt's internal workqueues" // {
default = true;
};
uuids = mkOption {
type = with types; attrsOf str;
description = "device-mapper name to encrypted block device UUID mapping";
};
};
};
config = {
2025-01-13 11:52:09 +08:00
fileSystems."/" = {
device = "rootfs";
fsType = "tmpfs";
2025-01-13 11:52:09 +08:00
options = [
"size=2G"
"mode=755"
];
};
2025-01-13 11:52:09 +08:00
fileSystems."/boot" = mkIf cfg.esp.enable {
device = "/dev/disk/by-uuid/${cfg.esp.uuid}";
fsType = "vfat";
};
2025-01-13 11:52:09 +08:00
fileSystems."/nix/persist" = mkIf cfg.external.enable {
inherit (cfg.external) device fsType options;
neededForBoot = true;
2024-01-04 15:03:54 +08:00
depends = [ "/nix" ];
};
2025-01-13 11:52:09 +08:00
fileSystems."/tmp" = {
device = "/nix/tmp";
2024-01-04 15:03:54 +08:00
options = [ "bind" ];
depends = [ "/nix/tmp" ];
};
services.fstrim.enable = mkIf ((cfg.type == "ext4") || (cfg.type == "xfs")) true;
boot.initrd.luks.devices = mkIf cfg.cryptsetup.enable (
2025-01-13 11:52:09 +08:00
mapAttrs' (
name: uuid:
nameValuePair "luks-${name}" {
inherit (cfg.cryptsetup) allowDiscards bypassWorkqueues;
device = "/dev/disk/by-uuid/${uuid}";
}
) cfg.cryptsetup.uuids
);
2024-03-14 17:40:56 +08:00
2025-01-13 11:52:09 +08:00
environment.persistence."/nix/persist/fhs".files = [
{
file = "/var/lib/private/mode";
parentDirectory.mode = "0700";
}
];
};
}