1 { config, lib, pkgs, utils, ... }:
3 cfg = config.services.pyload;
5 stateDir = "/var/lib/pyload";
8 meta.maintainers = with lib.maintainers; [ ambroisie ];
12 enable = mkEnableOption "pyLoad download manager";
14 package = mkPackageOption pkgs "pyLoad" { default = [ "pyload-ng" ]; };
16 listenAddress = mkOption {
18 default = "localhost";
20 description = "Address to listen on for the web UI.";
27 description = "Port to listen on for the web UI.";
30 downloadDirectory = mkOption {
32 default = "${stateDir}/downloads";
33 example = "/mnt/downloads";
34 description = "Directory to store downloads.";
40 description = "User under which pyLoad runs, and which owns the download directory.";
46 description = "Group under which pyLoad runs, and which owns the download directory.";
49 credentialsFile = mkOption {
50 type = with types; nullOr path;
52 example = "/run/secrets/pyload-credentials.env";
54 File containing {env}`PYLOAD_DEFAULT_USERNAME` and
55 {env}`PYLOAD_DEFAULT_PASSWORD` in the format of an `EnvironmentFile=`,
56 as described by {manpage}`systemd.exec(5)`.
58 If not given, they default to the username/password combo of
65 config = lib.mkIf cfg.enable {
66 systemd.tmpfiles.settings.pyload = {
67 ${cfg.downloadDirectory}.d = { inherit (cfg) user group; };
70 systemd.services.pyload = {
71 description = "pyLoad download manager";
72 wantedBy = [ "multi-user.target" ];
73 after = [ "network.target" ];
75 # NOTE: unlike what the documentation says, it looks like `HOME` is not
76 # defined with this service definition...
77 # Since pyload tries to do the equivalent of `cd ~`, it needs to be able
78 # to resolve $HOME, which fails when `RootDirectory` is set.
79 # FIXME: check if `SetLoginEnvironment` fixes this issue in version 255
82 PYLOAD__WEBUI__HOST = cfg.listenAddress;
83 PYLOAD__WEBUI__PORT = builtins.toString cfg.port;
87 ExecStart = utils.escapeSystemdExecArgs [
88 (lib.getExe cfg.package)
98 EnvironmentFile = lib.optional (cfg.credentialsFile != null) cfg.credentialsFile;
100 StateDirectory = "pyload";
101 WorkingDirectory = stateDir;
102 RuntimeDirectory = "pyload";
103 RuntimeDirectoryMode = "0700";
104 RootDirectory = "/run/pyload";
105 BindReadOnlyPaths = [
106 builtins.storeDir # Needed to run the python interpreter
109 cfg.downloadDirectory
113 LockPersonality = true;
114 NoNewPrivileges = true;
115 PrivateDevices = true;
116 PrivateMounts = true;
121 ProtectControlGroups = true;
123 ProtectHostname = true;
124 ProtectKernelLogs = true;
125 ProtectKernelModules = true;
126 ProtectKernelTunables = true;
127 ProtectProc = "invisible";
128 ProtectSystem = "strict";
130 RestrictAddressFamilies = "AF_INET AF_INET6 AF_UNIX";
131 RestrictNamespaces = true;
132 RestrictRealtime = true;
133 RestrictSUIDSGID = true;
134 SystemCallArchitectures = "native";
135 SystemCallFilter = [ "@system-service" "~@resources" "~@privileged" ];
137 CapabilityBoundingSet = [
144 "~CAP_LINUX_IMMUTABLE"
153 "~CAP_SYS_TTY_CONFIG"
158 users.users.pyload = lib.mkIf (cfg.user == "pyload") {
164 users.groups.pyload = lib.mkIf (cfg.group == "pyload") { };