config/profiles/mounts/common-zfs.nix

58 lines
2.2 KiB
Nix
Raw Normal View History

2023-12-10 06:03:49 +01:00
{ config, pkgs, lib, ... }:
{
# https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/index.html
# https://nixos.org/manual/nixos/stable/#sec-linux-zfs
# https://nixos.wiki/wiki/ZFS
# https://search.nixos.org/options?query=services.zfs
boot.kernelPackages = lib.mkForce pkgs.zfs.latestCompatibleLinuxPackages;
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";
2024-10-14 11:37:47 +02:00
# Only datasets with the com.sun:auto-snapshot property set to true will be snapshotted.
# zfs set com.sun:auto-snapshot=true DATASET
2023-12-10 06:03:49 +01:00
services.zfs.autoSnapshot.enable = true; # simply runs zfstools
# default args, can be overriden per-dataset
2024-10-14 11:37:47 +02:00
# 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;
2023-12-10 06:03:49 +01:00
services.zfs.autoSnapshot.monthly = 5;
#services.zfs.autoReplication.enable
#services.zfs.autoScrub.enable = true;
#services.zfs.trim.enable = true;
2024-02-01 02:09:03 +01:00
# the `sharenfs` property generates /etc/exports.d/zfs.exports file, automatically processed by NFS
2024-09-29 17:31:39 +02:00
# https://man.archlinux.org/man/core/nfs-utils/exports.5.en
2024-10-14 11:37:47 +02:00
# # zfs set sharenfs="-maproot=0:0 -network=192.168.1.0/24" Reidun/shared
2024-02-01 02:09:03 +01:00
# # zfs set sharenfs="ro=192.168.1.0/24,all_squash,anonuid=70,anongid=70" Meconium
2024-09-29 17:31:39 +02:00
# # zfs set sharenfs="rw=@192.168.1.0/24" Meconium
2024-10-14 11:37:47 +02:00
# # zfs set sharenfs="rw=@100.64.0.0/10" Meconium
2024-02-01 02:09:03 +01:00
services.nfs.server.enable = lib.mkDefault true;
2024-04-03 16:07:08 +02:00
2024-09-29 17:31:39 +02:00
# https://wiki.nixos.org/wiki/NFS
2024-04-03 16:07:08 +02:00
# TODO: move to common-nfs-server.nix
services.nfs.server = {
# fixed rpc.statd port; for firewall
lockdPort = 4001;
mountdPort = 4002;
statdPort = 4000;
extraNfsdConfig = '''';
};
2024-08-13 16:26:58 +02:00
networking.firewall = lib.mkIf config.services.nfs.server.enable {
2024-04-03 16:07:08 +02:00
# for NFSv3; view with `rpcinfo -p`
allowedTCPPorts = [ 111 2049 4000 4001 4002 ]; # 20048
allowedUDPPorts = [ 111 2049 4000 4001 4002 ]; # 20048
};
2023-12-10 06:03:49 +01:00
}