2021-12-05 20:58:27 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2015-07-04 01:42:16 +01:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2021-12-05 20:58:27 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.subsonic;
|
|
|
|
opt = options.services.subsonic;
|
|
|
|
in {
|
2015-07-04 01:42:16 +01:00
|
|
|
options = {
|
|
|
|
services.subsonic = {
|
|
|
|
enable = mkEnableOption "Subsonic daemon";
|
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
type = types.path;
|
2016-05-14 22:13:30 +01:00
|
|
|
default = "/var/lib/subsonic";
|
2015-07-04 01:42:16 +01:00
|
|
|
description = ''
|
|
|
|
The directory where Subsonic will create files.
|
|
|
|
Make sure it is writable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-12-23 23:13:15 +00:00
|
|
|
listenAddress = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.str;
|
2015-07-04 01:42:16 +01:00
|
|
|
default = "0.0.0.0";
|
|
|
|
description = ''
|
|
|
|
The host name or IP address on which to bind Subsonic.
|
|
|
|
Only relevant if you have multiple network interfaces and want
|
|
|
|
to make Subsonic available on only one of them. The default value
|
|
|
|
will bind Subsonic to all available network interfaces.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-06-18 16:30:56 +01:00
|
|
|
type = types.port;
|
2015-07-04 01:42:16 +01:00
|
|
|
default = 4040;
|
|
|
|
description = ''
|
|
|
|
The port on which Subsonic will listen for
|
|
|
|
incoming HTTP traffic. Set to 0 to disable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
httpsPort = mkOption {
|
2021-06-18 16:30:56 +01:00
|
|
|
type = types.port;
|
2015-07-04 01:42:16 +01:00
|
|
|
default = 0;
|
|
|
|
description = ''
|
|
|
|
The port on which Subsonic will listen for
|
|
|
|
incoming HTTPS traffic. Set to 0 to disable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
contextPath = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/";
|
|
|
|
description = ''
|
|
|
|
The context path, i.e., the last part of the Subsonic
|
|
|
|
URL. Typically '/' or '/subsonic'. Default '/'
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
maxMemory = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 100;
|
|
|
|
description = ''
|
|
|
|
The memory limit (max Java heap size) in megabytes.
|
|
|
|
Default: 100
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultMusicFolder = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/music";
|
|
|
|
description = ''
|
|
|
|
Configure Subsonic to use this folder for music. This option
|
|
|
|
only has effect the first time Subsonic is started.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultPodcastFolder = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/music/Podcast";
|
|
|
|
description = ''
|
|
|
|
Configure Subsonic to use this folder for Podcasts. This option
|
|
|
|
only has effect the first time Subsonic is started.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultPlaylistFolder = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/playlists";
|
|
|
|
description = ''
|
|
|
|
Configure Subsonic to use this folder for playlists. This option
|
|
|
|
only has effect the first time Subsonic is started.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
transcoders = mkOption {
|
|
|
|
type = types.listOf types.path;
|
2016-03-08 08:57:58 +00:00
|
|
|
default = [ "${pkgs.ffmpeg.bin}/bin/ffmpeg" ];
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression ''[ "''${pkgs.ffmpeg.bin}/bin/ffmpeg" ]'';
|
2015-07-04 01:42:16 +01:00
|
|
|
description = ''
|
|
|
|
List of paths to transcoder executables that should be accessible
|
|
|
|
from Subsonic. Symlinks will be created to each executable inside
|
2021-12-05 20:58:27 +00:00
|
|
|
''${config.${opt.home}}/transcoders.
|
2015-07-04 01:42:16 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.subsonic = {
|
|
|
|
description = "Personal media streamer";
|
2019-09-01 02:07:23 +01:00
|
|
|
after = [ "network.target" ];
|
2015-07-04 01:42:16 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-05-16 22:06:36 +01:00
|
|
|
script = ''
|
2021-10-13 11:24:30 +01:00
|
|
|
${pkgs.jre8}/bin/java -Xmx${toString cfg.maxMemory}m \
|
2016-05-16 22:06:36 +01:00
|
|
|
-Dsubsonic.home=${cfg.home} \
|
|
|
|
-Dsubsonic.host=${cfg.listenAddress} \
|
|
|
|
-Dsubsonic.port=${toString cfg.port} \
|
|
|
|
-Dsubsonic.httpsPort=${toString cfg.httpsPort} \
|
|
|
|
-Dsubsonic.contextPath=${cfg.contextPath} \
|
|
|
|
-Dsubsonic.defaultMusicFolder=${cfg.defaultMusicFolder} \
|
|
|
|
-Dsubsonic.defaultPodcastFolder=${cfg.defaultPodcastFolder} \
|
|
|
|
-Dsubsonic.defaultPlaylistFolder=${cfg.defaultPlaylistFolder} \
|
|
|
|
-Djava.awt.headless=true \
|
|
|
|
-verbose:gc \
|
|
|
|
-jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar
|
|
|
|
'';
|
|
|
|
|
|
|
|
preStart = ''
|
2016-05-16 22:11:06 +01:00
|
|
|
# Formerly this module set cfg.home to /var/subsonic. Try to move
|
|
|
|
# /var/subsonic to cfg.home.
|
|
|
|
oldHome="/var/subsonic"
|
|
|
|
if [ "${cfg.home}" != "$oldHome" ] &&
|
|
|
|
! [ -e "${cfg.home}" ] &&
|
|
|
|
[ -d "$oldHome" ] &&
|
|
|
|
[ $(${pkgs.coreutils}/bin/stat -c %u "$oldHome") -eq \
|
2018-06-30 00:58:35 +01:00
|
|
|
${toString config.users.users.subsonic.uid} ]; then
|
2016-05-16 22:11:06 +01:00
|
|
|
logger Moving "$oldHome" to "${cfg.home}"
|
|
|
|
${pkgs.coreutils}/bin/mv -T "$oldHome" "${cfg.home}"
|
|
|
|
fi
|
|
|
|
|
2015-07-04 01:42:16 +01:00
|
|
|
# Install transcoders.
|
2016-05-16 22:06:36 +01:00
|
|
|
${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \
|
|
|
|
${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \
|
|
|
|
${pkgs.bash}/bin/bash -c ' \
|
|
|
|
for exe in "$@"; do \
|
|
|
|
${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \
|
|
|
|
done' IGNORED_FIRST_ARG ${toString cfg.transcoders}
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
2015-07-04 01:42:16 +01:00
|
|
|
# Needed for Subsonic to find subsonic.war.
|
|
|
|
WorkingDirectory = "${pkgs.subsonic}";
|
|
|
|
Restart = "always";
|
|
|
|
User = "subsonic";
|
|
|
|
UMask = "0022";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users.subsonic = {
|
2015-07-04 01:42:16 +01:00
|
|
|
description = "Subsonic daemon user";
|
2016-05-14 22:13:30 +01:00
|
|
|
home = cfg.home;
|
2015-07-04 01:42:16 +01:00
|
|
|
createHome = true;
|
|
|
|
group = "subsonic";
|
|
|
|
uid = config.ids.uids.subsonic;
|
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups.subsonic.gid = config.ids.gids.subsonic;
|
2015-07-04 01:42:16 +01:00
|
|
|
};
|
|
|
|
}
|