summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorArseniy Seroka <jagajaga@users.noreply.github.com>2015-07-07 01:09:19 +0300
committerArseniy Seroka <jagajaga@users.noreply.github.com>2015-07-07 01:09:19 +0300
commit4f2b22aff05a11b014a59dbf4505e49c6baa0271 (patch)
tree08b0bc50c44ffbc5df50772aa0bb42df1bc10f50 /nixos
parentb3639275560ee4d1956575e4c825e65b2d15884c (diff)
parentf64a5dd3f365d640cf80e49c4c875cf766ce9aeb (diff)
downloadnixlib-4f2b22aff05a11b014a59dbf4505e49c6baa0271.tar
nixlib-4f2b22aff05a11b014a59dbf4505e49c6baa0271.tar.gz
nixlib-4f2b22aff05a11b014a59dbf4505e49c6baa0271.tar.bz2
nixlib-4f2b22aff05a11b014a59dbf4505e49c6baa0271.tar.lz
nixlib-4f2b22aff05a11b014a59dbf4505e49c6baa0271.tar.xz
nixlib-4f2b22aff05a11b014a59dbf4505e49c6baa0271.tar.zst
nixlib-4f2b22aff05a11b014a59dbf4505e49c6baa0271.zip
Merge pull request #8629 from telotortium/subsonic
subsonic: init at 5.2.1
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/misc/ids.nix2
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/misc/subsonic.nix157
3 files changed, 160 insertions, 0 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index 80d6ff20f9b4..88c860110179 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -225,6 +225,7 @@
       uwsgi = 201;
       gitit = 202;
       riemanntools = 203;
+      subsonic = 204;
 
       # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
 
@@ -428,6 +429,7 @@
       uwsgi = 201;
       gitit = 202;
       riemanntools = 203;
+      subsonic = 204;
 
       # When adding a gid, make sure it doesn't match an existing
       # uid. Users and groups with the same name should have equal
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index c1014bdff2e2..d580e269df96 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -218,6 +218,7 @@
   ./services/misc/ripple-data-api.nix
   ./services/misc/rogue.nix
   ./services/misc/siproxd.nix
+  ./services/misc/subsonic.nix
   ./services/misc/svnserve.nix
   ./services/misc/synergy.nix
   ./services/misc/uhub.nix
diff --git a/nixos/modules/services/misc/subsonic.nix b/nixos/modules/services/misc/subsonic.nix
new file mode 100644
index 000000000000..3e1a2e8fbb51
--- /dev/null
+++ b/nixos/modules/services/misc/subsonic.nix
@@ -0,0 +1,157 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.subsonic;
+  homeDir = "/var/subsonic";
+
+in
+{
+  options = {
+    services.subsonic = {
+      enable = mkEnableOption "Subsonic daemon";
+
+      home = mkOption {
+        type = types.path;
+        default = "${homeDir}";
+        description = ''
+          The directory where Subsonic will create files.
+          Make sure it is writable.
+        '';
+      };
+
+      host = mkOption {
+        type = types.string;
+        default = "0.0.0.0";
+        description = ''
+          The host name or IP address on which to bind Subsonic.
+          Only relevant if you have multiple network interfaces and want
+          to make Subsonic available on only one of them. The default value
+          will bind Subsonic to all available network interfaces.
+        '';
+      };
+
+      port = mkOption {
+        type = types.int;
+        default = 4040;
+        description = ''
+          The port on which Subsonic will listen for
+          incoming HTTP traffic. Set to 0 to disable.
+        '';
+      };
+
+      httpsPort = mkOption {
+        type = types.int;
+        default = 0;
+        description = ''
+          The port on which Subsonic will listen for
+          incoming HTTPS traffic. Set to 0 to disable.
+        '';
+      };
+
+      contextPath = mkOption {
+        type = types.path;
+        default = "/";
+        description = ''
+          The context path, i.e., the last part of the Subsonic
+          URL. Typically '/' or '/subsonic'. Default '/'
+        '';
+      };
+
+      maxMemory = mkOption {
+        type = types.int;
+        default = 100;
+        description = ''
+          The memory limit (max Java heap size) in megabytes.
+          Default: 100
+        '';
+      };
+
+      defaultMusicFolder = mkOption {
+        type = types.path;
+        default = "/var/music";
+        description = ''
+          Configure Subsonic to use this folder for music.  This option
+          only has effect the first time Subsonic is started.
+        '';
+      };
+
+      defaultPodcastFolder = mkOption {
+        type = types.path;
+        default = "/var/music/Podcast";
+        description = ''
+          Configure Subsonic to use this folder for Podcasts.  This option
+          only has effect the first time Subsonic is started.
+        '';
+      };
+
+      defaultPlaylistFolder = mkOption {
+        type = types.path;
+        default = "/var/playlists";
+        description = ''
+          Configure Subsonic to use this folder for playlists.  This option
+          only has effect the first time Subsonic is started.
+        '';
+      };
+
+      transcoders = mkOption {
+        type = types.listOf types.path;
+        default = [ "${pkgs.ffmpeg}/bin/ffmpeg" ];
+        description = ''
+          List of paths to transcoder executables that should be accessible
+          from Subsonic. Symlinks will be created to each executable inside
+          ${cfg.home}/transcoders.
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.subsonic = {
+      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.host} \
+            -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
+        '';
+        # 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}
+        '';
+        # Needed for Subsonic to find subsonic.war.
+        WorkingDirectory = "${pkgs.subsonic}";
+        Restart = "always";
+        User = "subsonic";
+        UMask = "0022";
+      };
+    };
+
+    users.extraUsers.subsonic = {
+      description = "Subsonic daemon user";
+      home = homeDir;
+      createHome = true;
+      group = "subsonic";
+      uid = config.ids.uids.subsonic;
+    };
+
+    users.extraGroups.subsonic.gid = config.ids.gids.subsonic;
+  };
+}