]> Git — Sourcephile - julm/julm-nix.git/blob - nixos/profiles/zfs.nix
patate: nftables: output-net: allow SMTP submission
[julm/julm-nix.git] / nixos / profiles / zfs.nix
1 { pkgs, lib, hostName, ... }:
2 {
3 # none is the recommended elevator with ZFS (which has its own I/O scheduler)
4 # and/or for SSD, whereas HDD could use mq-deadline.
5 services.udev.extraRules = ''
6 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"
7 ACTION=="add|change", KERNEL=="sd[a-z][0-9]*", ATTR{../queue/rotational}=="0", ATTR{../queue/scheduler}="none"
8 ACTION=="add|change", KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ATTR{../queue/rotational}=="0", ATTR{../queue/scheduler}="none"
9 '';
10
11 boot.supportedFilesystems = [ "zfs" ];
12 boot.initrd.supportedFilesystems = [ "zfs" ];
13
14 # Using ZFS together with hibernation (suspend to disk)
15 # may cause filesystem corruption.
16 # See https://github.com/openzfs/zfs/issues/260
17 boot.kernelParams = [ "nohibernate" ];
18
19 # Stable enough, clearer, and faster than the default /dev/disk/by-id
20 boot.zfs.devNodes = "/dev/disk/by-partlabel";
21 # Not useful so far.
22 # See also https://github.com/NixOS/nixpkgs/issues/62644#issuecomment-1479523469
23 boot.zfs.forceImportAll = false;
24 # More resilient for remote hosts,
25 # though it may call zpool clear.
26 boot.zfs.forceImportRoot = true;
27 boot.zfs.requestEncryptionCredentials = lib.mkDefault [ "${hostName}/root" ];
28
29 boot.zfs.enableUnstable = false;
30
31 # Enables periodic scrubbing of ZFS pools.
32 services.zfs.autoScrub.enable = true;
33 services.zfs.autoScrub.interval = "Sun *-*-08..14 00:15:00";
34
35 # According to zpool(8), for consumer hardware
36 # periodic manual TRIM is preferred over the automatic TRIM
37 # that ZFS implements.
38 services.zfs.trim.enable = true;
39 services.zfs.trim.interval = "Sun *-*-01..07 00:15:00";
40
41 # Hide ZFS mountpoints from gio, hence nautilus or caja
42 systemd.services.zfs-mount.postStart = ''
43 /run/wrappers/bin/mount -t zfs | cut -f 1 -d ' ' |
44 xargs -n 1 -r -t /run/wrappers/bin/mount -o remount,x-gvfs-hide
45 '';
46
47 environment.systemPackages = [
48 pkgs.lzop # For remote syncoid
49 pkgs.mbuffer # For remote syncoid
50 pkgs.sanoid
51 ];
52 }