1 { config, pkgs, lib, ... }:
3 cfg = config.services.nzbget;
5 stateDir = "/var/lib/nzbget";
6 configFile = "${stateDir}/nzbget.conf";
7 configOpts = lib.concatStringsSep " " (lib.mapAttrsToList (name: value: "-o ${name}=${lib.escapeShellArg (toStr value)}") cfg.settings);
9 if v == true then "yes"
10 else if v == false then "no"
11 else if lib.isInt v then toString v
16 (lib.mkRemovedOptionModule [ "services" "misc" "nzbget" "configFile" ] "The configuration of nzbget is now managed by users through the web interface.")
17 (lib.mkRemovedOptionModule [ "services" "misc" "nzbget" "dataDir" ] "The data directory for nzbget is now /var/lib/nzbget.")
18 (lib.mkRemovedOptionModule [ "services" "misc" "nzbget" "openFirewall" ] "The port used by nzbget is managed through the web interface so you should adjust your firewall rules accordingly.")
25 enable = lib.mkEnableOption "NZBGet, for downloading files from news servers";
30 description = "User account under which NZBGet runs";
33 group = lib.mkOption {
36 description = "Group under which NZBGet runs";
39 settings = lib.mkOption {
40 type = with lib.types; attrsOf (oneOf [ bool int str ]);
43 NZBGet configuration, passed via command line using switch -o. Refer to
44 <https://github.com/nzbget/nzbget/blob/master/nzbget.conf>
45 for details on supported values.
56 config = lib.mkIf cfg.enable {
57 services.nzbget.settings = {
58 # allows nzbget to run as a "simple" service
59 OutputMode = "loggable";
60 # use journald for logging
62 ErrorTarget = "screen";
63 WarningTarget = "screen";
64 InfoTarget = "screen";
65 DetailTarget = "screen";
67 ConfigTemplate = "${pkg}/share/nzbget/nzbget.conf";
68 WebDir = "${pkg}/share/nzbget/webui";
69 # nixos handles package updates
73 systemd.services.nzbget = {
74 description = "NZBGet Daemon";
75 after = [ "network.target" ];
76 wantedBy = [ "multi-user.target" ];
83 if [ ! -f ${configFile} ]; then
84 ${pkgs.coreutils}/bin/install -m 0700 ${pkg}/share/nzbget/nzbget.conf ${configFile}
89 StateDirectory = "nzbget";
90 StateDirectoryMode = "0750";
94 Restart = "on-failure";
95 ExecStart = "${pkg}/bin/nzbget --server --configfile ${stateDir}/nzbget.conf ${configOpts}";
96 ExecStop = "${pkg}/bin/nzbget --quit";
100 users.users = lib.mkIf (cfg.user == "nzbget") {
104 uid = config.ids.uids.nzbget;
108 users.groups = lib.mkIf (cfg.group == "nzbget") {
110 gid = config.ids.gids.nzbget;