From 8cb31d92140ccd5c3cc404a27f87182b9e45ec9b Mon Sep 17 00:00:00 2001 From: cnst Date: Mon, 21 Jul 2025 13:56:43 +0200 Subject: [PATCH] nfs --- hosts/kima/modules.nix | 5 ++ hosts/sobotka/modules.nix | 5 ++ modules/default.nix | 1 + modules/nixos/services/nfs/default.nix | 67 ++++++++++++++++++++++++++ modules/server/qbittorrent/default.nix | 13 +++++ 5 files changed, 91 insertions(+) create mode 100644 modules/nixos/services/nfs/default.nix diff --git a/hosts/kima/modules.nix b/hosts/kima/modules.nix index afb549d7..248f0b0a 100644 --- a/hosts/kima/modules.nix +++ b/hosts/kima/modules.nix @@ -175,6 +175,11 @@ mullvad = { enable = true; }; + nfs = { + enable = true; + server.enable = false; + client.enable = true; + }; nix-ld = { enable = false; }; diff --git a/hosts/sobotka/modules.nix b/hosts/sobotka/modules.nix index 9768dbaa..b187e048 100644 --- a/hosts/sobotka/modules.nix +++ b/hosts/sobotka/modules.nix @@ -167,6 +167,11 @@ mullvad = { enable = true; }; + nfs = { + enable = true; + server.enable = true; + client.enable = false; + }; nix-ld = { enable = false; }; diff --git a/modules/default.nix b/modules/default.nix index 0ea881d1..2a79f530 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -100,6 +100,7 @@ ./nixos/services/kanata ./nixos/services/locate ./nixos/services/mullvad + ./nixos/services/nfs ./nixos/services/nix-ld ./nixos/services/openssh ./nixos/services/pcscd diff --git a/modules/nixos/services/nfs/default.nix b/modules/nixos/services/nfs/default.nix new file mode 100644 index 00000000..35870b5b --- /dev/null +++ b/modules/nixos/services/nfs/default.nix @@ -0,0 +1,67 @@ +{ + config, + lib, + ... +}: let + inherit (lib) mkIf mkEnableOption mkOption types; + cfg = config.nixos.services.nfs; +in { + options.nixos.services.nfs = { + enable = mkEnableOption "Enable NFS support"; + + server = { + enable = mkEnableOption "Enable the NFS server"; + exports = mkOption { + type = types.str; + default = "/shared *(rw,async,wdelay,root_squash,no_subtree_check)"; + description = "NFS export entries"; + }; + }; + + client = { + enable = mkEnableOption "Enable NFS client mounting"; + mountPoint = mkOption { + type = types.str; + default = "/shared"; + description = "Mount point for NFS share"; + }; + device = mkOption { + type = types.str; + default = "sobotka:/shared"; + description = "Remote NFS device"; + }; + fsType = mkOption { + type = types.str; + default = "nfs4"; + description = "Filesystem type"; + }; + options = mkOption { + type = types.listOf types.str; + default = ["x-systemd.automount"]; + description = "Mount options"; + }; + }; + }; + + config = mkIf cfg.enable { + boot.supportedFilesystems = ["nfs"]; + services.rpcbind.enable = true; + networking.firewall = { + allowedTCPPorts = [2049 4000 4001 4002]; + allowedUDPPorts = [2049 4000 4001 4002]; + }; + + services.nfs.server = mkIf cfg.server.enable { + enable = true; + exports = cfg.server.exports; + }; + + fileSystems = mkIf cfg.client.enable { + "${cfg.client.mountPoint}" = { + device = cfg.client.device; + fsType = cfg.client.fsType; + options = cfg.client.options; + }; + }; + }; +} diff --git a/modules/server/qbittorrent/default.nix b/modules/server/qbittorrent/default.nix index 89997911..69e0d46f 100644 --- a/modules/server/qbittorrent/default.nix +++ b/modules/server/qbittorrent/default.nix @@ -70,6 +70,7 @@ in { volumes = [ "config:/storage/volumes/config" "config:/storage/volumes/downloads" + "/var/lib/qbittorrent:/config" ]; environmentFiles = [ config.age.secrets.gluetunEnv.path @@ -106,6 +107,18 @@ in { }; }; }; + + environment.persistence."/persist/backup" = { + directories = [ + { + directory = "/var/lib/qbittorrent"; + user = "qbittorrent"; + group = "qbittorrent"; + mode = "0750"; + } + ]; + }; + users = { users.qbittorrent = { uid = cfg.uid;