Update services/sabnzbd.nix
This commit is contained in:
parent
c7f7e75a38
commit
e77ca8fceb
1 changed files with 27 additions and 4 deletions
|
|
@ -1,12 +1,36 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ 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") {
|
config = lib.mkIf (config.networking.hostName == "FredOS-Mediaserver") {
|
||||||
|
|
||||||
users.users.sabnzbd = {
|
users.users.sabnzbd = {
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
group = "media";
|
group = "media";
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
"d /var/lib/sabnzbd 0755 sabnzbd media -"
|
"d /var/lib/sabnzbd 0755 sabnzbd media -"
|
||||||
"Z /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 -"
|
"d /mnt/storage/usenet/incomplete 2775 sabnzbd media -"
|
||||||
"Z /mnt/storage/usenet/incomplete 2775 sabnzbd media -"
|
"Z /mnt/storage/usenet/incomplete 2775 sabnzbd media -"
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services.sabnzbd = {
|
systemd.services.sabnzbd = {
|
||||||
description = "SABnzbd usenet downloader";
|
description = "SABnzbd usenet downloader";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
|
|
@ -24,7 +47,7 @@
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
User = "sabnzbd";
|
User = "sabnzbd";
|
||||||
Group = "media";
|
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";
|
ExecStart = "${pkgs.sabnzbd}/bin/sabnzbd --config-file /var/lib/sabnzbd/sabnzbd.ini --server 127.0.0.1:8085";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
UMask = "0002";
|
UMask = "0002";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue