From e77ca8fcebfd4ef370e7fb2a33d1ac128b9f3037 Mon Sep 17 00:00:00 2001 From: rope Date: Mon, 4 May 2026 02:27:50 -0700 Subject: [PATCH] Update services/sabnzbd.nix --- services/sabnzbd.nix | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/services/sabnzbd.nix b/services/sabnzbd.nix index 9b74cb0..6b38cc5 100644 --- a/services/sabnzbd.nix +++ b/services/sabnzbd.nix @@ -1,12 +1,36 @@ { config, pkgs, lib, ... }: +let + patchConfig = pkgs.writeShellScript "sabnzbd-patch-config" '' + CONFIG=/var/lib/sabnzbd/sabnzbd.ini + HOSTNAME=sabnzbd.nordhammer.it + if [ ! -f "$CONFIG" ]; then + printf '[misc]\nhost_whitelist = %s\nport = 8085\n' "$HOSTNAME" > "$CONFIG" + exit 0 + fi + ${pkgs.python3}/bin/python3 - <<'EOF' +import configparser, os, sys +config_file = '/var/lib/sabnzbd/sabnzbd.ini' +hostname = 'sabnzbd.nordhammer.it' +c = configparser.RawConfigParser() +c.read(config_file) +if not c.has_section('misc'): + c.add_section('misc') +wl = c.get('misc', 'host_whitelist', fallback='') +entries = [h.strip() for h in wl.split(',') if h.strip()] +if hostname not in entries: + entries.append(hostname) + c.set('misc', 'host_whitelist', ','.join(entries)) + with open(config_file, 'w') as f: + c.write(f) +EOF + ''; +in { config = lib.mkIf (config.networking.hostName == "FredOS-Mediaserver") { - users.users.sabnzbd = { isSystemUser = true; group = "media"; }; - systemd.tmpfiles.rules = [ "d /var/lib/sabnzbd 0755 sabnzbd media -" "Z /var/lib/sabnzbd 0755 sabnzbd media -" @@ -15,7 +39,6 @@ "d /mnt/storage/usenet/incomplete 2775 sabnzbd media -" "Z /mnt/storage/usenet/incomplete 2775 sabnzbd media -" ]; - systemd.services.sabnzbd = { description = "SABnzbd usenet downloader"; after = [ "network.target" ]; @@ -24,7 +47,7 @@ Type = "simple"; User = "sabnzbd"; Group = "media"; - # --server overrides the port in sabnzbd.ini on each start + ExecStartPre = patchConfig; ExecStart = "${pkgs.sabnzbd}/bin/sabnzbd --config-file /var/lib/sabnzbd/sabnzbd.ini --server 127.0.0.1:8085"; Restart = "on-failure"; UMask = "0002";