Files
config/profiles/mounts/common-zfs.nix
T
2025-11-23 14:49:41 +01:00

82 lines
3.0 KiB
Nix

{ config, pkgs, lib, ... }:
{
# https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/index.html
# https://nixos.org/manual/nixos/stable/#sec-linux-zfs
# https://wiki.nixos.org/wiki/ZFS
# https://search.nixos.org/options?query=services.zfs
# boot.kernelPackages = lib.mkForce pkgs.zfs.latestCompatibleLinuxPackages;
boot.kernelPackages = pkgs.linuxPackages; # should conflict if we try for e.g. linuxPackages_latest
boot.supportedFilesystems = [ "zfs" ];
boot.zfs.forceImportRoot = false;
# must be set per host
# head -c4 /dev/urandom | od -A none -t x4
# consider the one automatically generated by systemd:
# head -c 8 /etc/machine-id
#networking.hostId = "12345678";
# Only datasets with the com.sun:auto-snapshot property set to true will be snapshotted.
# zfs set com.sun:auto-snapshot=true DATASET
services.zfs.autoSnapshot.enable = !config.virtualisation.isVmVariant; # simply runs zfstools
# default args, can be overridden per-dataset
# zfs set com.sun:auto-snapshot:weekly=false DATASET
services.zfs.autoSnapshot.frequent = 4; # 15 min
services.zfs.autoSnapshot.hourly = 24;
services.zfs.autoSnapshot.daily = 7;
services.zfs.autoSnapshot.weekly = 4;
services.zfs.autoSnapshot.monthly = 5;
#services.zfs.autoReplication.enable
#services.zfs.autoScrub.enable = true;
#services.zfs.trim.enable = true;
# the `sharenfs` property generates /etc/exports.d/zfs.exports file, automatically processed by NFS
# https://man.freebsd.org/cgi/man.cgi?query=exports - -network only supports a single range
# # sudo zfs set sharenfs="-maproot=0:0 -network=192.168.1.0/24" Reidun/shared
# # sudo zfs set sharenfs="-maproot=0:0 -network=192.168.1.0/24" Freon
# https://man.archlinux.org/man/core/nfs-utils/exports.5.en
# # sudo zfs set sharenfs="rw=100.64.0.0/10,rw=192.168.1.0/24" Meconium
# https://wiki.nixos.org/wiki/NFS
# TODO: move to common-nfs-server.nix
services.nfs = {
# # sudo zfs set sharenfs="-maproot=0:0 -network=100.64.0.0/10" Reidun/shared
# # sudo zfs set sharenfs="-maproot=0:0 -network=100.64.0.0/10" Freon
# # sudo zfs set sharenfs="rw=100.64.0.0/10" Meconium
server.enable = lib.mkDefault (!config.virtualisation.isVmVariant);
# fixed rpc.statd port; for firewall
server.lockdPort = 4001;
server.mountdPort = 4002;
server.statdPort = 4000;
settings = {
# https://man.archlinux.org/man/core/nfs-utils/nfs.conf.5.en
# TODO: move the config in panorama-zfs.nix here
};
};
networking.firewall = let
ports = [
# for NFSv3; view with `rpcinfo -p`
111
2049
config.services.nfs.server.lockdPort
config.services.nfs.server.mountdPort
config.services.nfs.server.statdPort
# 20048
];
in
lib.mkIf config.services.nfs.server.enable {
# for NFSv3; view with `rpcinfo -p`
allowedTCPPorts = ports;
allowedUDPPorts = ports;
# for NFSv4
# allowedTCPPorts = [ 2049 ];
# allowedUDPPorts = [ 2049 ];
};
}