From 68ff2536e3a355248829c0f726f2a89ec7a2df93 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 10 Dec 2023 06:03:49 +0100 Subject: [PATCH] meconium: knut -> nox --- hosts/nord/default.nix | 1 + hosts/noximilien/default.nix | 3 +++ hosts/sopp/default.nix | 1 + profiles/mounts/common-zfs.nix | 31 +++++++++++++++++++++++++++++++ profiles/mounts/meconium-nfs.nix | 24 ++++++++++++++++++++++++ profiles/mounts/meconium-zfs.nix | 11 +++++++++++ profiles/mounts/reidun-nfs.nix | 3 --- 7 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 profiles/mounts/common-zfs.nix create mode 100644 profiles/mounts/meconium-nfs.nix create mode 100644 profiles/mounts/meconium-zfs.nix diff --git a/hosts/nord/default.nix b/hosts/nord/default.nix index a3aac47..5420e61 100644 --- a/hosts/nord/default.nix +++ b/hosts/nord/default.nix @@ -24,6 +24,7 @@ ../../users/pbsds ../../profiles/mounts/reidun-nfs.nix + ../../profiles/mounts/meconium-nfs.nix ../../profiles/shell/base.nix ../../profiles/shell/archives.nix diff --git a/hosts/noximilien/default.nix b/hosts/noximilien/default.nix index 612c497..6acbfb7 100644 --- a/hosts/noximilien/default.nix +++ b/hosts/noximilien/default.nix @@ -16,6 +16,7 @@ ../../users/jornane ../../profiles/mounts/reidun-nfs.nix + ../../profiles/mounts/meconium-zfs.nix ../../profiles/shell/base.nix ../../profiles/shell/archives.nix @@ -91,6 +92,8 @@ "kuklef.se" ]; + networking.hostId = "e1ffd469"; # needed for zfs: head -c 8 /etc/machine-id + # TODO: remove? Move to where relevant? nixpkgs.overlays = [ /** / diff --git a/hosts/sopp/default.nix b/hosts/sopp/default.nix index f5616ce..058c2cb 100644 --- a/hosts/sopp/default.nix +++ b/hosts/sopp/default.nix @@ -35,6 +35,7 @@ ../../users/pbsds ../../profiles/mounts/reidun-nfs.nix + ../../profiles/mounts/meconium-nfs.nix ../../profiles/shell/base.nix ../../profiles/shell/archives.nix diff --git a/profiles/mounts/common-zfs.nix b/profiles/mounts/common-zfs.nix new file mode 100644 index 0000000..5b22f7a --- /dev/null +++ b/profiles/mounts/common-zfs.nix @@ -0,0 +1,31 @@ +{ 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"; + + services.zfs.autoSnapshot.enable = true; # simply runs zfstools + # default args, can be overriden per-dataset + services.zfs.autoSnapshot.frequent = 2; # 15 min + services.zfs.autoSnapshot.hourly = 3; + services.zfs.autoSnapshot.daily = 4; + services.zfs.autoSnapshot.weekly = 3; + services.zfs.autoSnapshot.monthly = 5; + + #services.zfs.autoReplication.enable + #services.zfs.autoScrub.enable = true; + #services.zfs.trim.enable = true; + + # config.services.nfs.server.enable will automatically export NFS dataset tagged as such +} diff --git a/profiles/mounts/meconium-nfs.nix b/profiles/mounts/meconium-nfs.nix new file mode 100644 index 0000000..b635186 --- /dev/null +++ b/profiles/mounts/meconium-nfs.nix @@ -0,0 +1,24 @@ +{ config, pkgs, lib, ... }: +{ + # TODO: wireguard + #boot.kernelParams = [ "nfs.nfs4_disable_idmapping=0" "nfsd.nfs4_disable_idmapping=0" ]; + + fileSystems = let + mkMount = mountpoint: server: subdir: { + "${mountpoint}${subdir}" = { + device = "${server}${subdir}"; + fsType = "nfs"; + #options = [ "nfsvers=4.2" ]; + }; + }; + # TODO: combine nameValuePair and listToAttrs + joinSets = sets: builtins.foldl' (l: r: l // r) {} sets; + in joinSets ( + # TODO: depend on nox.networking.interfaces.eno1.ipv4.addresses + (map (mkMount "/mnt/meconium" "192.168.1.9:/Meconium" ) [ + "" + "/beets_music" + ]) + ); + +} diff --git a/profiles/mounts/meconium-zfs.nix b/profiles/mounts/meconium-zfs.nix new file mode 100644 index 0000000..68f8ae0 --- /dev/null +++ b/profiles/mounts/meconium-zfs.nix @@ -0,0 +1,11 @@ +{ config, pkgs, lib, ... }: +{ + # https://search.nixos.org/options?query=services.zfs + + imports = [ ./common-zfs.nix ]; + + # non legacy-mount + systemd.services.zfs-mount.enable = true; # default + boot.zfs.extraPools = [ "Meconium" ]; # import on boot + +} diff --git a/profiles/mounts/reidun-nfs.nix b/profiles/mounts/reidun-nfs.nix index 6fa6a1b..6eed482 100644 --- a/profiles/mounts/reidun-nfs.nix +++ b/profiles/mounts/reidun-nfs.nix @@ -54,9 +54,6 @@ "/Work/Programming" "/Work/School" "/pub" - ]) ++ (map (mkMount "/mnt/meconium" "192.168.1.3:/Meconium" ) [ - "" - "/beets_music" ]) );