From a712d8ff0b3a341d6e9ac30ecb2d88fbd2e0ddb1 Mon Sep 17 00:00:00 2001 From: Robert Irelan Date: Sat, 14 May 2016 14:13:30 -0700 Subject: [PATCH 1/3] subsonic: change NixOS home directory config Move Subsonic state directory from `/var/subsonic` to `/var/lib/subsonic`, since the general convention is for each application to put its state directory there. Also, automatically set the home directory of the `subsonic` user to the value of `config.services.subsonic.home`, rather than setting it to a value hardcoded in the module. This keeps the home directory of the `subsonic` user and the state directory for the Subsonic application in sync. --- nixos/modules/services/misc/subsonic.nix | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/nixos/modules/services/misc/subsonic.nix b/nixos/modules/services/misc/subsonic.nix index c1ebe418f72..0013912be77 100644 --- a/nixos/modules/services/misc/subsonic.nix +++ b/nixos/modules/services/misc/subsonic.nix @@ -2,19 +2,14 @@ with lib; -let - cfg = config.services.subsonic; - homeDir = "/var/subsonic"; - -in -{ +let cfg = config.services.subsonic; in { options = { services.subsonic = { enable = mkEnableOption "Subsonic daemon"; home = mkOption { type = types.path; - default = "${homeDir}"; + default = "/var/lib/subsonic"; description = '' The directory where Subsonic will create files. Make sure it is writable. @@ -146,7 +141,7 @@ in users.extraUsers.subsonic = { description = "Subsonic daemon user"; - home = homeDir; + home = cfg.home; createHome = true; group = "subsonic"; uid = config.ids.uids.subsonic; From 40d4f6df814e8070b3639c1687ade9af8e8e2c86 Mon Sep 17 00:00:00 2001 From: Robert Irelan Date: Mon, 16 May 2016 14:06:36 -0700 Subject: [PATCH 2/3] Move from ExecStart{,Pre} to systemd.nix attributes --- nixos/modules/services/misc/subsonic.nix | 47 ++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/nixos/modules/services/misc/subsonic.nix b/nixos/modules/services/misc/subsonic.nix index 0013912be77..a3c2d6c681d 100644 --- a/nixos/modules/services/misc/subsonic.nix +++ b/nixos/modules/services/misc/subsonic.nix @@ -107,30 +107,31 @@ let cfg = config.services.subsonic; in { description = "Personal media streamer"; after = [ "local-fs.target" "network.target" ]; wantedBy = [ "multi-user.target" ]; - serviceConfig = { - ExecStart = '' - ${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \ - -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 - ''; + script = '' + ${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \ + -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 = '' # Install transcoders. - ExecStartPre = '' - ${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} - ''; + ${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 = { # Needed for Subsonic to find subsonic.war. WorkingDirectory = "${pkgs.subsonic}"; Restart = "always"; From cf14dad167b19314f1497fff6b28bcbd597a7f8e Mon Sep 17 00:00:00 2001 From: Robert Irelan Date: Mon, 16 May 2016 14:11:06 -0700 Subject: [PATCH 3/3] Add script to move /var/subsonic to cfg.home --- nixos/modules/services/misc/subsonic.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nixos/modules/services/misc/subsonic.nix b/nixos/modules/services/misc/subsonic.nix index a3c2d6c681d..c2efd53d413 100644 --- a/nixos/modules/services/misc/subsonic.nix +++ b/nixos/modules/services/misc/subsonic.nix @@ -123,6 +123,18 @@ let cfg = config.services.subsonic; in { ''; 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. ${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \ ${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \