Merge pull request #132722 from aanderse/nixos/nzbget

nixos/nzbget: add settings option
This commit is contained in:
Aaron Andersen 2021-08-29 12:25:37 -04:00 committed by GitHub
commit 515ad99467
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 20 deletions

View file

@ -7,24 +7,12 @@ let
pkg = pkgs.nzbget;
stateDir = "/var/lib/nzbget";
configFile = "${stateDir}/nzbget.conf";
configOpts = concatStringsSep " " (mapAttrsToList (name: value: "-o ${name}=${value}") nixosOpts);
nixosOpts = {
# allows nzbget to run as a "simple" service
OutputMode = "loggable";
# use journald for logging
WriteLog = "none";
ErrorTarget = "screen";
WarningTarget = "screen";
InfoTarget = "screen";
DetailTarget = "screen";
# required paths
ConfigTemplate = "${pkg}/share/nzbget/nzbget.conf";
WebDir = "${pkg}/share/nzbget/webui";
# nixos handles package updates
UpdateCheck = "none";
};
configOpts = concatStringsSep " " (mapAttrsToList (name: value: "-o ${name}=${escapeShellArg (toStr value)}") cfg.settings);
toStr = v:
if v == true then "yes"
else if v == false then "no"
else if isInt v then toString v
else v;
in
{
imports = [
@ -50,12 +38,41 @@ in
default = "nzbget";
description = "Group under which NZBGet runs";
};
settings = mkOption {
type = with types; attrsOf (oneOf [ bool int str ]);
default = {};
description = ''
NZBGet configuration, passed via command line using switch -o. Refer to
<link xlink:href="https://github.com/nzbget/nzbget/blob/master/nzbget.conf"/>
for details on supported values.
'';
example = {
MainDir = "/data";
};
};
};
};
# implementation
config = mkIf cfg.enable {
services.nzbget.settings = {
# allows nzbget to run as a "simple" service
OutputMode = "loggable";
# use journald for logging
WriteLog = "none";
ErrorTarget = "screen";
WarningTarget = "screen";
InfoTarget = "screen";
DetailTarget = "screen";
# required paths
ConfigTemplate = "${pkg}/share/nzbget/nzbget.conf";
WebDir = "${pkg}/share/nzbget/webui";
# nixos handles package updates
UpdateCheck = "none";
};
systemd.services.nzbget = {
description = "NZBGet Daemon";
after = [ "network.target" ];
@ -64,6 +81,7 @@ in
unrar
p7zip
];
preStart = ''
if [ ! -f ${configFile} ]; then
${pkgs.coreutils}/bin/install -m 0700 ${pkg}/share/nzbget/nzbget.conf ${configFile}

View file

@ -8,13 +8,21 @@ import ./make-test-python.nix ({ pkgs, ...} : {
server = { ... }: {
services.nzbget.enable = true;
# provide some test settings
services.nzbget.settings = {
"MainDir" = "/var/lib/nzbget";
"DirectRename" = true;
"DiskSpace" = 0;
"Server1.Name" = "this is a test";
};
# hack, don't add (unfree) unrar to nzbget's path,
# so we can run this test in CI
systemd.services.nzbget.path = pkgs.lib.mkForce [ pkgs.p7zip ];
};
};
testScript = ''
testScript = { nodes, ... }: ''
start_all()
server.wait_for_unit("nzbget.service")
@ -26,5 +34,13 @@ import ./make-test-python.nix ({ pkgs, ...} : {
server.succeed(
"${pkgs.nzbget}/bin/nzbget -n -o Control_iP=127.0.0.1 -o Control_port=6789 -o Control_password=tegbzn6789 -V"
)
config = server.succeed("${nodes.server.config.systemd.services.nzbget.serviceConfig.ExecStart} --printconfig")
# confirm the test settings are applied
assert 'MainDir = "/var/lib/nzbget"' in config
assert 'DirectRename = "yes"' in config
assert 'DiskSpace = "0"' in config
assert 'Server1.Name = "this is a test"' in config
'';
})

View file

@ -1,5 +1,5 @@
{ lib, stdenv, fetchurl, pkg-config, libxml2, ncurses, libsigcxx, libpar2
, gnutls, libgcrypt, zlib, openssl }:
, gnutls, libgcrypt, zlib, openssl, nixosTests }:
stdenv.mkDerivation rec {
pname = "nzbget";
@ -17,6 +17,8 @@ stdenv.mkDerivation rec {
enableParallelBuilding = true;
passthru.tests = { inherit (nixosTests) nzbget; };
meta = with lib; {
homepage = "https://nzbget.net";
license = licenses.gpl2Plus;