feat(fs): add configuration for xfs, ext4, btrfs
This commit is contained in:
parent
00a1576803
commit
6517ca329d
22
faucet/fs/btrfs.nix
Normal file
22
faucet/fs/btrfs.nix
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{ pkgs
|
||||||
|
, lib
|
||||||
|
, config
|
||||||
|
, ... }: with lib; let
|
||||||
|
cfg = config.faucet.fs;
|
||||||
|
in {
|
||||||
|
options.faucet.fs.btrfs = {
|
||||||
|
options = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [ "noatime" "compress=zstd" ];
|
||||||
|
description = "btrfs mount options";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf (cfg.type == "btrfs") {
|
||||||
|
fileSystems."/nix" =
|
||||||
|
{ inherit (cfg.btrfs) options;
|
||||||
|
device = "/dev/disk/by-uuid/${cfg.store}";
|
||||||
|
fsType = "btrfs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
87
faucet/fs/default.nix
Normal file
87
faucet/fs/default.nix
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
{ pkgs
|
||||||
|
, lib
|
||||||
|
, config
|
||||||
|
, ... }: with lib; let
|
||||||
|
cfg = config.faucet.fs;
|
||||||
|
in {
|
||||||
|
imports = [
|
||||||
|
./ext4.nix
|
||||||
|
./xfs.nix
|
||||||
|
#./bcachefs.nix
|
||||||
|
./btrfs.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
options.faucet.fs = {
|
||||||
|
type = mkOption {
|
||||||
|
type = with types; enum [ "ext4" "xfs" "bcachefs" "btrfs" ];
|
||||||
|
default = "bcachefs";
|
||||||
|
description = "filesystem type to use for persistent state storage";
|
||||||
|
};
|
||||||
|
store = mkOption {
|
||||||
|
type = with types; str;
|
||||||
|
description = "UUID/dataset of nix store backing device";
|
||||||
|
};
|
||||||
|
esp = {
|
||||||
|
enable = mkEnableOption "EFI system partition" // { default = true; };
|
||||||
|
uuid = mkOption {
|
||||||
|
type = with types; str;
|
||||||
|
default = "cafebabe";
|
||||||
|
description = "vfat serial number of EFI system partition";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
extPersist = {
|
||||||
|
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";
|
||||||
|
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 = {
|
||||||
|
fileSystems."/" =
|
||||||
|
{ device = "rootfs";
|
||||||
|
fsType = "tmpfs";
|
||||||
|
options = [ "size=2G" "mode=755" ];
|
||||||
|
};
|
||||||
|
fileSystems."/boot" = mkIf cfg.esp.enable
|
||||||
|
{ device = "/dev/disk/by-uuid/${cfg.esp.uuid}";
|
||||||
|
fsType = "vfat";
|
||||||
|
};
|
||||||
|
fileSystems."/nix/persist" = mkIf cfg.extPersist.enable
|
||||||
|
{ inherit (cfg.extPersist) device fsType options;
|
||||||
|
neededForBoot = true;
|
||||||
|
depends = "/nix";
|
||||||
|
};
|
||||||
|
|
||||||
|
services.fstrim.enable = mkIf ((cfg.type == "ext4") || (cfg.type == "xfs")) true;
|
||||||
|
|
||||||
|
boot.initrd.luks.devices = mkIf cfg.cryptsetup.enable (
|
||||||
|
mapAttrs' (name: uuid: nameValuePair "luks-${name}" {
|
||||||
|
inherit (cfg.cryptsetup) allowDiscards bypassWorkqueues;
|
||||||
|
device = "/dev/disk/by-uuid/${uuid}";
|
||||||
|
}) cfg.cryptsetup.uuids);
|
||||||
|
};
|
||||||
|
}
|
10
faucet/fs/ext4.nix
Normal file
10
faucet/fs/ext4.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{ lib
|
||||||
|
, config
|
||||||
|
, ... }: with lib; let
|
||||||
|
cfg = config.faucet.fs;
|
||||||
|
in mkIf (cfg.type == "ext4") {
|
||||||
|
fileSystems."/nix" =
|
||||||
|
{ device = "/dev/disk/by-uuid/${cfg.store}";
|
||||||
|
fsType = "ext4";
|
||||||
|
};
|
||||||
|
}
|
11
faucet/fs/xfs.nix
Normal file
11
faucet/fs/xfs.nix
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{ lib
|
||||||
|
, config
|
||||||
|
, ... }: with lib; let
|
||||||
|
cfg = config.faucet.fs;
|
||||||
|
in mkIf (cfg.type == "xfs") {
|
||||||
|
# NOTE: -m reflink=1
|
||||||
|
fileSystems."/nix" =
|
||||||
|
{ device = "/dev/disk/by-uuid/${cfg.store}";
|
||||||
|
fsType = "xfs";
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue