aboutsummaryrefslogtreecommitdiff
path: root/infra/modules
diff options
context:
space:
mode:
Diffstat (limited to 'infra/modules')
-rw-r--r--infra/modules/base/zfs.nix116
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"
+ ];
+ };
+ };
+ };
+ };
+ };
+}