From 07e49b1591a70fdc31ff3886424833ddb6e3c1d9 Mon Sep 17 00:00:00 2001 From: rocketcamel Date: Sat, 13 Dec 2025 22:40:04 -0800 Subject: [PATCH] feat: add nfs mesh --- nix/hosts/kumatani/configuration.nix | 27 +------ nix/modules/commonPackages.nix | 1 + nix/modules/default.nix | 2 + nix/modules/mounts.nix | 31 ++++++++ nix/modules/nfs-mesh.nix | 113 +++++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 26 deletions(-) create mode 100644 nix/modules/mounts.nix create mode 100644 nix/modules/nfs-mesh.nix diff --git a/nix/hosts/kumatani/configuration.nix b/nix/hosts/kumatani/configuration.nix index 2f30e8d..11b0b28 100644 --- a/nix/hosts/kumatani/configuration.nix +++ b/nix/hosts/kumatani/configuration.nix @@ -47,34 +47,9 @@ }; desktop.enable = true; - home-manager.users.luca = { - services.kanshi = { - enable = true; - settings = [ - { - profile.name = "main"; - profile.outputs = [ - { - criteria = "DP-2"; - status = "enable"; - scale = 1.0; - mode = "1920x1080"; - position = "0,190"; - } - { - criteria = "HDMI-A-1"; - status = "enable"; - scale = 1.0; - mode = "3440x1440"; - position = "1920,0"; - } - ]; - } - ]; - }; - }; kanata.enable = true; kanata.apple = true; + users.users.luca = { isNormalUser = true; extraGroups = [ diff --git a/nix/modules/commonPackages.nix b/nix/modules/commonPackages.nix index 6af8574..9e0a79e 100644 --- a/nix/modules/commonPackages.nix +++ b/nix/modules/commonPackages.nix @@ -71,6 +71,7 @@ libxkbcommon udev alsa-lib + waypipe ]; programs.nix-ld.enable = lib.mkDefault true; programs.zsh.enable = lib.mkDefault true; diff --git a/nix/modules/default.nix b/nix/modules/default.nix index 4b2f794..c1704c8 100644 --- a/nix/modules/default.nix +++ b/nix/modules/default.nix @@ -19,5 +19,7 @@ ./printing.nix ./sensors.nix ./dns.nix + ./mounts.nix + ./nfs-mesh.nix ]; } diff --git a/nix/modules/mounts.nix b/nix/modules/mounts.nix new file mode 100644 index 0000000..9a7680c --- /dev/null +++ b/nix/modules/mounts.nix @@ -0,0 +1,31 @@ +{ + pkgs, + lib, + config, + ... +}: +{ + options.mounts = { + enable = lib.mkEnableOption "enable mounts" // { + default = true; + }; + }; + + config = lib.mkIf config.mounts.enable { + boot.supportedFilesystems = [ "nfs" ]; + services.rpcbind.enable = true; + + systemd.tmpfiles.rules = [ "d /mnt/data 0755 luca users -" ]; + fileSystems = { + "/mnt/data" = { + device = "rufus:/data"; + fsType = "nfs"; + options = [ + "x-systemd.automount" + "noauto" + "x-systemd.idle-timeout=600" + ]; + }; + }; + }; +} diff --git a/nix/modules/nfs-mesh.nix b/nix/modules/nfs-mesh.nix new file mode 100644 index 0000000..f70ff98 --- /dev/null +++ b/nix/modules/nfs-mesh.nix @@ -0,0 +1,113 @@ +{ + pkgs, + lib, + config, + ... +}: +let + cfg = config.nfs-mesh; + remoteHosts = lib.filter (h: h != config.networking.hostName) cfg.hosts; +in +{ + options.nfs-mesh = { + enable = lib.mkEnableOption "NFS mesh networking" // { + default = true; + }; + + hosts = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ + "usahara" + "kumatani" + "tux" + ]; + description = '' + List of hostnames participating in the NFS mesh. + Each host will export its configured path and mount all other hosts. + ''; + example = [ + "usahara" + "kumatani" + "tux" + ]; + }; + + exportPath = lib.mkOption { + type = lib.types.str; + default = "/home"; + description = '' + Path to export to other hosts in the mesh. + This will be mounted at /mnt/{hostname} on remote hosts. + ''; + example = "/home"; + }; + + exportOptions = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ + "rw" + "sync" + "no_subtree_check" + "no_root_squash" + ]; + description = '' + NFS export options. Default allows read-write access with no root squashing + since all hosts are on a trusted Tailscale network. + ''; + }; + + mountOptions = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ + "x-systemd.automount" + "noauto" + "x-systemd.idle-timeout=600" + "nfsvers=4.2" + "soft" + "timeo=10" + "retrans=3" + ]; + description = '' + NFS mount options. Uses automount for on-demand mounting with idle timeout. + Soft mount with short timeout to avoid hanging on unreachable hosts. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + boot.supportedFilesystems = [ "nfs" ]; + + services.rpcbind.enable = true; + + services.nfs.server = { + enable = true; + exports = '' + ${cfg.exportPath} 100.64.0.0/10(${lib.concatStringsSep "," cfg.exportOptions}) + ''; + }; + + systemd.tmpfiles.rules = map (host: "d /mnt/${host} 0755 luca users -") remoteHosts; + + fileSystems = lib.listToAttrs ( + map (host: { + name = "/mnt/${host}"; + value = { + device = "${host}:${cfg.exportPath}"; + fsType = "nfs"; + options = cfg.mountOptions; + }; + }) remoteHosts + ); + + systemd.services.nfs-server = { + requires = [ + "rpcbind.service" + "network-online.target" + ]; + after = [ + "rpcbind.service" + "network-online.target" + ]; + }; + }; +}