Merge pull request #15471 from telotortium/subsonic

subsonic: change NixOS home directory config

+39 -31
+39 -31
nixos/modules/services/misc/subsonic.nix
··· 2 3 with lib; 4 5 - let 6 - cfg = config.services.subsonic; 7 - homeDir = "/var/subsonic"; 8 - 9 - in 10 - { 11 options = { 12 services.subsonic = { 13 enable = mkEnableOption "Subsonic daemon"; 14 15 home = mkOption { 16 type = types.path; 17 - default = "${homeDir}"; 18 description = '' 19 The directory where Subsonic will create files. 20 Make sure it is writable. ··· 112 description = "Personal media streamer"; 113 after = [ "local-fs.target" "network.target" ]; 114 wantedBy = [ "multi-user.target" ]; 115 serviceConfig = { 116 - ExecStart = '' 117 - ${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \ 118 - -Dsubsonic.home=${cfg.home} \ 119 - -Dsubsonic.host=${cfg.listenAddress} \ 120 - -Dsubsonic.port=${toString cfg.port} \ 121 - -Dsubsonic.httpsPort=${toString cfg.httpsPort} \ 122 - -Dsubsonic.contextPath=${cfg.contextPath} \ 123 - -Dsubsonic.defaultMusicFolder=${cfg.defaultMusicFolder} \ 124 - -Dsubsonic.defaultPodcastFolder=${cfg.defaultPodcastFolder} \ 125 - -Dsubsonic.defaultPlaylistFolder=${cfg.defaultPlaylistFolder} \ 126 - -Djava.awt.headless=true \ 127 - -verbose:gc \ 128 - -jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar 129 - ''; 130 - # Install transcoders. 131 - ExecStartPre = '' 132 - ${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \ 133 - ${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \ 134 - ${pkgs.bash}/bin/bash -c ' \ 135 - for exe in "$@"; do \ 136 - ${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \ 137 - done' IGNORED_FIRST_ARG ${toString cfg.transcoders} 138 - ''; 139 # Needed for Subsonic to find subsonic.war. 140 WorkingDirectory = "${pkgs.subsonic}"; 141 Restart = "always"; ··· 146 147 users.extraUsers.subsonic = { 148 description = "Subsonic daemon user"; 149 - home = homeDir; 150 createHome = true; 151 group = "subsonic"; 152 uid = config.ids.uids.subsonic;
··· 2 3 with lib; 4 5 + let cfg = config.services.subsonic; in { 6 options = { 7 services.subsonic = { 8 enable = mkEnableOption "Subsonic daemon"; 9 10 home = mkOption { 11 type = types.path; 12 + default = "/var/lib/subsonic"; 13 description = '' 14 The directory where Subsonic will create files. 15 Make sure it is writable. ··· 107 description = "Personal media streamer"; 108 after = [ "local-fs.target" "network.target" ]; 109 wantedBy = [ "multi-user.target" ]; 110 + script = '' 111 + ${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \ 112 + -Dsubsonic.home=${cfg.home} \ 113 + -Dsubsonic.host=${cfg.listenAddress} \ 114 + -Dsubsonic.port=${toString cfg.port} \ 115 + -Dsubsonic.httpsPort=${toString cfg.httpsPort} \ 116 + -Dsubsonic.contextPath=${cfg.contextPath} \ 117 + -Dsubsonic.defaultMusicFolder=${cfg.defaultMusicFolder} \ 118 + -Dsubsonic.defaultPodcastFolder=${cfg.defaultPodcastFolder} \ 119 + -Dsubsonic.defaultPlaylistFolder=${cfg.defaultPlaylistFolder} \ 120 + -Djava.awt.headless=true \ 121 + -verbose:gc \ 122 + -jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar 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 + 138 + # Install transcoders. 139 + ${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \ 140 + ${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \ 141 + ${pkgs.bash}/bin/bash -c ' \ 142 + for exe in "$@"; do \ 143 + ${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \ 144 + done' IGNORED_FIRST_ARG ${toString cfg.transcoders} 145 + ''; 146 serviceConfig = { 147 # Needed for Subsonic to find subsonic.war. 148 WorkingDirectory = "${pkgs.subsonic}"; 149 Restart = "always"; ··· 154 155 users.extraUsers.subsonic = { 156 description = "Subsonic daemon user"; 157 + home = cfg.home; 158 createHome = true; 159 group = "subsonic"; 160 uid = config.ids.uids.subsonic;