···
16
+
cfg = config.services.lavalink;
18
+
format = pkgs.formats.yaml { };
22
+
options.services.lavalink = {
23
+
enable = mkEnableOption "Lavalink";
25
+
package = lib.mkPackageOption pkgs "lavalink" { };
27
+
password = mkOption {
28
+
type = types.nullOr types.str;
30
+
example = "s3cRe!p4SsW0rD";
32
+
The password for Lavalink's authentication in plain text.
41
+
The port that Lavalink will use.
45
+
address = mkOption {
47
+
default = "0.0.0.0";
48
+
example = "127.0.0.1";
50
+
The network address to bind to.
54
+
openFirewall = mkOption {
59
+
Whether to expose the port to the network.
65
+
default = "lavalink";
68
+
The user of the service.
74
+
default = "lavalink";
77
+
The group of the service.
83
+
default = "/var/lib/lavalink";
84
+
example = "/home/lavalink";
86
+
The home directory for lavalink.
90
+
enableHttp2 = mkEnableOption "HTTP/2 support";
92
+
jvmArgs = mkOption {
95
+
example = "-Djava.io.tmpdir=/var/lib/lavalink/tmp -Xmx6G";
97
+
Set custom JVM arguments.
101
+
environmentFile = mkOption {
102
+
type = types.nullOr types.str;
104
+
example = "/run/secrets/lavalink/passwordEnvFile";
106
+
Add custom environment variables from a file.
107
+
See <https://lavalink.dev/configuration/index.html#example-environment-variables> for the full documentation.
111
+
plugins = mkOption {
112
+
type = types.listOf (
115
+
dependency = mkOption {
117
+
example = "dev.lavalink.youtube:youtube-plugin:1.8.0";
119
+
The coordinates of the plugin.
123
+
repository = mkOption {
125
+
example = "https://maven.example.com/releases";
126
+
default = "https://maven.lavalink.dev/releases";
128
+
The plugin repository. Defaults to the lavalink releases repository.
130
+
To use the snapshots repository, use <https://maven.lavalink.dev/snapshots> instead
136
+
example = lib.fakeHash;
138
+
The hash of the plugin.
142
+
configName = mkOption {
143
+
type = types.nullOr types.str;
144
+
example = "youtube";
147
+
The name of the plugin to use as the key for the plugin configuration.
151
+
extraConfig = mkOption {
152
+
type = types.submodule { freeformType = format.type; };
155
+
The configuration for the plugin.
157
+
The {option}`services.lavalink.plugins.*.configName` option must be set.
165
+
example = lib.literalExpression ''
168
+
dependency = "dev.lavalink.youtube:youtube-plugin:1.8.0";
169
+
repository = "https://maven.lavalink.dev/snapshots";
170
+
hash = lib.fakeHash;
171
+
configName = "youtube";
174
+
allowSearch = true;
175
+
allowDirectVideoIds = true;
176
+
allowDirectPlaylistIds = true;
183
+
A list of plugins for lavalink.
187
+
extraConfig = mkOption {
188
+
type = types.submodule { freeformType = format.type; };
191
+
Configuration to write to {file}`application.yml`.
192
+
See <https://lavalink.dev/configuration/#example-applicationyml> for the full documentation.
194
+
Individual configuration parameters can be overwritten using environment variables.
195
+
See <https://lavalink.dev/configuration/#example-environment-variables> for more information.
200
+
example = lib.literalExpression ''
202
+
lavalink.server = {
203
+
sources.twitch = true;
205
+
filters.volume = true;
208
+
logging.file.path = "./logs/";
216
+
pluginSymlinks = lib.concatStringsSep "\n" (
220
+
pluginParts = lib.match ''^(.*?:(.*?):)([0-9]+\.[0-9]+\.[0-9]+)$'' pluginCfg.dependency;
222
+
pluginWebPath = lib.replaceStrings [ "." ":" ] [ "/" "/" ] (lib.elemAt pluginParts 0);
224
+
pluginFileName = lib.elemAt pluginParts 1;
225
+
pluginVersion = lib.elemAt pluginParts 2;
227
+
pluginFile = "${pluginFileName}-${pluginVersion}.jar";
228
+
pluginUrl = "${pluginCfg.repository}/${pluginWebPath}${pluginVersion}/${pluginFile}";
230
+
plugin = pkgs.fetchurl {
232
+
inherit (pluginCfg) hash;
235
+
"ln -sf ${plugin} ${cfg.home}/plugins/${pluginFile}"
239
+
pluginExtraConfigs = builtins.listToAttrs (
241
+
pluginConfig: lib.attrsets.nameValuePair pluginConfig.configName pluginConfig.extraConfig
242
+
) (lib.lists.filter (pluginCfg: pluginCfg.configName != null) cfg.plugins)
245
+
config = lib.attrsets.recursiveUpdate cfg.extraConfig {
247
+
inherit (cfg) port address;
248
+
http2.enabled = cfg.enableHttp2;
251
+
plugins = pluginExtraConfigs;
252
+
lavalink.plugins = (
255
+
builtins.removeAttrs pluginConfig [
264
+
configWithPassword = lib.attrsets.recursiveUpdate config (
265
+
lib.attrsets.optionalAttrs (cfg.password != null) { lavalink.server.password = cfg.password; }
268
+
configFile = format.generate "application.yml" configWithPassword;
275
+
pluginCfg: pluginCfg.extraConfig != { } && pluginCfg.configName == null
277
+
message = "Plugins with extra configuration need to have the `configName` attribute defined";
281
+
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
283
+
users.groups = mkIf (cfg.group == "lavalink") { lavalink = { }; };
284
+
users.users = mkIf (cfg.user == "lavalink") {
286
+
inherit (cfg) home;
287
+
group = "lavalink";
288
+
description = "The user for the Lavalink server";
289
+
isSystemUser = true;
293
+
systemd.tmpfiles.settings."10-lavalink" =
296
+
inherit (cfg) user group;
301
+
"${cfg.home}/plugins".d = mkIf (cfg.plugins != [ ]) dirConfig;
302
+
${cfg.home}.d = dirConfig;
305
+
systemd.services.lavalink = {
306
+
description = "Lavalink Service";
308
+
wantedBy = [ "multi-user.target" ];
317
+
ln -sf ${configFile} ${cfg.home}/application.yml
318
+
export _JAVA_OPTIONS="${cfg.jvmArgs}"
320
+
${lib.getExe cfg.package}
328
+
Restart = "on-failure";
330
+
EnvironmentFile = cfg.environmentFile;
331
+
WorkingDirectory = cfg.home;