mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-25 21:44:49 +00:00
Merge pull request #30943 from csingley/nzbget
nzbget.service override nzbget.conf broken paths with current derivation
This commit is contained in:
commit
1503409aac
@ -4,9 +4,7 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.nzbget;
|
cfg = config.services.nzbget;
|
||||||
nzbget = pkgs.nzbget;
|
nzbget = pkgs.nzbget; in {
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
options = {
|
||||||
services.nzbget = {
|
services.nzbget = {
|
||||||
enable = mkEnableOption "NZBGet";
|
enable = mkEnableOption "NZBGet";
|
||||||
@ -42,21 +40,41 @@ in
|
|||||||
p7zip
|
p7zip
|
||||||
];
|
];
|
||||||
preStart = ''
|
preStart = ''
|
||||||
test -d /var/lib/nzbget || {
|
datadir=/var/lib/nzbget
|
||||||
echo "Creating nzbget state directoy in /var/lib/"
|
cfgtemplate=${cfg.package}/share/nzbget/nzbget.conf
|
||||||
mkdir -p /var/lib/nzbget
|
test -d $datadir || {
|
||||||
|
echo "Creating nzbget data directory in $datadir"
|
||||||
|
mkdir -p $datadir
|
||||||
}
|
}
|
||||||
test -f /var/lib/nzbget/nzbget.conf || {
|
test -f $configfile || {
|
||||||
echo "nzbget.conf not found. Copying default config to /var/lib/nzbget/nzbget.conf"
|
echo "nzbget.conf not found. Copying default config $cfgtemplate to $configfile"
|
||||||
cp ${cfg.package}/share/nzbget/nzbget.conf /var/lib/nzbget/nzbget.conf
|
cp $cfgtemplate $configfile
|
||||||
echo "Setting file mode of nzbget.conf to 0700 (needs to be written and contains plaintext credentials)"
|
echo "Setting $configfile permissions to 0700 (needs to be written and contains plaintext credentials)"
|
||||||
chmod 0700 /var/lib/nzbget/nzbget.conf
|
chmod 0700 $configfile
|
||||||
echo "Setting temporary \$MAINDIR variable in default config required in order to allow nzbget to complete initial start"
|
echo "Setting temporary \$MAINDIR variable in default config required in order to allow nzbget to complete initial start"
|
||||||
echo "Remember to change this to a proper value once NZBGet startup has been completed"
|
echo "Remember to change this to a proper value once NZBGet startup has been completed"
|
||||||
sed -i -e 's/MainDir=.*/MainDir=\/tmp/g' /var/lib/nzbget/nzbget.conf
|
sed -i -e 's/MainDir=.*/MainDir=\/tmp/g' $configfile
|
||||||
}
|
}
|
||||||
echo "Ensuring proper ownership of /var/lib/nzbget (${cfg.user}:${cfg.group})."
|
echo "Ensuring proper ownership of $datadir (${cfg.user}:${cfg.group})."
|
||||||
chown -R ${cfg.user}:${cfg.group} /var/lib/nzbget
|
chown -R ${cfg.user}:${cfg.group} $datadir
|
||||||
|
'';
|
||||||
|
|
||||||
|
script = ''
|
||||||
|
configfile=/var/lib/nzbget/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
|
||||||
|
# the currently installed nzbget derivation.
|
||||||
|
cfgfallback () {
|
||||||
|
local hit=`grep -Po "(?<=^$1=).*+" "$configfile" | sed 's/[ \t]*$//'` # Strip trailing whitespace
|
||||||
|
( test $hit && test -e $hit ) || {
|
||||||
|
echo "In $configfile, valid $1 not found; falling back to $1=$2"
|
||||||
|
args+=" -o $1=$2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfgfallback ConfigTemplate ${cfg.package}/share/nzbget/nzbget.conf
|
||||||
|
cfgfallback WebDir ${cfg.package}/share/nzbget/webui
|
||||||
|
${cfg.package}/bin/nzbget $args
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
@ -64,7 +82,6 @@ in
|
|||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
Group = cfg.group;
|
Group = cfg.group;
|
||||||
PermissionsStartOnly = "true";
|
PermissionsStartOnly = "true";
|
||||||
ExecStart = "${cfg.package}/bin/nzbget --daemon --configfile /var/lib/nzbget/nzbget.conf";
|
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user