2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
117 lines
3.3 KiB
Nix
117 lines
3.3 KiB
Nix
{ config, pkgs, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.nzbget;
|
|
pkg = pkgs.nzbget;
|
|
stateDir = "/var/lib/nzbget";
|
|
configFile = "${stateDir}/nzbget.conf";
|
|
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 = [
|
|
(mkRemovedOptionModule [ "services" "misc" "nzbget" "configFile" ] "The configuration of nzbget is now managed by users through the web interface.")
|
|
(mkRemovedOptionModule [ "services" "misc" "nzbget" "dataDir" ] "The data directory for nzbget is now /var/lib/nzbget.")
|
|
(mkRemovedOptionModule [ "services" "misc" "nzbget" "openFirewall" ] "The port used by nzbget is managed through the web interface so you should adjust your firewall rules accordingly.")
|
|
];
|
|
|
|
# interface
|
|
|
|
options = {
|
|
services.nzbget = {
|
|
enable = mkEnableOption "NZBGet";
|
|
|
|
user = mkOption {
|
|
type = types.str;
|
|
default = "nzbget";
|
|
description = lib.mdDoc "User account under which NZBGet runs";
|
|
};
|
|
|
|
group = mkOption {
|
|
type = types.str;
|
|
default = "nzbget";
|
|
description = lib.mdDoc "Group under which NZBGet runs";
|
|
};
|
|
|
|
settings = mkOption {
|
|
type = with types; attrsOf (oneOf [ bool int str ]);
|
|
default = {};
|
|
description = lib.mdDoc ''
|
|
NZBGet configuration, passed via command line using switch -o. Refer to
|
|
<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" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
path = with pkgs; [
|
|
unrar
|
|
p7zip
|
|
];
|
|
|
|
preStart = ''
|
|
if [ ! -f ${configFile} ]; then
|
|
${pkgs.coreutils}/bin/install -m 0700 ${pkg}/share/nzbget/nzbget.conf ${configFile}
|
|
fi
|
|
'';
|
|
|
|
serviceConfig = {
|
|
StateDirectory = "nzbget";
|
|
StateDirectoryMode = "0750";
|
|
User = cfg.user;
|
|
Group = cfg.group;
|
|
UMask = "0002";
|
|
Restart = "on-failure";
|
|
ExecStart = "${pkg}/bin/nzbget --server --configfile ${stateDir}/nzbget.conf ${configOpts}";
|
|
ExecStop = "${pkg}/bin/nzbget --quit";
|
|
};
|
|
};
|
|
|
|
users.users = mkIf (cfg.user == "nzbget") {
|
|
nzbget = {
|
|
home = stateDir;
|
|
group = cfg.group;
|
|
uid = config.ids.uids.nzbget;
|
|
};
|
|
};
|
|
|
|
users.groups = mkIf (cfg.group == "nzbget") {
|
|
nzbget = {
|
|
gid = config.ids.gids.nzbget;
|
|
};
|
|
};
|
|
};
|
|
}
|