Remove n0emis as direct maintainer (#365023)
[NixPkgs.git] / nixos / modules / services / audio / liquidsoap.nix
blob5a070a9b2116b95b5f9bbcb871bfc8fcd71a30c0
2   config,
3   lib,
4   pkgs,
5   ...
6 }:
7 let
8   streams = builtins.attrNames config.services.liquidsoap.streams;
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     };
36   ##### interface
38   options = {
40     services.liquidsoap.streams = lib.mkOption {
42       description = ''
43         Set of Liquidsoap streams to start,
44         one systemd service per stream.
45       '';
47       default = { };
49       example = lib.literalExpression ''
50         {
51           myStream1 = "/etc/liquidsoap/myStream1.liq";
52           myStream2 = ./myStream2.liq;
53           myStream3 = "out(playlist(\"/srv/music/\"))";
54         }
55       '';
57       type = lib.types.attrsOf (lib.types.either lib.types.path lib.types.str);
58     };
60   };
61   ##### implementation
63   config = lib.mkIf (builtins.length streams != 0) {
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     };
74     users.groups.liquidsoap.gid = config.ids.gids.liquidsoap;
76     systemd.services = builtins.listToAttrs (map streamService streams);
77   };