86 lines
2.2 KiB
Nix
86 lines
2.2 KiB
Nix
|
{
|
||
|
lib,
|
||
|
nglib,
|
||
|
config,
|
||
|
pkgs,
|
||
|
...
|
||
|
}: let
|
||
|
cfg = config.services.deluge;
|
||
|
cfgInit = config.init.services.deluged;
|
||
|
in {
|
||
|
options.services.deluge = {
|
||
|
enable = lib.mkEnableOption "deluge";
|
||
|
package = lib.mkPackageOption pkgs "deluge-2_x" {};
|
||
|
|
||
|
configDir = lib.mkOption {
|
||
|
type = lib.types.path;
|
||
|
default = "/var/lib/deluge";
|
||
|
|
||
|
description = ''
|
||
|
Directory for Deluge's run-time configuration
|
||
|
'';
|
||
|
};
|
||
|
|
||
|
web = {
|
||
|
enable = lib.mkEnableOption "Deluge web daemon";
|
||
|
|
||
|
port = lib.mkOption {
|
||
|
type = lib.types.port;
|
||
|
default = 8112;
|
||
|
description = ''
|
||
|
Deluge web UI port
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
config = lib.mkIf cfg.enable {
|
||
|
init.services = {
|
||
|
deluged = {
|
||
|
enabled = true;
|
||
|
user = lib.mkDefault "deluge";
|
||
|
group = lib.mkDefault "deluge";
|
||
|
tmpfiles = with nglib.nottmpfiles.dsl; [(d cfg.configDir "-" cfgInit.user cfgInit.group _ _)];
|
||
|
|
||
|
script = pkgs.writeShellScript "deluged-run" ''
|
||
|
# TODO: make init-level option?
|
||
|
umask 0002
|
||
|
${cfg.package}/bin/deluged \
|
||
|
--do-not-daemonize \
|
||
|
--config ${cfg.configDir}
|
||
|
'';
|
||
|
};
|
||
|
|
||
|
deluge-web = {
|
||
|
enabled = cfg.web.enable;
|
||
|
dependencies = ["deluged"];
|
||
|
user = lib.mkDefault "deluge";
|
||
|
group = lib.mkDefault "deluge";
|
||
|
|
||
|
script = pkgs.writeShellScript "deluge-web-run" ''
|
||
|
${cfg.package}/bin/deluge-web \
|
||
|
--do-not-daemonize \
|
||
|
--port ${toString cfg.web.port} \
|
||
|
--config ${cfg.configDir}
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
|
||
|
environment = {
|
||
|
systemPackages = [cfg.package];
|
||
|
variables.PYTHON_EGG_CACHE = "${config.users.users.${cfgInit.user}.home}/.cache";
|
||
|
};
|
||
|
|
||
|
users.users.${cfgInit.user} = lib.mkIf (cfgInit.user == "deluge") (nglib.mkDefaultRec {
|
||
|
description = "deluge";
|
||
|
group = cfgInit.group;
|
||
|
createHome = true;
|
||
|
home = "/home/deluge";
|
||
|
useDefaultShell = true;
|
||
|
uid = config.ids.uids.deluge;
|
||
|
});
|
||
|
|
||
|
users.groups.${cfgInit.group} = lib.mkIf (cfgInit.group == "deluge") (nglib.mkDefaultRec {gid = config.ids.gids.deluge;});
|
||
|
};
|
||
|
}
|