diff options
| author | vkcku <[email protected]> | 2026-06-01 12:01:49 +0530 |
|---|---|---|
| committer | vkcku <[email protected]> | 2026-06-01 12:01:49 +0530 |
| commit | 69114148f8f279d4f5456bd88fedb9d537bed7e5 (patch) | |
| tree | bf414e3de377033727dc564e57cc1600b88af22b /infra/modules/base/zfs.nix | |
| parent | infra: add disko to default imports (diff) | |
infra: add ZFS configuration to base module
monorepo-revid: ba5f961c68f194c29b75984a70b68dcb96124c3b
Diffstat (limited to 'infra/modules/base/zfs.nix')
| -rw-r--r-- | infra/modules/base/zfs.nix | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/infra/modules/base/zfs.nix b/infra/modules/base/zfs.nix new file mode 100644 index 0000000..e2cb007 --- /dev/null +++ b/infra/modules/base/zfs.nix @@ -0,0 +1,116 @@ +{ + flake.modules.nixos.base = + { + config, + lib, + pkgs, + ... + }: + let + cfg = config.infra.zfs; + in + { + options.infra.zfs = { + pool = lib.mkOption { + type = lib.types.str; + description = "The name of the ZFS pool."; + }; + + reservation = lib.mkOption { + type = lib.types.strMatching "[0-9]+[KMGTP]?"; + description = "The amount of space to reserve for the reservation dataset."; + default = "10G"; + }; + }; + + config = { + boot = { + kernelPackages = pkgs.linuxPackages_7_0; + zfs.forceImportRoot = false; + }; + + assertions = + let + expectedZfsVersion = "2.4.2"; + in + [ + { + assertion = pkgs.zfs.version == expectedZfsVersion; + message = '' + ZFS version is ${pkgs.zfs.version}, expected ${expectedZfsVersion}. Check the latest supported kernel + version at https://github.com/openzfs/zfs/releases and update `boot.kernelPackages` + in modules/zfs.nix if needed as well as this assertion. + ''; + } + ]; + + disko.devices.zpool."${cfg.pool}" = { + type = "zpool"; + + rootFsOptions = { + acltype = "posix"; + atime = "off"; + canmount = "off"; + compression = "zstd-3"; + dnodesize = "auto"; + setuid = "off"; + xattr = "sa"; + normalization = "formD"; + utf8only = "on"; + }; + + datasets = { + reservation = { + type = "zfs_fs"; + options = { + reservation = cfg.reservation; + mountpoint = "legacy"; + }; + }; + + "local/nix" = { + type = "zfs_fs"; + mountpoint = "/nix"; + options = { + canmount = "on"; + mountpoint = "legacy"; + }; + mountOptions = [ + "nosuid" + "nodev" + ]; + }; + + "local/root" = { + type = "zfs_fs"; + mountpoint = "/"; + options = { + canmount = "on"; + mountpoint = "legacy"; + }; + postCreateHook = '' + zfs snapshot "${cfg.pool}/local/root@blank" + ''; + mountOptions = [ + "nosuid" + "nodev" + ]; + }; + + "persist" = { + type = "zfs_fs"; + mountpoint = "/persist"; + options = { + canmount = "on"; + mountpoint = "legacy"; + }; + mountOptions = [ + "nosuid" + "nodev" + ]; + }; + }; + }; + }; + }; +} |
