1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 streams = builtins.attrNames config.services.liquidsoap.streams; 7 8 streamService = 9 name: 10 let stream = builtins.getAttr name config.services.liquidsoap.streams; in 11 { inherit name; 12 value = { 13 after = [ "network-online.target" "sound.target" ]; 14 description = "${name} liquidsoap stream"; 15 wantedBy = [ "multi-user.target" ]; 16 path = [ pkgs.wget ]; 17 preStart = 18 '' 19 mkdir -p /var/log/liquidsoap 20 chown liquidsoap -R /var/log/liquidsoap 21 ''; 22 serviceConfig = { 23 PermissionsStartOnly="true"; 24 ExecStart = "${pkgs.liquidsoap}/bin/liquidsoap ${stream}"; 25 User = "liquidsoap"; 26 }; 27 }; 28 }; 29in 30{ 31 32 ##### interface 33 34 options = { 35 36 services.liquidsoap.streams = mkOption { 37 38 description = 39 '' 40 Set of Liquidsoap streams to start, 41 one systemd service per stream. 42 ''; 43 44 default = {}; 45 46 example = { 47 myStream1 = literalExample "\"/etc/liquidsoap/myStream1.liq\""; 48 myStream2 = literalExample "./myStream2.liq"; 49 myStream3 = literalExample "\"out(playlist(\\\"/srv/music/\\\"))\""; 50 }; 51 52 type = types.attrsOf (types.either types.path types.str); 53 }; 54 55 }; 56 ##### implementation 57 58 config = mkIf (builtins.length streams != 0) { 59 60 users.extraUsers.liquidsoap = { 61 uid = config.ids.uids.liquidsoap; 62 group = "liquidsoap"; 63 extraGroups = [ "audio" ]; 64 description = "Liquidsoap streaming user"; 65 home = "/var/lib/liquidsoap"; 66 createHome = true; 67 }; 68 69 users.extraGroups.liquidsoap.gid = config.ids.gids.liquidsoap; 70 71 systemd.services = builtins.listToAttrs ( map streamService streams ); 72 }; 73 74}