nixos/global/fs/zfs.nix

45 lines
1.2 KiB
Nix
Raw Normal View History

2024-01-09 13:17:47 +08:00
{ pkgs
, lib
, config
, ... }: with lib; let
cfg = config.global.fs;
in {
# -o ashift=12
# -O encryption=on -O keyformat=passphrase -O keylocation=prompt
# -O compression=on -O mountpoint=none -O xattr=sa -O acltype=posixacl
2024-01-09 13:17:47 +08:00
options.global.fs.zfs = {
persist = mkOption {
type = with types; str;
default = cfg.store;
description = ''
pool for persist dataset
defaults to nix store dataset
'';
};
};
config = mkIf (cfg.type == "zfs") {
fileSystems = {
"/nix" =
{ device = "${cfg.store}/nix";
fsType = "zfs";
};
"/nix/persist" =
{ device = "${cfg.zfs.persist}/persist";
fsType = "zfs";
neededForBoot = true;
};
} // (mapAttrs' (name: opts: nameValuePair
"/nix/persist/home/${name}" {
device = "${cfg.zfs.persist}/home/${name}";
fsType = "zfs";
neededForBoot = true;
}) (filterAttrs (n: _: n != "root") config.users.profiles));
services.zfs.trim.enable = true;
services.zfs.autoSnapshot.enable = true;
services.zfs.autoScrub.enable = true;
boot.zfs.devNodes = mkDefault "/dev/disk/by-partuuid";
};
}