chore(arr): Use functions

This commit is contained in:
Tibo De Peuter 2025-10-13 20:35:46 +02:00
parent b2e904306b
commit 2c195bf807
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2

View file

@ -12,7 +12,16 @@ let
PGID = toString config.users.groups.media.gid; PGID = toString config.users.groups.media.gid;
UMASK = "002"; UMASK = "002";
in { in {
options.homelab.apps.arr = { options.homelab.apps.arr = let
mkAppOption = appName: {
enable = lib.mkEnableOption "${appName} using Docker";
exposePorts = lib.mkOption {
type = lib.types.bool;
description = "Expose ${appName} port";
default = cfg.exposePorts;
};
};
in {
enable = lib.mkEnableOption "Arr Stack using Docker"; enable = lib.mkEnableOption "Arr Stack using Docker";
exposePorts = lib.mkOption { exposePorts = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
@ -21,46 +30,11 @@ in {
default = ! config.homelab.apps.traefik.enable; default = ! config.homelab.apps.traefik.enable;
}; };
bazarr = { bazarr = mkAppOption "Bazarr";
enable = lib.mkEnableOption "Bazarr using Docker"; prowlarr = mkAppOption "Prowlarr";
exposePorts = lib.mkOption { qbittorrent = mkAppOption "qBittorrent";
type = lib.types.bool; radarr = mkAppOption "Radarr";
description = "Expose Bazarr port"; sonarr = mkAppOption "Sonarr";
default = cfg.exposePorts;
};
};
prowlarr = {
enable = lib.mkEnableOption "Prowlarr using Docker";
exposePorts = lib.mkOption {
type = lib.types.bool;
description = "Expose Prowlarr port";
default = cfg.exposePorts;
};
};
qbittorrent = {
enable = lib.mkEnableOption "qBittorrent using Docker";
exposePorts = lib.mkOption {
type = lib.types.bool;
description = "Expose qBittorrent port";
default = cfg.exposePorts;
};
};
radarr = {
enable = lib.mkEnableOption "Radarr using Docker";
exposePorts = lib.mkOption {
type = lib.types.bool;
description = "Expose Radarr port";
default = cfg.exposePorts;
};
};
sonarr = {
enable = lib.mkEnableOption "Sonarr using Docker";
exposePorts = lib.mkOption {
type = lib.types.bool;
description = "Expose Sonarr port";
default = cfg.exposePorts;
};
};
}; };
config = { config = {
@ -87,9 +61,9 @@ in {
virtualisation.containers.enable = lib.mkIf inUse true; virtualisation.containers.enable = lib.mkIf inUse true;
}; };
fileSystems = lib.mkIf inUse { fileSystems = let
"/srv/bazarr-backup" = lib.mkIf cfg.bazarr.enable { mkFileSystem = device: {
device = "192.168.0.11:/mnt/BIG/BACKUP/BAZARR"; inherit device;
fsType = "nfs"; fsType = "nfs";
options = [ options = [
"rw" "rw"
@ -102,75 +76,14 @@ in {
]; ];
}; };
"/srv/prowlarr-backup" = lib.mkIf cfg.prowlarr.enable { hugoBackup = "192.168.0.11:/mnt/BIG/BACKUP";
device = "192.168.0.11:/mnt/BIG/BACKUP/PROWLARR"; in lib.mkIf inUse {
fsType = "nfs"; "/srv/bazarr-backup" = lib.mkIf cfg.bazarr.enable (mkFileSystem "${hugoBackup}/BAZARR");
options = [ "/srv/prowlarr-backup" = lib.mkIf cfg.bazarr.enable (mkFileSystem "${hugoBackup}/PROWLARR");
"rw" "/srv/qbittorrent" = lib.mkIf cfg.qbittorrent.enable (mkFileSystem "192.168.0.11:/mnt/SMALL/CONFIG/QBITTORRENT");
"auto" "/srv/radarr-backup" = lib.mkIf cfg.radarr.enable (mkFileSystem "${hugoBackup}/RADARR");
"nfsvers=4.2" "/srv/sonarr-backup" = lib.mkIf cfg.sonarr.enable (mkFileSystem "${hugoBackup}/SONARR");
"rsize=1048576" "wsize=1048576" "/srv/torrent" = mkFileSystem "192.168.0.11:/mnt/SMALL/MEDIA/TORRENT";
"hard"
"timeo=600" "retrans=2"
"_netdev" "nosuid" "tcp"
];
};
"/srv/qbittorrent" = lib.mkIf cfg.qbittorrent.enable {
device = "192.168.0.11:/mnt/SMALL/CONFIG/QBITTORRENT";
fsType = "nfs";
options = [
"rw"
"auto"
"nfsvers=4.2"
"rsize=1048576" "wsize=1048576"
"hard"
"timeo=600" "retrans=2"
"_netdev" "nosuid" "tcp"
];
};
"/srv/radarr-backup" = lib.mkIf cfg.radarr.enable {
device = "192.168.0.11:/mnt/BIG/BACKUP/RADARR";
fsType = "nfs";
options = [
"rw"
"auto"
"nfsvers=4.2"
"rsize=1048576" "wsize=1048576"
"hard"
"timeo=600" "retrans=2"
"_netdev" "nosuid" "tcp"
];
};
"/srv/sonarr-backup" = lib.mkIf cfg.sonarr.enable {
device = "192.168.0.11:/mnt/BIG/BACKUP/SONARR";
fsType = "nfs";
options = [
"rw"
"auto"
"nfsvers=4.2"
"rsize=1048576" "wsize=1048576"
"hard"
"timeo=600" "retrans=2"
"_netdev" "nosuid" "tcp"
];
};
"/srv/torrent" = {
device = "192.168.0.11:/mnt/SMALL/MEDIA/TORRENT";
fsType = "nfs";
options = [
"rw"
"auto"
"nfsvers=4.2"
"rsize=1048576" "wsize=1048576"
"hard"
"timeo=600" "retrans=2"
"_netdev" "nosuid" "tcp"
];
};
}; };
# Make sure the Docker network exists. # Make sure the Docker network exists.
@ -195,45 +108,24 @@ in {
}; };
# Create a user for each app. # Create a user for each app.
users.users = { users.users = let
bazarr = lib.mkIf cfg.bazarr.enable { mkUser = uid: {
uid = lib.mkForce 3003; uid = lib.mkForce uid;
isSystemUser = true; isSystemUser = true;
group = config.users.groups.media.name; group = config.users.groups.media.name;
home = "/var/empty"; home = "/var/empty";
shell = null; shell = null;
}; };
prowlarr = lib.mkIf cfg.prowlarr.enable { in {
uid = lib.mkForce 3004; bazarr = lib.mkIf cfg.bazarr.enable (mkUser 3003);
isSystemUser = true; prowlarr = lib.mkIf cfg.prowlarr.enable (mkUser 3004);
group = config.users.groups.media.name; qbittorrent = lib.mkIf cfg.qbittorrent.enable (mkUser 3005) // {
home = "/var/empty";
shell = null;
};
qbittorrent = lib.mkIf cfg.qbittorrent.enable {
uid = lib.mkForce 3005;
isSystemUser = true;
group = config.users.groups.media.name;
extraGroups = [ extraGroups = [
config.users.groups.apps.name config.users.groups.apps.name
]; ];
home = "/var/empty";
shell = null;
};
radarr = lib.mkIf cfg.radarr.enable {
uid = lib.mkForce 3006;
isSystemUser = true;
group = config.users.groups.media.name;
home = "/var/empty";
shell = null;
};
sonarr = lib.mkIf cfg.sonarr.enable {
uid = lib.mkForce 3007;
isSystemUser = true;
group = config.users.groups.media.name;
home = "/var/empty";
shell = null;
}; };
radarr = lib.mkIf cfg.radarr.enable (mkUser 3006);
sonarr = lib.mkIf cfg.sonarr.enable (mkUser 3007);
}; };
virtualisation.oci-containers.containers = let virtualisation.oci-containers.containers = let