feat(fs): add zfs split store options

This commit is contained in:
514fpv 2024-02-10 00:16:09 +08:00
parent 714bf122bf
commit 189eabe42c
Signed by: koishi
SSH key fingerprint: SHA256:axz0uIzzY+5W19i7QOUuiw5LSqhKfCBKPf3L4xFRxLw
3 changed files with 45 additions and 1 deletions

View file

@ -8,8 +8,8 @@ in {
./ext4.nix
./f2fs.nix
./xfs.nix
./zfs.nix
./bcachefs.nix
./zfs
];
options.global.fs = {

View file

@ -4,6 +4,10 @@
, ... }: with lib; let
cfg = config.global.fs;
in {
imports = [
./split.nix
];
# -o ashift=12
# -O encryption=on -O keyformat=passphrase -O keylocation=prompt
# -O compression=on -O mountpoint=none -O xattr=sa -O acltype=posixacl
@ -21,6 +25,19 @@ in {
description = "zfs dataset mountpoints";
};
externalStore = mkEnableOption "external nix store filesystem";
split = {
enable = mkEnableOption "zfs state with split nix store";
mdProg = mkOption {
type = with types; str;
default = "/usr/bin/true";
description = "mdadm PROGRAM config value";
};
secret = mkOption {
type = with types; str;
description = "UUID of secret filesystem";
};
};
};
config = mkIf (cfg.type == "zfs") {

27
global/fs/zfs/split.nix Normal file
View file

@ -0,0 +1,27 @@
{ pkgs
, lib
, config
, ... }: with lib; let
cfg = config.global.fs.zfs.split;
in mkIf cfg.enable {
# unconditionally enable fstrim for xfs and ext4
services.fstrim.enable = mkDefault true;
# enable swraid for split raid1 system array
boot.swraid.enable = mkDefault true;
boot.swraid.mdadmConf = mkDefault ''
PROGRAM ${cfg.mdProg}
'';
# secret filesystem backed by LUKS on swraid
fileSystems."/nix/var/secret" =
{ device = "/dev/disk/by-uuid/${cfg.secret}";
fsType = "ext4";
options = [ "noatime" ];
neededForBoot = true;
depends = [ "/nix/var" ];
};
# import system state pool after encrypted filesystems become available for key loading
boot.initrd.systemd.services."zfs-import-${config.global.fs.store}".after = [ "cryptsetup.target" ];
}