feat: migrate remaining applications, services, and user configurations
This commit is contained in:
parent
3a8f6e6451
commit
2960480557
26 changed files with 2903 additions and 0 deletions
303
modules/apps/arr/default.nix
Normal file
303
modules/apps/arr/default.nix
Normal file
|
|
@ -0,0 +1,303 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.homelab.apps.arr;
|
||||
|
||||
networkName = "arrStack";
|
||||
proxyNet = config.homelab.apps.traefik.sharedNetworkName;
|
||||
|
||||
appNames = [ "bazarr" "prowlarr" "qbittorrent" "radarr" "sonarr" ];
|
||||
inUse = builtins.any (app: cfg.${app}.enable) appNames;
|
||||
|
||||
PGID = toString config.users.groups.media.gid;
|
||||
UMASK = "002";
|
||||
in {
|
||||
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";
|
||||
exposePorts = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
description = "Expose all app ports";
|
||||
# Only expose ports by default if Traefik is not in use.
|
||||
default = ! config.homelab.apps.traefik.enable;
|
||||
};
|
||||
|
||||
bazarr = mkAppOption "Bazarr";
|
||||
prowlarr = mkAppOption "Prowlarr";
|
||||
qbittorrent = mkAppOption "qBittorrent";
|
||||
radarr = mkAppOption "Radarr";
|
||||
sonarr = mkAppOption "Sonarr";
|
||||
};
|
||||
|
||||
config = {
|
||||
homelab = {
|
||||
users = lib.mkIf inUse {
|
||||
apps.enable = true;
|
||||
media.enable = true;
|
||||
};
|
||||
|
||||
# "Master switch": Enable all apps.
|
||||
apps.arr = lib.mkIf cfg.enable {
|
||||
bazarr.enable = true;
|
||||
prowlarr.enable = true;
|
||||
qbittorrent.enable = true;
|
||||
radarr.enable = true;
|
||||
sonarr.enable = true;
|
||||
};
|
||||
|
||||
fileSystems.media.video = {
|
||||
enable = true;
|
||||
permissions = [ "read" "write" ];
|
||||
};
|
||||
|
||||
virtualisation.containers.enable = lib.mkIf inUse true;
|
||||
};
|
||||
|
||||
fileSystems = let
|
||||
mkFileSystem = device: {
|
||||
inherit device;
|
||||
fsType = "nfs";
|
||||
options = [
|
||||
"rw"
|
||||
"auto"
|
||||
"nfsvers=4.2"
|
||||
"rsize=1048576" "wsize=1048576"
|
||||
"hard"
|
||||
"timeo=600" "retrans=2"
|
||||
"_netdev" "nosuid" "tcp"
|
||||
];
|
||||
};
|
||||
|
||||
hugoBackup = "192.168.0.11:/mnt/BIG/BACKUP";
|
||||
in lib.mkIf inUse {
|
||||
"/srv/bazarr-backup" = lib.mkIf cfg.bazarr.enable (mkFileSystem "${hugoBackup}/BAZARR");
|
||||
"/srv/prowlarr-backup" = lib.mkIf cfg.bazarr.enable (mkFileSystem "${hugoBackup}/PROWLARR");
|
||||
"/srv/qbittorrent" = lib.mkIf cfg.qbittorrent.enable (mkFileSystem "192.168.0.11:/mnt/SMALL/CONFIG/QBITTORRENT");
|
||||
"/srv/radarr-backup" = lib.mkIf cfg.radarr.enable (mkFileSystem "${hugoBackup}/RADARR");
|
||||
"/srv/sonarr-backup" = lib.mkIf cfg.sonarr.enable (mkFileSystem "${hugoBackup}/SONARR");
|
||||
"/srv/torrent" = mkFileSystem "192.168.0.11:/mnt/SMALL/MEDIA/TORRENT";
|
||||
};
|
||||
|
||||
# Make sure the Docker network exists.
|
||||
systemd.services."docker-${networkName}-create-network" = lib.mkIf inUse {
|
||||
description = "Create Docker network for ${networkName}";
|
||||
requiredBy = [
|
||||
"docker-bazarr.service"
|
||||
"docker-prowlarr.service"
|
||||
"docker-qbittorrent.service"
|
||||
"docker-radarr.service"
|
||||
"docker-sonarr.service"
|
||||
];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
script = ''
|
||||
if ! ${pkgs.docker}/bin/docker network ls | grep -q ${networkName}; then
|
||||
${pkgs.docker}/bin/docker network create ${networkName}
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
# Create a user for each app.
|
||||
users.users = let
|
||||
mkUser = uid: {
|
||||
uid = lib.mkForce uid;
|
||||
isSystemUser = true;
|
||||
group = config.users.groups.media.name;
|
||||
home = "/var/empty";
|
||||
shell = null;
|
||||
};
|
||||
in {
|
||||
bazarr = lib.mkIf cfg.bazarr.enable (mkUser 3003);
|
||||
prowlarr = lib.mkIf cfg.prowlarr.enable (mkUser 3004);
|
||||
qbittorrent = lib.mkIf cfg.qbittorrent.enable (mkUser 3005) // {
|
||||
extraGroups = [
|
||||
config.users.groups.apps.name
|
||||
];
|
||||
};
|
||||
radarr = lib.mkIf cfg.radarr.enable (mkUser 3006);
|
||||
sonarr = lib.mkIf cfg.sonarr.enable (mkUser 3007);
|
||||
};
|
||||
|
||||
virtualisation.oci-containers.containers = let
|
||||
videoHostPath = config.homelab.fileSystems.media.video.hostPath;
|
||||
in {
|
||||
bazarr = let
|
||||
port = 6767;
|
||||
in lib.mkIf cfg.bazarr.enable {
|
||||
hostname = "bazarr";
|
||||
image = "ghcr.io/hotio/bazarr:release-1.5.2";
|
||||
autoStart = true;
|
||||
ports = lib.mkIf cfg.bazarr.exposePorts [
|
||||
"${toString port}:${toString port}/tcp"
|
||||
"${toString port}:${toString port}/udp"
|
||||
];
|
||||
extraOptions = [
|
||||
"--network=${networkName}"
|
||||
"--network=${proxyNet}"
|
||||
];
|
||||
environment = {
|
||||
PUID = toString config.users.users.bazarr.uid;
|
||||
inherit PGID UMASK;
|
||||
TZ = config.time.timeZone;
|
||||
WEBUI_PORTS = "${toString port}/tcp,${toString port}/udp";
|
||||
};
|
||||
volumes = [
|
||||
"bazarr-config:/config"
|
||||
|
||||
"/srv/bazarr-backup:/config/backup"
|
||||
|
||||
"${videoHostPath}/Films:/media/movies"
|
||||
"${videoHostPath}/Series:/media/series"
|
||||
];
|
||||
labels = {
|
||||
"traefik.enable" = "true";
|
||||
"traefik.docker.network" = proxyNet;
|
||||
"traefik.http.routers.bazarr.rule" = "Host(`bazarr.depeuter.dev`)";
|
||||
"traefik.http.services.bazarr.loadbalancer.server.port" = toString port;
|
||||
};
|
||||
};
|
||||
|
||||
prowlarr = let
|
||||
port = 9696;
|
||||
in lib.mkIf cfg.prowlarr.enable {
|
||||
hostname = "prowlarr";
|
||||
image = "ghcr.io/hotio/prowlarr:release-2.0.5.5160";
|
||||
autoStart = true;
|
||||
ports = lib.mkIf cfg.prowlarr.exposePorts [
|
||||
"${toString port}:${toString port}/tcp"
|
||||
];
|
||||
extraOptions = [
|
||||
"--network=${networkName}"
|
||||
"--network=${proxyNet}"
|
||||
];
|
||||
environment = {
|
||||
PUID = toString config.users.users.prowlarr.uid;
|
||||
inherit PGID UMASK;
|
||||
TZ = config.time.timeZone;
|
||||
};
|
||||
volumes = [
|
||||
"prowlarr-config:/config"
|
||||
|
||||
"/srv/prowlarr-backup:/config/Backups"
|
||||
];
|
||||
labels = {
|
||||
"traefik.enable" = "true";
|
||||
"traefik.docker.network" = proxyNet;
|
||||
"traefik.http.routers.prowlarr.rule" = "Host(`prowlarr.depeuter.dev`)";
|
||||
"traefik.http.services.prowlarr.loadbalancer.server.port" = toString port;
|
||||
};
|
||||
};
|
||||
|
||||
qbittorrent = let
|
||||
port = 10095;
|
||||
in lib.mkIf cfg.qbittorrent.enable {
|
||||
hostname = "qbittorrent";
|
||||
image = "ghcr.io/hotio/qbittorrent:release-5.1.2";
|
||||
autoStart = true;
|
||||
ports = lib.mkIf cfg.qbittorrent.exposePorts [
|
||||
"${toString port}:${toString port}/tcp"
|
||||
"${toString port}:${toString port}/udp"
|
||||
];
|
||||
extraOptions = [
|
||||
"--network=${networkName}"
|
||||
"--network=${proxyNet}"
|
||||
];
|
||||
environment = {
|
||||
PUID = toString config.users.users.qbittorrent.uid;
|
||||
inherit PGID UMASK;
|
||||
TZ = config.time.timeZone;
|
||||
WEBUI_PORTS = "${toString port}/tcp,${toString port}/udp";
|
||||
};
|
||||
volumes = [
|
||||
"/srv/qbittorrent:/config"
|
||||
|
||||
"/srv/torrent:/media/cache"
|
||||
];
|
||||
labels = {
|
||||
"traefik.enable" = "true";
|
||||
"traefik.docker.network" = proxyNet;
|
||||
"traefik.http.routers.qbittorrent.rule" = "Host(`qb.depeuter.dev`)";
|
||||
"traefik.http.services.qbittorrent.loadbalancer.server.port" = toString port;
|
||||
};
|
||||
};
|
||||
|
||||
radarr = let
|
||||
port = 7878;
|
||||
in lib.mkIf cfg.radarr.enable {
|
||||
hostname = "radarr";
|
||||
image = "ghcr.io/hotio/radarr:testing-5.28.0.10205";
|
||||
autoStart = true;
|
||||
ports = lib.mkIf cfg.radarr.exposePorts [
|
||||
"${toString port}:${toString port}/tcp"
|
||||
];
|
||||
extraOptions = [
|
||||
"--network=${networkName}"
|
||||
"--network=${proxyNet}"
|
||||
];
|
||||
environment = {
|
||||
PUID = toString config.users.users.radarr.uid;
|
||||
inherit PGID UMASK;
|
||||
TZ = config.time.timeZone;
|
||||
};
|
||||
volumes = [
|
||||
"radarr-config:/config"
|
||||
|
||||
"/srv/radarr-backup:/config/Backups"
|
||||
|
||||
"/srv/torrent:/media/cache"
|
||||
"${videoHostPath}/Films:/media/movies"
|
||||
];
|
||||
labels = {
|
||||
"traefik.enable" = "true";
|
||||
"traefik.docker.network" = proxyNet;
|
||||
"traefik.http.routers.radarr.rule" = "Host(`radarr.depeuter.dev`)";
|
||||
"traefik.http.services.radarr.loadbalancer.server.port" = toString port;
|
||||
};
|
||||
};
|
||||
|
||||
sonarr = let
|
||||
port = 8989;
|
||||
in lib.mkIf cfg.sonarr.enable {
|
||||
hostname = "sonarr";
|
||||
image = "ghcr.io/hotio/sonarr:release-4.0.15.2941";
|
||||
autoStart = true;
|
||||
ports = lib.mkIf cfg.sonarr.exposePorts [
|
||||
"${toString port}:${toString port}/tcp"
|
||||
];
|
||||
extraOptions = [
|
||||
"--network=${networkName}"
|
||||
"--network=${proxyNet}"
|
||||
];
|
||||
environment = {
|
||||
PUID = toString config.users.users.sonarr.uid;
|
||||
inherit PGID UMASK;
|
||||
TZ = config.time.timeZone;
|
||||
};
|
||||
volumes = [
|
||||
"sonarr-config:/config"
|
||||
|
||||
"/srv/sonarr-backup:/config/Backups"
|
||||
|
||||
"/srv/torrent:/media/cache"
|
||||
"${videoHostPath}/Series:/media/series"
|
||||
];
|
||||
labels = {
|
||||
"traefik.enable" = "true";
|
||||
"traefik.docker.network" = proxyNet;
|
||||
"traefik.http.routers.sonarr.rule" = "Host(`sonarr.depeuter.dev`)";
|
||||
"traefik.http.services.sonarr.loadbalancer.server.port" = toString port;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue