refactor: abstract NFS mount creation via custom options
This commit is contained in:
parent
d4d655e735
commit
1403b1f9c0
9 changed files with 93 additions and 120 deletions
|
|
@ -61,29 +61,26 @@ in {
|
||||||
virtualisation.containers.enable = lib.mkIf inUse true;
|
virtualisation.containers.enable = lib.mkIf inUse true;
|
||||||
};
|
};
|
||||||
|
|
||||||
fileSystems = let
|
homelab.nfsMounts = let
|
||||||
mkFileSystem = device: {
|
hugoBackup = "192.168.0.11:/mnt/BIG/BACKUP";
|
||||||
inherit device;
|
arrOptions = [
|
||||||
fsType = "nfs";
|
|
||||||
options = [
|
|
||||||
"rw"
|
|
||||||
"auto"
|
"auto"
|
||||||
"nfsvers=4.2"
|
|
||||||
"rsize=1048576" "wsize=1048576"
|
"rsize=1048576" "wsize=1048576"
|
||||||
"hard"
|
"hard"
|
||||||
"timeo=600" "retrans=2"
|
"timeo=600" "retrans=2"
|
||||||
"_netdev" "nosuid" "tcp"
|
"_netdev"
|
||||||
];
|
];
|
||||||
|
mkMount = device: {
|
||||||
|
inherit device;
|
||||||
|
extraOptions = arrOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
hugoBackup = "192.168.0.11:/mnt/BIG/BACKUP";
|
|
||||||
in lib.mkIf inUse {
|
in lib.mkIf inUse {
|
||||||
"/srv/bazarr-backup" = lib.mkIf cfg.bazarr.enable (mkFileSystem "${hugoBackup}/BAZARR");
|
"/srv/bazarr-backup" = lib.mkIf cfg.bazarr.enable (mkMount "${hugoBackup}/BAZARR");
|
||||||
"/srv/prowlarr-backup" = lib.mkIf cfg.bazarr.enable (mkFileSystem "${hugoBackup}/PROWLARR");
|
"/srv/prowlarr-backup" = lib.mkIf cfg.bazarr.enable (mkMount "${hugoBackup}/PROWLARR");
|
||||||
"/srv/qbittorrent" = lib.mkIf cfg.qbittorrent.enable (mkFileSystem "192.168.0.11:/mnt/SMALL/CONFIG/QBITTORRENT");
|
"/srv/qbittorrent" = lib.mkIf cfg.qbittorrent.enable (mkMount "192.168.0.11:/mnt/SMALL/CONFIG/QBITTORRENT");
|
||||||
"/srv/radarr-backup" = lib.mkIf cfg.radarr.enable (mkFileSystem "${hugoBackup}/RADARR");
|
"/srv/radarr-backup" = lib.mkIf cfg.radarr.enable (mkMount "${hugoBackup}/RADARR");
|
||||||
"/srv/sonarr-backup" = lib.mkIf cfg.sonarr.enable (mkFileSystem "${hugoBackup}/SONARR");
|
"/srv/sonarr-backup" = lib.mkIf cfg.sonarr.enable (mkMount "${hugoBackup}/SONARR");
|
||||||
"/srv/torrent" = mkFileSystem "192.168.0.11:/mnt/SMALL/MEDIA/TORRENT";
|
"/srv/torrent" = mkMount "192.168.0.11:/mnt/SMALL/MEDIA/TORRENT";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Make sure the Docker network exists.
|
# Make sure the Docker network exists.
|
||||||
|
|
|
||||||
|
|
@ -42,17 +42,13 @@ in {
|
||||||
shell = null;
|
shell = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
fileSystems."${books}" = {
|
homelab.nfsMounts."${books}" = {
|
||||||
device = "192.168.0.11:/mnt/SMALL/MEDIA/BOOKS";
|
device = "192.168.0.11:/mnt/SMALL/MEDIA/BOOKS";
|
||||||
fsType = "nfs";
|
extraOptions = [
|
||||||
options = [
|
|
||||||
"rw"
|
|
||||||
"auto"
|
"auto"
|
||||||
"nfsvers=4.2"
|
|
||||||
"rsize=1048576" "wsize=1048576"
|
"rsize=1048576" "wsize=1048576"
|
||||||
"soft"
|
|
||||||
"timeo=600" "retrans=2"
|
"timeo=600" "retrans=2"
|
||||||
"_netdev" "nosuid" "tcp"
|
"_netdev"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -66,17 +62,13 @@ in {
|
||||||
|
|
||||||
# Calibre desktop
|
# Calibre desktop
|
||||||
(lib.mkIf cfg.desktop.enable {
|
(lib.mkIf cfg.desktop.enable {
|
||||||
fileSystems."${calibre-config}" = {
|
homelab.nfsMounts."${calibre-config}" = {
|
||||||
device = "192.168.0.11:/mnt/SMALL/CONFIG/CALIBRE";
|
device = "192.168.0.11:/mnt/SMALL/CONFIG/CALIBRE";
|
||||||
fsType = "nfs";
|
extraOptions = [
|
||||||
options = [
|
|
||||||
"rw"
|
|
||||||
"auto"
|
"auto"
|
||||||
"nfsvers=4.2"
|
|
||||||
"rsize=1048576" "wsize=1048576"
|
"rsize=1048576" "wsize=1048576"
|
||||||
"soft"
|
|
||||||
"timeo=600" "retrans=2"
|
"timeo=600" "retrans=2"
|
||||||
"_netdev" "nosuid" "tcp"
|
"_netdev"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -124,17 +116,13 @@ in {
|
||||||
|
|
||||||
# Calibre Web
|
# Calibre Web
|
||||||
(lib.mkIf cfg.web.enable {
|
(lib.mkIf cfg.web.enable {
|
||||||
fileSystems."${calibre-web-config}" = {
|
homelab.nfsMounts."${calibre-web-config}" = {
|
||||||
device = "192.168.0.11:/mnt/SMALL/CONFIG/CALIBRE-WEB";
|
device = "192.168.0.11:/mnt/SMALL/CONFIG/CALIBRE-WEB";
|
||||||
fsType = "nfs";
|
extraOptions = [
|
||||||
options = [
|
|
||||||
"rw"
|
|
||||||
"auto"
|
"auto"
|
||||||
"nfsvers=4.2"
|
|
||||||
"rsize=1048576" "wsize=1048576"
|
"rsize=1048576" "wsize=1048576"
|
||||||
"soft"
|
|
||||||
"timeo=600" "retrans=2"
|
"timeo=600" "retrans=2"
|
||||||
"_netdev" "nosuid" "tcp"
|
"_netdev"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,13 @@ in {
|
||||||
lib.mkIf cfg.enable {
|
lib.mkIf cfg.enable {
|
||||||
homelab.virtualisation.containers.enable = true;
|
homelab.virtualisation.containers.enable = true;
|
||||||
|
|
||||||
fileSystems."/srv/freshrss" = {
|
homelab.nfsMounts."/srv/freshrss" = {
|
||||||
device = "192.168.0.11:/mnt/SMALL/CONFIG/FRESHRSS";
|
device = "192.168.0.11:/mnt/SMALL/CONFIG/FRESHRSS";
|
||||||
fsType = "nfs";
|
extraOptions = [
|
||||||
options = [
|
|
||||||
"rw"
|
|
||||||
"auto"
|
"auto"
|
||||||
"nfsvers=4.2"
|
"timeo=600"
|
||||||
"async" "soft" "timeo=600"
|
|
||||||
"retrans=2"
|
"retrans=2"
|
||||||
"_netdev"
|
"_netdev"
|
||||||
"nosuid"
|
|
||||||
"tcp"
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,32 +40,13 @@ in {
|
||||||
|
|
||||||
# Use filesystem mounts because rootless containers otherwise don't have access to the mount path (nested in docker directories).
|
# Use filesystem mounts because rootless containers otherwise don't have access to the mount path (nested in docker directories).
|
||||||
# You could probably fix this by modifying the access rights on the path, but what would the point of that be?
|
# You could probably fix this by modifying the access rights on the path, but what would the point of that be?
|
||||||
fileSystems = {
|
homelab.nfsMounts = {
|
||||||
# Mount options:
|
|
||||||
# - hard: retry requests indefinitely if the server becomes unresponsive.
|
|
||||||
# - nosuid: prevent set-user-id and set-group-id bits
|
|
||||||
"/srv/gitea-config" = {
|
"/srv/gitea-config" = {
|
||||||
device = "192.168.0.11:/mnt/SMALL/CONFIG/GITEA";
|
device = "192.168.0.11:/mnt/SMALL/CONFIG/GITEA";
|
||||||
fsType = "nfs";
|
|
||||||
options = [
|
|
||||||
"rw"
|
|
||||||
"nfsvers=4.2"
|
|
||||||
"async" "soft" "timeo=100" "retry=50" "actimeo=1800" "lookupcache=all"
|
|
||||||
"nosuid"
|
|
||||||
"tcp"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
"/srv/gitea-git" = {
|
"/srv/gitea-git" = {
|
||||||
device = "192.168.0.11:/mnt/SMALL/DATA/GIT";
|
device = "192.168.0.11:/mnt/SMALL/DATA/GIT";
|
||||||
fsType = "nfs";
|
|
||||||
options = [
|
|
||||||
"rw"
|
|
||||||
"nfsvers=4.2"
|
|
||||||
"async" "soft" "timeo=100" "retry=50" "actimeo=1800" "lookupcache=all"
|
|
||||||
"nosuid"
|
|
||||||
"tcp"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,15 +34,10 @@ in {
|
||||||
shell = null;
|
shell = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
fileSystems."${homepage-config}" = {
|
homelab.nfsMounts."${homepage-config}" = {
|
||||||
device = "192.168.0.11:/mnt/SMALL/CONFIG/HOMEPAGE";
|
device = "192.168.0.11:/mnt/SMALL/CONFIG/HOMEPAGE";
|
||||||
fsType = "nfs";
|
extraOptions = [
|
||||||
options = [
|
|
||||||
"rw"
|
|
||||||
"auto"
|
"auto"
|
||||||
"nfsvers=4.2"
|
|
||||||
"async" "soft" "timeo=100" "retry=50" "actimeo=1800" "lookupcache=all"
|
|
||||||
"nosuid" "tcp"
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,42 +25,15 @@ in {
|
||||||
virtualisation.containers.enable = true;
|
virtualisation.containers.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
fileSystems = {
|
homelab.nfsMounts = let
|
||||||
"/srv/audio" = {
|
mkMount = device: {
|
||||||
device = "192.168.0.11:/mnt/SMALL/MEDIA/AUDIO";
|
inherit device;
|
||||||
fsType = "nfs";
|
readOnly = true;
|
||||||
options = [
|
|
||||||
"ro"
|
|
||||||
"nfsvers=4.2"
|
|
||||||
"async" "soft"
|
|
||||||
"timeo=100" "retry=50" "actimeo=1800" "lookupcache=all"
|
|
||||||
"nosuid" "tcp"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
"/srv/homevideo" = {
|
|
||||||
device = "192.168.0.11:/mnt/BIG/MEDIA/HOMEVIDEO/ARCHIVE";
|
|
||||||
fsType = "nfs";
|
|
||||||
options = [
|
|
||||||
"ro"
|
|
||||||
"nfsvers=4.2"
|
|
||||||
"async" "soft"
|
|
||||||
"timeo=100" "retry=50" "actimeo=1800" "lookupcache=all"
|
|
||||||
"nosuid" "tcp"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
"/srv/photo" = {
|
|
||||||
device = "192.168.0.11:/mnt/BIG/MEDIA/PHOTO/ARCHIVE";
|
|
||||||
fsType = "nfs";
|
|
||||||
options = [
|
|
||||||
"ro"
|
|
||||||
"nfsvers=4.2"
|
|
||||||
"async" "soft"
|
|
||||||
"timeo=100" "retry=50" "actimeo=1800" "lookupcache=all"
|
|
||||||
"nosuid" "tcp"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
in {
|
||||||
|
"/srv/audio" = mkMount "192.168.0.11:/mnt/SMALL/MEDIA/AUDIO";
|
||||||
|
"/srv/homevideo" = mkMount "192.168.0.11:/mnt/BIG/MEDIA/HOMEVIDEO/ARCHIVE";
|
||||||
|
"/srv/photo" = mkMount "192.168.0.11:/mnt/BIG/MEDIA/PHOTO/ARCHIVE";
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.jellyfin = {
|
users.users.jellyfin = {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
imports = [
|
imports = [
|
||||||
./docker.nix
|
./docker.nix
|
||||||
./monitoring.nix
|
./monitoring.nix
|
||||||
|
./nfs.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
|
||||||
46
modules/common/nfs.nix
Normal file
46
modules/common/nfs.nix
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
options.homelab.nfsMounts = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (lib.types.submodule {
|
||||||
|
options = {
|
||||||
|
device = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = "The NFS device, e.g. 192.168.0.11:/mnt/POOL/DATA";
|
||||||
|
};
|
||||||
|
readOnly = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Whether to mount the NFS share read-only";
|
||||||
|
};
|
||||||
|
extraOptions = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [
|
||||||
|
"async"
|
||||||
|
"soft"
|
||||||
|
"timeo=100"
|
||||||
|
"retry=50"
|
||||||
|
"actimeo=1800"
|
||||||
|
"lookupcache=all"
|
||||||
|
];
|
||||||
|
description = "Extra NFS mount options to append";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = {};
|
||||||
|
description = "NFS mounts to automatically configure with standard homelab options";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
fileSystems = lib.mapAttrs (path: cfg: {
|
||||||
|
device = cfg.device;
|
||||||
|
fsType = "nfs";
|
||||||
|
options = [
|
||||||
|
"nfsvers=4.2"
|
||||||
|
"nosuid"
|
||||||
|
"tcp"
|
||||||
|
] ++ (if cfg.readOnly then [ "ro" ] else [ "rw" ])
|
||||||
|
++ cfg.extraOptions;
|
||||||
|
}) config.homelab.nfsMounts;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -25,17 +25,14 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
fileSystems."${cfg.hostPath}" = {
|
homelab.nfsMounts."${cfg.hostPath}" = {
|
||||||
device = "192.168.0.11:${remotePath}";
|
device = "192.168.0.11:${remotePath}";
|
||||||
fsType = "nfs";
|
readOnly = permissionsOption == "ro";
|
||||||
options = [
|
extraOptions = [
|
||||||
permissionsOption
|
|
||||||
"auto"
|
"auto"
|
||||||
"nfsvers=4.2"
|
|
||||||
"async" "soft"
|
|
||||||
"rsize=1048576" "wsize=1048576"
|
"rsize=1048576" "wsize=1048576"
|
||||||
"timeo=600" "retry=50" "retrans=2" "actimeo=1800" "lookupcache=all"
|
"timeo=600" "retrans=2"
|
||||||
"_netdev" "nosuid" "tcp"
|
"_netdev"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue