at 23.11-pre 1.6 kB view raw
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 serviceConfig = { 18 ExecStart = "${pkgs.liquidsoap}/bin/liquidsoap ${stream}"; 19 User = "liquidsoap"; 20 LogsDirectory = "liquidsoap"; 21 }; 22 }; 23 }; 24in 25{ 26 27 ##### interface 28 29 options = { 30 31 services.liquidsoap.streams = mkOption { 32 33 description = 34 lib.mdDoc '' 35 Set of Liquidsoap streams to start, 36 one systemd service per stream. 37 ''; 38 39 default = {}; 40 41 example = literalExpression '' 42 { 43 myStream1 = "/etc/liquidsoap/myStream1.liq"; 44 myStream2 = ./myStream2.liq; 45 myStream3 = "out(playlist(\"/srv/music/\"))"; 46 } 47 ''; 48 49 type = types.attrsOf (types.either types.path types.str); 50 }; 51 52 }; 53 ##### implementation 54 55 config = mkIf (builtins.length streams != 0) { 56 57 users.users.liquidsoap = { 58 uid = config.ids.uids.liquidsoap; 59 group = "liquidsoap"; 60 extraGroups = [ "audio" ]; 61 description = "Liquidsoap streaming user"; 62 home = "/var/lib/liquidsoap"; 63 createHome = true; 64 }; 65 66 users.groups.liquidsoap.gid = config.ids.gids.liquidsoap; 67 68 systemd.services = builtins.listToAttrs ( map streamService streams ); 69 }; 70 71}