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