1 { config, lib, options, pkgs, ... }:
6 cfg = config.services.subsonic;
7 opt = options.services.subsonic;
11 enable = mkEnableOption "Subsonic daemon";
15 default = "/var/lib/subsonic";
17 The directory where Subsonic will create files.
18 Make sure it is writable.
22 listenAddress = mkOption {
26 The host name or IP address on which to bind Subsonic.
27 Only relevant if you have multiple network interfaces and want
28 to make Subsonic available on only one of them. The default value
29 will bind Subsonic to all available network interfaces.
37 The port on which Subsonic will listen for
38 incoming HTTP traffic. Set to 0 to disable.
42 httpsPort = mkOption {
46 The port on which Subsonic will listen for
47 incoming HTTPS traffic. Set to 0 to disable.
51 contextPath = mkOption {
55 The context path, i.e., the last part of the Subsonic
56 URL. Typically '/' or '/subsonic'. Default '/'
60 maxMemory = mkOption {
64 The memory limit (max Java heap size) in megabytes.
69 defaultMusicFolder = mkOption {
71 default = "/var/music";
73 Configure Subsonic to use this folder for music. This option
74 only has effect the first time Subsonic is started.
78 defaultPodcastFolder = mkOption {
80 default = "/var/music/Podcast";
82 Configure Subsonic to use this folder for Podcasts. This option
83 only has effect the first time Subsonic is started.
87 defaultPlaylistFolder = mkOption {
89 default = "/var/playlists";
91 Configure Subsonic to use this folder for playlists. This option
92 only has effect the first time Subsonic is started.
96 transcoders = mkOption {
97 type = types.listOf types.path;
98 default = [ "${pkgs.ffmpeg.bin}/bin/ffmpeg" ];
99 defaultText = literalExpression ''[ "''${pkgs.ffmpeg.bin}/bin/ffmpeg" ]'';
101 List of paths to transcoder executables that should be accessible
102 from Subsonic. Symlinks will be created to each executable inside
103 ''${config.${opt.home}}/transcoders.
109 config = mkIf cfg.enable {
110 systemd.services.subsonic = {
111 description = "Personal media streamer";
112 after = [ "network.target" ];
113 wantedBy = [ "multi-user.target" ];
115 ${pkgs.jre8}/bin/java -Xmx${toString cfg.maxMemory}m \
116 -Dsubsonic.home=${cfg.home} \
117 -Dsubsonic.host=${cfg.listenAddress} \
118 -Dsubsonic.port=${toString cfg.port} \
119 -Dsubsonic.httpsPort=${toString cfg.httpsPort} \
120 -Dsubsonic.contextPath=${cfg.contextPath} \
121 -Dsubsonic.defaultMusicFolder=${cfg.defaultMusicFolder} \
122 -Dsubsonic.defaultPodcastFolder=${cfg.defaultPodcastFolder} \
123 -Dsubsonic.defaultPlaylistFolder=${cfg.defaultPlaylistFolder} \
124 -Djava.awt.headless=true \
126 -jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar
130 # Formerly this module set cfg.home to /var/subsonic. Try to move
131 # /var/subsonic to cfg.home.
132 oldHome="/var/subsonic"
133 if [ "${cfg.home}" != "$oldHome" ] &&
134 ! [ -e "${cfg.home}" ] &&
136 [ $(${pkgs.coreutils}/bin/stat -c %u "$oldHome") -eq \
137 ${toString config.users.users.subsonic.uid} ]; then
138 logger Moving "$oldHome" to "${cfg.home}"
139 ${pkgs.coreutils}/bin/mv -T "$oldHome" "${cfg.home}"
142 # Install transcoders.
143 ${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \
144 ${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \
145 ${pkgs.bash}/bin/bash -c ' \
146 for exe in "$@"; do \
147 ${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \
148 done' IGNORED_FIRST_ARG ${toString cfg.transcoders}
151 # Needed for Subsonic to find subsonic.war.
152 WorkingDirectory = "${pkgs.subsonic}";
159 users.users.subsonic = {
160 description = "Subsonic daemon user";
164 uid = config.ids.uids.subsonic;
167 users.groups.subsonic.gid = config.ids.gids.subsonic;