···
settingsFormat = pkgs.formats.yaml {};
5
+
defaultUser = "slskd";
options.services.slskd = with lib; with types; {
enable = mkEnableOption "enable slskd";
9
-
rotateLogs = mkEnableOption "enable an unit and timer that will rotate logs in /var/slskd/logs";
10
+
package = mkPackageOptionMD pkgs "slskd" { };
11
-
package = mkPackageOption pkgs "slskd" { };
14
+
default = defaultUser;
15
+
description = "User account under which slskd runs.";
14
-
description = lib.mdDoc "options for nginx";
17
-
domain = "example.com";
18
-
contextPath = "/slskd";
20
-
type = submodule ({name, config, ...}: {
22
-
enable = mkEnableOption "enable nginx as a reverse proxy";
20
+
default = defaultUser;
21
+
description = "Group under which slskd runs.";
24
-
domainName = mkOption {
26
-
description = "Domain you want to use";
28
-
contextPath = mkOption {
31
-
description = lib.mdDoc ''
32
-
The context path, i.e., the last part of the slskd
33
-
URL. Typically '/' or '/slskd'. Default '/'
25
+
type = types.nullOr types.str;
27
+
If non-null, enables an nginx reverse proxy virtual host at this FQDN,
28
+
at the path configurated with `services.slskd.web.url_base`.
30
+
example = "slskd.example.com";
34
+
type = types.submodule (import ../web-servers/nginx/vhost-options.nix { inherit config lib; });
36
+
example = lib.literalExpression ''
43
+
This option customizes the nginx virtual host set up for slskd.
environmentFile = mkOption {
43
-
Path to a file containing secrets.
44
-
It must at least contain the variable `SLSKD_SLSK_PASSWORD`
50
+
Path to the environment file sourced on startup.
51
+
It must at least contain the variables `SLSKD_SLSK_USERNAME` and `SLSKD_SLSK_PASSWORD`.
52
+
Web interface credentials should also be set here in `SLSKD_USERNAME` and `SLSKD_PASSWORD`.
53
+
Other, optional credentials like SOCKS5 with `SLSKD_SLSK_PROXY_USERNAME` and `SLSKD_SLSK_PROXY_PASSWORD`
54
+
should all reside here instead of in the world-readable nix store.
55
+
Variables are documented at https://github.com/slskd/slskd/blob/master/docs/config.md
openFirewall = mkOption {
51
-
Whether to open the firewall for services.slskd.settings.listen_port";
61
+
description = "Whether to open the firewall for the soulseek network listen port (not the web interface port).";
57
-
description = lib.mdDoc ''
58
-
Configuration for slskd, see
59
-
[available options](https://github.com/slskd/slskd/blob/master/docs/config.md)
60
-
`APP_DIR` is set to /var/lib/slskd, where default download & incomplete directories,
61
-
log and databases will be created.
67
+
Application configuration for slskd. See
68
+
[documentation](https://github.com/slskd/slskd/blob/master/docs/config.md).
freeformType = settingsFormat.type;
74
+
remote_file_management = mkEnableOption "modification of share contents through the web ui";
77
+
force_share_scan = mkOption {
79
+
description = "Force a rescan of shares on every startup.";
81
+
no_version_check = mkOption {
85
+
description = "Don't perform a version check on startup.";
90
+
incomplete = mkOption {
92
+
description = "Directory where incomplete downloading files are stored.";
93
+
defaultText = "/var/lib/slskd/incomplete";
96
+
downloads = mkOption {
98
+
description = "Directory where downloaded files are stored.";
99
+
defaultText = "/var/lib/slskd/downloads";
105
+
directories = mkOption {
108
+
Paths to shared directories. See
109
+
[documentation](https://github.com/slskd/slskd/blob/master/docs/config.md#directories)
110
+
for advanced usage.
112
+
example = lib.literalExpression ''[ "/home/John/Music" "!/home/John/Music/Recordings" "[Music Drive]/mnt" ]'';
114
+
filters = mkOption {
116
+
example = lib.literalExpression ''[ "\.ini$" "Thumbs.db$" "\.DS_Store$" ]'';
117
+
description = "Regular expressions of files to exclude from sharing.";
123
+
description = "Chat rooms to join on startup.";
69
-
username = mkOption {
127
+
description = mkOption {
71
-
description = "Username on the Soulseek Network";
129
+
description = "The user description for the Soulseek network.";
130
+
defaultText = "A slskd user. https://github.com/slskd/slskd";
75
-
description = "Port to use for communication on the Soulseek Network";
134
+
description = "The port on which to listen for incoming connections.";
143
+
type = ints.unsigned;
144
+
description = "Limit of the number of concurrent upload slots.";
146
+
speed_limit = mkOption {
147
+
type = ints.unsigned;
148
+
description = "Total upload speed limit.";
153
+
type = ints.unsigned;
154
+
description = "Limit of the number of concurrent download slots.";
156
+
speed_limit = mkOption {
157
+
type = ints.unsigned;
158
+
description = "Total upload download limit";
163
+
filters.search.request = mkOption {
165
+
example = lib.literalExpression ''[ "^.{1,2}$" ]'';
166
+
description = "Incoming search requests which match this filter are ignored.";
84
-
description = "The HTTP listen port";
173
+
description = "The HTTP listen port.";
88
-
default = config.services.slskd.nginx.contextPath;
89
-
defaultText = "config.services.slskd.nginx.contextPath";
90
-
description = lib.mdDoc ''
91
-
The context path, i.e., the last part of the slskd URL
178
+
description = "The base path in the url for web requests.";
180
+
# Users should use a reverse proxy instead for https
181
+
https.disabled = mkOption {
184
+
description = "Disable the built-in HTTPS server";
97
-
directories = mkOption {
99
-
description = lib.mdDoc ''
100
-
Paths to your shared directories. See
101
-
[documentation](https://github.com/slskd/slskd/blob/master/docs/config.md#directories)
191
+
succeeded = mkOption {
192
+
type = ints.unsigned;
193
+
description = "Lifespan of succeeded upload tasks.";
194
+
defaultText = "(indefinite)";
196
+
errored = mkOption {
197
+
type = ints.unsigned;
198
+
description = "Lifespan of errored upload tasks.";
199
+
defaultText = "(indefinite)";
201
+
cancelled = mkOption {
202
+
type = ints.unsigned;
203
+
description = "Lifespan of cancelled upload tasks.";
204
+
defaultText = "(indefinite)";
208
+
succeeded = mkOption {
209
+
type = ints.unsigned;
210
+
description = "Lifespan of succeeded download tasks.";
211
+
defaultText = "(indefinite)";
213
+
errored = mkOption {
214
+
type = ints.unsigned;
215
+
description = "Lifespan of errored download tasks.";
216
+
defaultText = "(indefinite)";
218
+
cancelled = mkOption {
219
+
type = ints.unsigned;
220
+
description = "Lifespan of cancelled download tasks.";
221
+
defaultText = "(indefinite)";
226
+
complete = mkOption {
227
+
type = ints.unsigned;
228
+
description = "Lifespan of completely downloaded files in minutes.";
230
+
defaultText = "(indefinite)";
232
+
incomplete = mkOption {
233
+
type = ints.unsigned;
234
+
description = "Lifespan of incomplete downloading files in minutes.";
235
+
defaultText = "(indefinite)";
108
-
incomplete = mkOption {
109
-
type = nullOr path;
110
-
description = "Directory where downloading files are stored";
111
-
defaultText = "<APP_DIR>/incomplete";
114
-
downloads = mkOption {
115
-
type = nullOr path;
116
-
description = "Directory where downloaded files are stored";
117
-
defaultText = "<APP_DIR>/downloads";
241
+
# Disable by default, journald already retains as needed
244
+
description = "Whether to log to the application directory.";
···
cfg = config.services.slskd;
129
-
confWithoutNullValues = (lib.filterAttrs (key: value: value != null) cfg.settings);
257
+
confWithoutNullValues = (lib.filterAttrsRecursive (key: value: (builtins.tryEval value).success && value != null) cfg.settings);
configurationYaml = settingsFormat.generate "slskd.yml" confWithoutNullValues;
263
+
# Force off, configuration file is in nix store and is immutable
264
+
services.slskd.settings.remote_configuration = lib.mkForce false;
266
+
users.users = lib.optionalAttrs (cfg.user == defaultUser) {
267
+
"${defaultUser}" = {
143
-
# Reverse proxy configuration
144
-
services.nginx.enable = true;
145
-
services.nginx.virtualHosts."${cfg.nginx.domainName}" = {
149
-
"${cfg.nginx.contextPath}" = {
150
-
proxyPass = "http://localhost:${toString cfg.settings.web.port}";
151
-
proxyWebsockets = true;
273
+
users.groups = lib.optionalAttrs (cfg.group == defaultUser) {
274
+
"${defaultUser}" = {};
156
-
# Hide state & logs
157
-
systemd.tmpfiles.rules = [
158
-
"d /var/lib/slskd/data 0750 slskd slskd - -"
159
-
"d /var/lib/slskd/logs 0750 slskd slskd - -"
systemd.services.slskd = {
description = "A modern client-server application for the Soulseek file sharing network";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
170
-
StateDirectory = "slskd";
286
+
StateDirectory = "slskd"; # Creates /var/lib/slskd and manages permissions
ExecStart = "${cfg.package}/bin/slskd --app-dir /var/lib/slskd --config ${configurationYaml}";
ReadOnlyPaths = map (d: builtins.elemAt (builtins.split "[^/]*(/.+)" d) 1) cfg.settings.shares.directories;
291
+
(lib.optional (cfg.settings.directories.incomplete != null) cfg.settings.directories.incomplete) ++
292
+
(lib.optional (cfg.settings.directories.downloads != null) cfg.settings.directories.downloads);
···
networking.firewall.allowedTCPPorts = lib.optional cfg.openFirewall cfg.settings.soulseek.listen_port;
197
-
systemd.services.slskd-rotatelogs = lib.mkIf cfg.rotateLogs {
198
-
description = "Rotate slskd logs";
203
-
"${pkgs.findutils}/bin/find /var/lib/slskd/logs/ -type f -mtime +10 -delete"
204
-
"${pkgs.findutils}/bin/find /var/lib/slskd/logs/ -type f -mtime +1 -exec ${pkgs.gzip}/bin/gzip -q {} ';'"
316
+
services.nginx = lib.mkIf (cfg.domain != null) {
317
+
enable = lib.mkDefault true;
318
+
virtualHosts."${cfg.domain}" = lib.mkMerge [
321
+
locations."${cfg.settings.web.url_base}" = {
322
+
proxyPass = "http://127.0.0.1:${toString cfg.settings.web.port}";
323
+
proxyWebsockets = true;
331
+
maintainers = with lib.maintainers; [ ppom melvyn2 ];