9 cfg = config.services.pyload;
11 stateDir = "/var/lib/pyload";
14 meta.maintainers = with lib.maintainers; [ ambroisie ];
18 enable = mkEnableOption "pyLoad download manager";
20 package = mkPackageOption pkgs "pyLoad" { default = [ "pyload-ng" ]; };
22 listenAddress = mkOption {
24 default = "localhost";
26 description = "Address to listen on for the web UI.";
33 description = "Port to listen on for the web UI.";
36 downloadDirectory = mkOption {
38 default = "${stateDir}/downloads";
39 example = "/mnt/downloads";
40 description = "Directory to store downloads.";
46 description = "User under which pyLoad runs, and which owns the download directory.";
52 description = "Group under which pyLoad runs, and which owns the download directory.";
55 credentialsFile = mkOption {
56 type = with types; nullOr path;
58 example = "/run/secrets/pyload-credentials.env";
60 File containing {env}`PYLOAD_DEFAULT_USERNAME` and
61 {env}`PYLOAD_DEFAULT_PASSWORD` in the format of an `EnvironmentFile=`,
62 as described by {manpage}`systemd.exec(5)`.
64 If not given, they default to the username/password combo of
71 config = lib.mkIf cfg.enable {
72 systemd.tmpfiles.settings.pyload = {
73 ${cfg.downloadDirectory}.d = { inherit (cfg) user group; };
76 systemd.services.pyload = {
77 description = "pyLoad download manager";
78 wantedBy = [ "multi-user.target" ];
79 after = [ "network.target" ];
81 # NOTE: unlike what the documentation says, it looks like `HOME` is not
82 # defined with this service definition...
83 # Since pyload tries to do the equivalent of `cd ~`, it needs to be able
84 # to resolve $HOME, which fails when `RootDirectory` is set.
85 # FIXME: check if `SetLoginEnvironment` fixes this issue in version 255
88 PYLOAD__WEBUI__HOST = cfg.listenAddress;
89 PYLOAD__WEBUI__PORT = builtins.toString cfg.port;
93 ExecStart = utils.escapeSystemdExecArgs [
94 (lib.getExe cfg.package)
104 EnvironmentFile = lib.optional (cfg.credentialsFile != null) cfg.credentialsFile;
106 StateDirectory = "pyload";
107 WorkingDirectory = stateDir;
108 RuntimeDirectory = "pyload";
109 RuntimeDirectoryMode = "0700";
110 RootDirectory = "/run/pyload";
111 BindReadOnlyPaths = [
112 builtins.storeDir # Needed to run the python interpreter
115 cfg.downloadDirectory
119 LockPersonality = true;
120 NoNewPrivileges = true;
121 PrivateDevices = true;
122 PrivateMounts = true;
127 ProtectControlGroups = true;
129 ProtectHostname = true;
130 ProtectKernelLogs = true;
131 ProtectKernelModules = true;
132 ProtectKernelTunables = true;
133 ProtectProc = "invisible";
134 ProtectSystem = "strict";
136 RestrictAddressFamilies = "AF_INET AF_INET6 AF_UNIX";
137 RestrictNamespaces = true;
138 RestrictRealtime = true;
139 RestrictSUIDSGID = true;
140 SystemCallArchitectures = "native";
147 CapabilityBoundingSet = [
154 "~CAP_LINUX_IMMUTABLE"
163 "~CAP_SYS_TTY_CONFIG"
168 users.users.pyload = lib.mkIf (cfg.user == "pyload") {
174 users.groups.pyload = lib.mkIf (cfg.group == "pyload") { };