sabnzbd: ensure config file exists initially (#504535)

This commit is contained in:
Bjørn Forsman
2026-04-02 13:16:51 +00:00
committed by GitHub
3 changed files with 69 additions and 19 deletions
+2 -2
View File
@@ -84,7 +84,7 @@ in
tor = 35;
cups = 36;
foldingathome = 37;
#sabnzbd = 38; # dropped in 25.11
#sabnzbd = 38; # dropped in 26.05
#kdm = 39; # dropped in 17.03
#ghostone = 40; # dropped in 18.03
git = 41;
@@ -570,7 +570,7 @@ in
lambdabot = 191;
asterisk = 192;
plex = 193;
#sabnzbd = 194; # dropped in 25.11
#sabnzbd = 194; # dropped in 26.05
#grafana = 196; #unused
#skydns = 197; #unused
# ripple-rest = 198; # unused, removed 2017-08-12
@@ -33,7 +33,7 @@ let
"__version__" = 19;
"__encoding__" = "utf-8";
};
allSettings = cfg.settings // mandatoryGlobalSettings;
allSettings = mandatoryGlobalSettings // cfg.settings;
# sabnzbd uses configobj type inis, which support
# nested sections specified by increasing numbers
@@ -514,10 +514,7 @@ in
systemd.services.sabnzbd =
let
files =
if cfg.configFile != null then
[ sabnzbdIniPath ]
else
(lib.optional cfg.allowConfigWrite sabnzbdIniPath) ++ [ publicSettingsIni ] ++ cfg.secretFiles;
(lib.optional cfg.allowConfigWrite sabnzbdIniPath) ++ [ publicSettingsIni ] ++ cfg.secretFiles;
iniPathQuoted = lib.escapeShellArg sabnzbdIniPath;
in
{
@@ -532,11 +529,18 @@ in
StateDirectory = cfg.stateDir;
ExecStart = "${lib.getExe cfg.package} -d -f ${iniPathQuoted}";
};
}
// lib.optionalAttrs (cfg.configFile == null) {
preStart = ''
set -euo pipefail
${lib.toShellVar "files" files}
# We overwrite this immediately, but the merge script requires that
# all files exist
# See also: nixpkgs #504224
(touch ${iniPathQuoted} 2>/dev/null || true)
tmpfile=$(mktemp)
${lib.getExe (pkgs.python3.withPackages (py: [ py.configobj ]))} \
+58 -12
View File
@@ -1,12 +1,7 @@
{ lib, ... }:
{
name = "sabnzbd";
meta.maintainers = with lib.maintainers; [ jojosch ];
node.pkgsReadOnly = false;
nodes.machine =
{ pkgs, lib, ... }:
let
common-config =
{ pkgs, ... }:
{
services.sabnzbd = {
enable = true;
@@ -62,14 +57,65 @@
# unrar is unfree
nixpkgs.config.allowUnfreePackages = [ "unrar" ];
};
in
{
name = "sabnzbd";
meta.maintainers = with lib.maintainers; [ jojosch ];
node.pkgsReadOnly = false;
nodes.machine =
{ ... }:
{
imports = [ common-config ];
};
nodes.with_writeable_config =
{ ... }:
{
imports = [ common-config ];
config.services.sabnzbd.allowConfigWrite = true;
};
nodes.with_raw_config_file =
{ pkgs, ... }:
{
imports = [ common-config ];
config = {
services.sabnzbd = {
configFile = builtins.toFile "config.ini" ''
[misc]
inet_exposure = 2
html_login = 0
api_key = abcdef
log_dir = /var/lib/sabnzbd
admin_dir = /var/lib/sabnzbd
'';
};
environment.systemPackages = [
pkgs.jq
(pkgs.writeScriptBin "do_test_2" ''
set -euxo pipefail
misc_url="http://127.0.0.1:8080/api?mode=get_config&section=misc&output=json&apikey=abcdef"
[[ $(curl $misc_url | jq .config.misc.inet_exposure) == 2 ]]
[[ $(curl $misc_url | jq .config.misc.html_login) == "false" ]]
'')
];
};
};
testScript = ''
def wait_for_up(m):
m.wait_for_unit("sabnzbd.service")
m.wait_until_succeeds("curl --fail -L http://localhost:8080")
machine.wait_for_unit("sabnzbd.service")
machine.wait_until_succeeds(
"curl --fail -L http://localhost:8080/"
)
wait_for_up(machine)
wait_for_up(with_writeable_config)
wait_for_up(with_raw_config_file)
machine.succeed("do_test")
with_writeable_config.succeed("do_test")
with_raw_config_file.succeed("do_test_2")
'';
}