Skip to content

Commit

Permalink
nzbget service: fix preStart script and add more options to module
Browse files Browse the repository at this point in the history
  • Loading branch information
elseym committed Jan 14, 2019
1 parent bbf5f02 commit 44e1aab
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions nixos/modules/services/misc/nzbget.nix
Expand Up @@ -16,6 +16,20 @@ in {
description = "The NZBGet package to use";
};

dataDir = mkOption {
type = types.str;
default = "/var/lib/nzbget";
description = "The directory where NZBGet stores its configuration files.";
};

openFirewall = mkOption {
type = types.bool;
default = false;
description = ''
Open ports in the firewall for the NZBGet web interface
'';
};

user = mkOption {
type = types.str;
default = "nzbget";
Expand All @@ -40,7 +54,8 @@ in {
p7zip
];
preStart = ''
datadir=/var/lib/nzbget
datadir=${cfg.dataDir}
configfile=${cfg.dataDir}/nzbget.conf
cfgtemplate=${cfg.package}/share/nzbget/nzbget.conf
test -d $datadir || {
echo "Creating nzbget data directory in $datadir"
Expand All @@ -60,7 +75,7 @@ in {
'';

script = ''
configfile=/var/lib/nzbget/nzbget.conf
configfile=${cfg.dataDir}/nzbget.conf
args="--daemon --configfile $configfile"
# The script in preStart (above) copies nzbget's config template to datadir on first run, containing paths that point to the nzbget derivation installed at the time.
# These paths break when nzbget is upgraded & the original derivation is garbage collected. If such broken paths are found in the config file, override them to point to
Expand All @@ -86,6 +101,10 @@ in {
};
};

networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ 8989 ];
};

users.users = mkIf (cfg.user == "nzbget") {
nzbget = {
group = cfg.group;
Expand Down

0 comments on commit 44e1aab

Please sign in to comment.