nixos/services/sabnzbd.nix

60 lines
1.8 KiB
Nix
Raw Normal View History

2026-05-04 01:40:03 -07:00
{ config, pkgs, lib, ... }:
2026-05-04 02:27:50 -07:00
let
patchConfig = pkgs.writeShellScript "sabnzbd-patch-config" ''
CONFIG=/var/lib/sabnzbd/sabnzbd.ini
HOSTNAME=sabnzbd.nordhammer.it
2026-05-04 02:29:10 -07:00
2026-05-04 02:27:50 -07:00
if [ ! -f "$CONFIG" ]; then
printf '[misc]\nhost_whitelist = %s\nport = 8085\n' "$HOSTNAME" > "$CONFIG"
exit 0
fi
2026-05-04 02:29:10 -07:00
2026-05-04 02:40:44 -07:00
if ${pkgs.gnugrep}/bin/grep -q "^host_whitelist" "$CONFIG"; then
${pkgs.gnused}/bin/sed -i "s/^host_whitelist =.*/host_whitelist = $HOSTNAME/" "$CONFIG"
else
${pkgs.gnused}/bin/sed -i "/^\[misc\]/a host_whitelist = $HOSTNAME" "$CONFIG"
fi
2026-05-04 02:27:50 -07:00
'';
in
2026-05-04 01:40:03 -07:00
{
config = lib.mkIf (config.networking.hostName == "FredOS-Mediaserver") {
2026-05-04 02:29:10 -07:00
2026-05-04 01:40:03 -07:00
users.users.sabnzbd = {
isSystemUser = true;
group = "media";
};
2026-05-04 02:29:10 -07:00
2026-05-04 01:40:03 -07:00
systemd.tmpfiles.rules = [
"d /var/lib/sabnzbd 0755 sabnzbd media -"
"Z /var/lib/sabnzbd 0755 sabnzbd media -"
"d /mnt/storage/usenet/downloads 2775 sabnzbd media -"
"Z /mnt/storage/usenet/downloads 2775 sabnzbd media -"
"d /mnt/storage/usenet/incomplete 2775 sabnzbd media -"
"Z /mnt/storage/usenet/incomplete 2775 sabnzbd media -"
];
2026-05-04 02:29:10 -07:00
2026-05-04 01:40:03 -07:00
systemd.services.sabnzbd = {
description = "SABnzbd usenet downloader";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
User = "sabnzbd";
Group = "media";
2026-05-04 02:27:50 -07:00
ExecStartPre = patchConfig;
2026-05-04 01:40:03 -07:00
ExecStart = "${pkgs.sabnzbd}/bin/sabnzbd --config-file /var/lib/sabnzbd/sabnzbd.ini --server 127.0.0.1:8085";
Restart = "on-failure";
UMask = "0002";
NoNewPrivileges = true;
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = false;
ReadWritePaths = [
"/var/lib/sabnzbd"
"/mnt/storage/usenet"
];
WorkingDirectory = "/var/lib/sabnzbd";
};
};
};
}