git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #15471 from telotortium/subsonic
cf5e07cJoachim Fasting
nixos/modules/services/misc/subsonic.nix+39−31
@@ -2,19 +2,14 @@
2
2
3with lib;
3with lib;
4
4
5−let
6− cfg = config.services.subsonic;
5+let cfg = config.services.subsonic; in {
7− homeDir = "/var/subsonic";
8−
9−in
10−{
11 options = {
6 options = {
12 services.subsonic = {
7 services.subsonic = {
13 enable = mkEnableOption "Subsonic daemon";
8 enable = mkEnableOption "Subsonic daemon";
14
9
15 home = mkOption {
10 home = mkOption {
16 type = types.path;
11 type = types.path;
17− default = "${homeDir}";
12+ default = "/var/lib/subsonic";
18 description = ''
13 description = ''
19 The directory where Subsonic will create files.
14 The directory where Subsonic will create files.
20 Make sure it is writable.
15 Make sure it is writable.
@@ -112,30 +107,43 @@ in
112 description = "Personal media streamer";
107 description = "Personal media streamer";
113 after = [ "local-fs.target" "network.target" ];
108 after = [ "local-fs.target" "network.target" ];
114 wantedBy = [ "multi-user.target" ];
109 wantedBy = [ "multi-user.target" ];
115− serviceConfig = {
110+ script = ''
116− ExecStart = ''
117− ${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \
111+ ${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \
118− -Dsubsonic.home=${cfg.home} \
112+ -Dsubsonic.home=${cfg.home} \
119− -Dsubsonic.host=${cfg.listenAddress} \
113+ -Dsubsonic.host=${cfg.listenAddress} \
120− -Dsubsonic.port=${toString cfg.port} \
114+ -Dsubsonic.port=${toString cfg.port} \
121− -Dsubsonic.httpsPort=${toString cfg.httpsPort} \
115+ -Dsubsonic.httpsPort=${toString cfg.httpsPort} \
122− -Dsubsonic.contextPath=${cfg.contextPath} \
116+ -Dsubsonic.contextPath=${cfg.contextPath} \
123− -Dsubsonic.defaultMusicFolder=${cfg.defaultMusicFolder} \
117+ -Dsubsonic.defaultMusicFolder=${cfg.defaultMusicFolder} \
124− -Dsubsonic.defaultPodcastFolder=${cfg.defaultPodcastFolder} \
118+ -Dsubsonic.defaultPodcastFolder=${cfg.defaultPodcastFolder} \
125− -Dsubsonic.defaultPlaylistFolder=${cfg.defaultPlaylistFolder} \
119+ -Dsubsonic.defaultPlaylistFolder=${cfg.defaultPlaylistFolder} \
126− -Djava.awt.headless=true \
120+ -Djava.awt.headless=true \
127− -verbose:gc \
121+ -verbose:gc \
128− -jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar
122+ -jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar
129− '';
123+ '';
124+
125+ preStart = ''
126+ # Formerly this module set cfg.home to /var/subsonic. Try to move
127+ # /var/subsonic to cfg.home.
128+ oldHome="/var/subsonic"
129+ if [ "${cfg.home}" != "$oldHome" ] &&
130+ ! [ -e "${cfg.home}" ] &&
131+ [ -d "$oldHome" ] &&
132+ [ $(${pkgs.coreutils}/bin/stat -c %u "$oldHome") -eq \
133+ ${toString config.users.extraUsers.subsonic.uid} ]; then
134+ logger Moving "$oldHome" to "${cfg.home}"
135+ ${pkgs.coreutils}/bin/mv -T "$oldHome" "${cfg.home}"
136+ fi
137+
130 # Install transcoders.
138 # Install transcoders.
131− ExecStartPre = ''
132− ${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \
139+ ${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \
133− ${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \
140+ ${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \
134− ${pkgs.bash}/bin/bash -c ' \
141+ ${pkgs.bash}/bin/bash -c ' \
135− for exe in "$@"; do \
142+ for exe in "$@"; do \
136− ${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \
143+ ${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \
137− done' IGNORED_FIRST_ARG ${toString cfg.transcoders}
144+ done' IGNORED_FIRST_ARG ${toString cfg.transcoders}
138− '';
145+ '';
146+ serviceConfig = {
139 # Needed for Subsonic to find subsonic.war.
147 # Needed for Subsonic to find subsonic.war.
140 WorkingDirectory = "${pkgs.subsonic}";
148 WorkingDirectory = "${pkgs.subsonic}";
141 Restart = "always";
149 Restart = "always";
@@ -146,7 +154,7 @@ in
146
154
147 users.extraUsers.subsonic = {
155 users.extraUsers.subsonic = {
148 description = "Subsonic daemon user";
156 description = "Subsonic daemon user";
149− home = homeDir;
157+ home = cfg.home;
150 createHome = true;
158 createHome = true;
151 group = "subsonic";
159 group = "subsonic";
152 uid = config.ids.uids.subsonic;
160 uid = config.ids.uids.subsonic;