8 # none is the recommended elevator with ZFS (which has its own I/O scheduler)
9 services.udev.extraRules = ''
10 ACTION=="add|change", KERNEL=="sd[a-z]*[0-9]*|mmcblk[0-9]*p[0-9]*|nvme[0-9]*n[0-9]*p[0-9]*", ENV{ID_FS_TYPE}=="zfs_member", ATTR{../queue/scheduler}="none"
13 boot.supportedFilesystems = [ "zfs" ];
14 boot.initrd.supportedFilesystems = [ "zfs" ];
17 # Disabled because the zfs kernel module is not signed
18 "module.sig_enforce=0"
21 # Using ZFS together with hibernation (suspend to disk)
22 # may cause filesystem corruption.
23 # See https://github.com/openzfs/zfs/issues/260
24 boot.zfs.allowHibernation = false;
25 #boot.zfs.unsafeAllowHibernation = false;
27 # Stable enough, clearer, and faster than the default /dev/disk/by-id
28 boot.zfs.devNodes = "/dev/disk/by-partlabel";
30 # See also https://github.com/NixOS/nixpkgs/issues/62644#issuecomment-1479523469
31 boot.zfs.forceImportAll = false;
32 # More resilient for remote hosts,
33 # though it may call zpool clear.
34 boot.zfs.forceImportRoot = true;
35 boot.zfs.requestEncryptionCredentials = lib.mkDefault [ "${hostName}/root" ];
37 #boot.zfs.package = pkgs.zfs_unstable;
39 # Enables periodic scrubbing of ZFS pools.
40 services.zfs.autoScrub.enable = true;
41 services.zfs.autoScrub.interval = "Sun *-*-08..14 00:15:00";
43 # According to zpool(8), for consumer hardware
44 # periodic manual TRIM is preferred over the automatic TRIM
45 # that ZFS implements.
46 services.zfs.trim.enable = true;
47 services.zfs.trim.interval = "Sun *-*-01..07 00:15:00";
49 # Hide ZFS mountpoints from gio, hence nautilus or caja
50 systemd.services.zfs-mount.postStart = ''
51 /run/wrappers/bin/mount -t zfs | cut -f 1 -d ' ' |
52 xargs -n 1 -r -t /run/wrappers/bin/mount -o remount,x-gvfs-hide || true
55 environment.systemPackages = [
56 pkgs.lzop # For remote syncoid
57 pkgs.mbuffer # For remote syncoid
61 # Force zpool import, even if the disk has not been exported,
62 # (ie. still imported onto another computer).
63 systemd.services."zfs-import@" = {
64 description = "ZFS import pool: %I";
66 ConditionPathIsDirectory = "/sys/module/zfs";
67 StartLimitIntervalSec = 0;
69 after = [ "systemd-modules-load.service" ];
70 path = lib.mkBefore [ "/run/booted-system/sw" ];
73 RemainAfterExit = true;
75 SyslogIdentifier = "zfs-import@%i";
78 pkgs.writeShellScript "zfs-import" ''
81 zpool status "$pool" ||
82 zpool import -lFd /dev/disk/by-id/ -o cachefile=none "$pool" ||
83 zpool reopen "$pool" ||
84 zpool import -lfd /dev/disk/by-id/ -o cachefile=none "$pool" ||
85 zpool clear -nFX "$pool"
86 ${pkgs.systemd}/bin/systemctl restart zfs-mount.service