about summary refs log tree commit diff
path: root/nixos/modules/services/audio
diff options
context:
space:
mode:
authorEmery Hemingway <emery@vfemail.net>2014-11-20 17:30:24 -0500
committerEmery Hemingway <emery@vfemail.net>2014-11-20 17:41:15 -0500
commit21e4ff562409747a4ce18ffd61375db8dcd8116f (patch)
tree803d4a76506c3c07a75bc608ffaed916194a8677 /nixos/modules/services/audio
parentc1f458eb85147b6eb6baff0f7873da7bc111957e (diff)
downloadnixlib-21e4ff562409747a4ce18ffd61375db8dcd8116f.tar
nixlib-21e4ff562409747a4ce18ffd61375db8dcd8116f.tar.gz
nixlib-21e4ff562409747a4ce18ffd61375db8dcd8116f.tar.bz2
nixlib-21e4ff562409747a4ce18ffd61375db8dcd8116f.tar.lz
nixlib-21e4ff562409747a4ce18ffd61375db8dcd8116f.tar.xz
nixlib-21e4ff562409747a4ce18ffd61375db8dcd8116f.tar.zst
nixlib-21e4ff562409747a4ce18ffd61375db8dcd8116f.zip
initial liquidsoap service expression
Diffstat (limited to 'nixos/modules/services/audio')
-rw-r--r--nixos/modules/services/audio/liquidsoap.nix74
1 files changed, 74 insertions, 0 deletions
diff --git a/nixos/modules/services/audio/liquidsoap.nix b/nixos/modules/services/audio/liquidsoap.nix
new file mode 100644
index 000000000000..bf67d2399ebb
--- /dev/null
+++ b/nixos/modules/services/audio/liquidsoap.nix
@@ -0,0 +1,74 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  streams = builtins.attrNames config.services.liquidsoap.streams;
+
+  streamService =
+    name:
+    let stream = builtins.getAttr name config.services.liquidsoap.streams; in
+    { inherit name;
+      value = {
+        after = [ "network-online.target" "sound.target" ];
+        description = "${name} liquidsoap stream";
+        wantedBy = [ "multi-user.target" ];
+        path = [ pkgs.wget ];
+        preStart =
+          ''
+            mkdir -p /var/log/liquidsoap
+            chown liquidsoap -R /var/log/liquidsoap
+          '';
+        serviceConfig = {
+          PermissionsStartOnly="true";
+          ExecStart = "${pkgs.liquidsoap}/bin/liquidsoap ${stream}";
+          User = "liquidsoap";
+        };
+      };
+    };
+in
+{
+
+  ##### interface
+
+  options = {
+
+    services.liquidsoap.streams = mkOption {
+
+      description =
+        ''
+          Set of Liquidsoap streams to start,
+          one systemd service per stream.
+        '';
+
+      default = {};
+
+      example = {
+        myStream1 = literalExample "\"/etc/liquidsoap/myStream1.liq\"";
+        myStream2 = literalExample "./myStream2.liq";
+        myStream3 = literalExample "\"out(playlist(\"/srv/music/\"))\"";
+      };
+
+      type = types.attrsOf (types.either types.path types.str);
+    };
+
+  };
+  ##### implementation
+
+  config = mkIf (builtins.length streams != 0) {
+
+    users.extraUsers.liquidsoap = {
+      uid = config.ids.uids.liquidsoap;
+      group = "liquidsoap";
+      extraGroups = [ "audio" ];
+      description = "Liquidsoap streaming user";
+      home = "/var/lib/liquidsoap";
+      createHome = true;
+    };
+
+    users.extraGroups.liquidsoap.gid = config.ids.gids.liquidsoap;
+
+    systemd.services = builtins.listToAttrs ( map streamService streams );
+  };
+
+}