Merge pull request #15471 from telotortium/subsonic

subsonic: change NixOS home directory config
This commit is contained in:
Joachim Fasting 2016-05-18 04:01:32 +02:00
commit cf5e07ca5b

View File

@ -2,19 +2,14 @@
with lib; with lib;
let let cfg = config.services.subsonic; in {
cfg = config.services.subsonic;
homeDir = "/var/subsonic";
in
{
options = { options = {
services.subsonic = { services.subsonic = {
enable = mkEnableOption "Subsonic daemon"; enable = mkEnableOption "Subsonic daemon";
home = mkOption { home = mkOption {
type = types.path; type = types.path;
default = "${homeDir}"; default = "/var/lib/subsonic";
description = '' description = ''
The directory where Subsonic will create files. The directory where Subsonic will create files.
Make sure it is writable. Make sure it is writable.
@ -112,8 +107,7 @@ in
description = "Personal media streamer"; description = "Personal media streamer";
after = [ "local-fs.target" "network.target" ]; after = [ "local-fs.target" "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig = { script = ''
ExecStart = ''
${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \ ${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \
-Dsubsonic.home=${cfg.home} \ -Dsubsonic.home=${cfg.home} \
-Dsubsonic.host=${cfg.listenAddress} \ -Dsubsonic.host=${cfg.listenAddress} \
@ -127,8 +121,21 @@ in
-verbose:gc \ -verbose:gc \
-jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar -jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar
''; '';
preStart = ''
# 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 \
${toString config.users.extraUsers.subsonic.uid} ]; then
logger Moving "$oldHome" to "${cfg.home}"
${pkgs.coreutils}/bin/mv -T "$oldHome" "${cfg.home}"
fi
# Install transcoders. # Install transcoders.
ExecStartPre = ''
${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \ ${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \
${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \ ${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \
${pkgs.bash}/bin/bash -c ' \ ${pkgs.bash}/bin/bash -c ' \
@ -136,6 +143,7 @@ in
${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \ ${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \
done' IGNORED_FIRST_ARG ${toString cfg.transcoders} done' IGNORED_FIRST_ARG ${toString cfg.transcoders}
''; '';
serviceConfig = {
# Needed for Subsonic to find subsonic.war. # Needed for Subsonic to find subsonic.war.
WorkingDirectory = "${pkgs.subsonic}"; WorkingDirectory = "${pkgs.subsonic}";
Restart = "always"; Restart = "always";
@ -146,7 +154,7 @@ in
users.extraUsers.subsonic = { users.extraUsers.subsonic = {
description = "Subsonic daemon user"; description = "Subsonic daemon user";
home = homeDir; home = cfg.home;
createHome = true; createHome = true;
group = "subsonic"; group = "subsonic";
uid = config.ids.uids.subsonic; uid = config.ids.uids.subsonic;