Files
nix-config/modules/boot/zfs.org
T
phundrak ba018ef841 refactor: change to litterate config
Configuration is now held by the `.org` files. All `.nix` files are
tangled from the org-mode files.
2026-10-06 12:40:58 +02:00

1.6 KiB
Raw Blame History

ZFS Support

ZFS Support

Enabling ZFS is quite straightforward on my machines. In my module nixos.zfs, I expose two options: which ZFS pools to import, and whether to force-import the root pool. But first, here’s the skeleton of my module.

{
  flake.modules.nixos.zfs = {
    lib,
    config,
    ...
  }:
    with lib; let
      cfg = config.mySystem.boot;
    in {
      <<options>>
      <<enable>>
      <<pools>>
      <<force-import-root>>
    };
}

The main option is the list of pools, which I pass directly to the standard NixOS configuration.

options.mySystem.boot.zfs = {
  pools = mkOption {
    type = types.listOf types.str;
    default = [];
  };
  forceImportRoot = mkEnableOption "Force-import the ZFS root pool at boot, even if it looks already imported elsewhere";
};

Now, I can enable ZFS on the system importing the current module.

config.boot.supportedFilesystems = ["zfs"];

And lastly, passing the list of pools to the standard NixOS option is quite simple.

config.boot.zfs.extraPools = cfg.zfs.pools;

Force-importing the root pool can paper over a stale or mismatched host ID, but it also risks mounting a pool that’s already imported elsewhere and corrupting it, so NixOS is moving to disable it by default. I’d rather keep that safety and only turn it back on for the rare host (or the rare boot) that actually needs it.

config.boot.zfs.forceImportRoot = cfg.zfs.forceImportRoot;