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