2021-12-05 20:58:27 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2017-08-23 12:09:48 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.airsonic;
|
2021-12-05 20:58:27 +00:00
|
|
|
opt = options.services.airsonic;
|
2017-08-23 12:09:48 +00:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.airsonic = {
|
|
|
|
enable = mkEnableOption "Airsonic, the Free and Open Source media streaming server (fork of Subsonic and Libresonic)";
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "airsonic";
|
|
|
|
description = "User account under which airsonic runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/airsonic";
|
|
|
|
description = ''
|
|
|
|
The directory where Airsonic will create files.
|
|
|
|
Make sure it is writable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-02-01 01:09:06 +00:00
|
|
|
virtualHost = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Name of the nginx virtualhost to use and setup. If null, do not setup any virtualhost.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-08-23 12:09:48 +00:00
|
|
|
listenAddress = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2017-08-23 12:09:48 +00:00
|
|
|
default = "127.0.0.1";
|
|
|
|
description = ''
|
|
|
|
The host name or IP address on which to bind Airsonic.
|
|
|
|
Only relevant if you have multiple network interfaces and want
|
|
|
|
to make Airsonic available on only one of them. The default value
|
|
|
|
will bind Airsonic to all available network interfaces.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 4040;
|
|
|
|
description = ''
|
|
|
|
The port on which Airsonic will listen for
|
|
|
|
incoming HTTP traffic. Set to 0 to disable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
contextPath = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/";
|
|
|
|
description = ''
|
|
|
|
The context path, i.e., the last part of the Airsonic
|
|
|
|
URL. Typically '/' or '/airsonic'. Default '/'
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
maxMemory = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 100;
|
|
|
|
description = ''
|
|
|
|
The memory limit (max Java heap size) in megabytes.
|
|
|
|
Default: 100
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
transcoders = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [ "${pkgs.ffmpeg.bin}/bin/ffmpeg" ];
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression ''[ "''${pkgs.ffmpeg.bin}/bin/ffmpeg" ]'';
|
2017-08-23 12:09:48 +00:00
|
|
|
description = ''
|
|
|
|
List of paths to transcoder executables that should be accessible
|
|
|
|
from Airsonic. Symlinks will be created to each executable inside
|
2021-12-05 20:58:27 +00:00
|
|
|
''${config.${opt.home}}/transcoders.
|
2017-08-23 12:09:48 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-09-14 00:03:31 +00:00
|
|
|
|
2021-08-28 18:26:03 +00:00
|
|
|
jre = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.jre8;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.jre8";
|
2021-08-28 18:26:03 +00:00
|
|
|
description = ''
|
|
|
|
JRE package to use.
|
|
|
|
|
|
|
|
Airsonic only supports Java 8, airsonic-advanced requires at least
|
|
|
|
Java 11.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
war = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${pkgs.airsonic}/webapps/airsonic.war";
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression ''"''${pkgs.airsonic}/webapps/airsonic.war"'';
|
2021-08-28 18:26:03 +00:00
|
|
|
description = "Airsonic war file to use.";
|
|
|
|
};
|
|
|
|
|
2018-09-14 00:03:31 +00:00
|
|
|
jvmOptions = mkOption {
|
|
|
|
description = ''
|
|
|
|
Extra command line options for the JVM running AirSonic.
|
|
|
|
Useful for sending jukebox output to non-default alsa
|
|
|
|
devices.
|
|
|
|
'';
|
|
|
|
default = [
|
|
|
|
];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
example = [
|
|
|
|
"-Djavax.sound.sampled.Clip='#CODEC [plughw:1,0]'"
|
|
|
|
"-Djavax.sound.sampled.Port='#Port CODEC [hw:1]'"
|
|
|
|
"-Djavax.sound.sampled.SourceDataLine='#CODEC [plughw:1,0]'"
|
|
|
|
"-Djavax.sound.sampled.TargetDataLine='#CODEC [plughw:1,0]'"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2017-08-23 12:09:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.airsonic = {
|
|
|
|
description = "Airsonic Media Server";
|
2019-09-01 01:07:23 +00:00
|
|
|
after = [ "network.target" ];
|
2017-08-23 12:09:48 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
# Install transcoders.
|
2017-08-25 22:05:51 +00:00
|
|
|
rm -rf ${cfg.home}/transcode
|
|
|
|
mkdir -p ${cfg.home}/transcode
|
2017-08-23 12:09:48 +00:00
|
|
|
for exe in ${toString cfg.transcoders}; do
|
2017-08-25 22:05:51 +00:00
|
|
|
ln -sf "$exe" ${cfg.home}/transcode
|
2017-08-23 12:09:48 +00:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
2017-08-25 22:04:56 +00:00
|
|
|
ExecStart = ''
|
2021-08-28 18:26:03 +00:00
|
|
|
${cfg.jre}/bin/java -Xmx${toString cfg.maxMemory}m \
|
2017-08-25 22:04:56 +00:00
|
|
|
-Dairsonic.home=${cfg.home} \
|
|
|
|
-Dserver.address=${cfg.listenAddress} \
|
|
|
|
-Dserver.port=${toString cfg.port} \
|
|
|
|
-Dairsonic.contextPath=${cfg.contextPath} \
|
|
|
|
-Djava.awt.headless=true \
|
2019-02-01 01:09:06 +00:00
|
|
|
${optionalString (cfg.virtualHost != null)
|
|
|
|
"-Dserver.use-forward-headers=true"} \
|
2018-09-14 00:03:31 +00:00
|
|
|
${toString cfg.jvmOptions} \
|
2017-08-25 22:04:56 +00:00
|
|
|
-verbose:gc \
|
2021-08-28 18:26:03 +00:00
|
|
|
-jar ${cfg.war}
|
2017-08-25 22:04:56 +00:00
|
|
|
'';
|
2017-08-23 12:09:48 +00:00
|
|
|
Restart = "always";
|
|
|
|
User = "airsonic";
|
|
|
|
UMask = "0022";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-02-01 01:09:06 +00:00
|
|
|
services.nginx = mkIf (cfg.virtualHost != null) {
|
|
|
|
enable = true;
|
2020-01-14 14:22:22 +00:00
|
|
|
recommendedProxySettings = true;
|
2019-08-13 21:52:01 +00:00
|
|
|
virtualHosts.${cfg.virtualHost} = {
|
|
|
|
locations.${cfg.contextPath}.proxyPass = "http://${cfg.listenAddress}:${toString cfg.port}";
|
2019-02-01 01:09:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users.airsonic = {
|
2017-08-23 12:09:48 +00:00
|
|
|
description = "Airsonic service user";
|
2021-08-08 12:00:00 +00:00
|
|
|
group = "airsonic";
|
2017-08-23 12:09:48 +00:00
|
|
|
name = cfg.user;
|
|
|
|
home = cfg.home;
|
|
|
|
createHome = true;
|
2019-10-12 20:25:28 +00:00
|
|
|
isSystemUser = true;
|
2017-08-23 12:09:48 +00:00
|
|
|
};
|
2021-08-08 12:00:00 +00:00
|
|
|
users.groups.airsonic = {};
|
2017-08-23 12:09:48 +00:00
|
|
|
};
|
|
|
|
}
|