Release NixOS 23.11
[NixPkgs.git] / nixos / tests / mediamtx.nix
blob8cacd02631d9560089f3deaad49eeea91eaf41eb
1 import ./make-test-python.nix ({ pkgs, lib, ...} :
4   name = "mediamtx";
5   meta.maintainers = with lib.maintainers; [ fpletz ];
7   nodes = {
8     machine = { config, ... }: {
9       services.mediamtx = {
10         enable = true;
11         settings = {
12           metrics = true;
13           paths.all.source = "publisher";
14         };
15       };
17       systemd.services.rtmp-publish = {
18         description = "Publish an RTMP stream to mediamtx";
19         after = [ "mediamtx.service" ];
20         bindsTo = [ "mediamtx.service" ];
21         wantedBy = [ "multi-user.target" ];
22         serviceConfig = {
23           DynamicUser = true;
24           Restart = "on-failure";
25           RestartSec = "1s";
26           TimeoutStartSec = "10s";
27           ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -re -f lavfi -i smptebars=size=800x600:rate=10 -c libx264 -f flv rtmp://localhost:1935/test";
28         };
29       };
31       systemd.services.rtmp-receive = {
32         description = "Receive an RTMP stream from mediamtx";
33         after = [ "rtmp-publish.service" ];
34         bindsTo = [ "rtmp-publish.service" ];
35         wantedBy = [ "multi-user.target" ];
36         serviceConfig = {
37           DynamicUser = true;
38           Restart = "on-failure";
39           RestartSec = "1s";
40           TimeoutStartSec = "10s";
41           ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -y -re -i rtmp://localhost:1935/test -f flv /dev/null";
42         };
43       };
44     };
45   };
47   testScript = ''
48     start_all()
50     machine.wait_for_unit("mediamtx.service")
51     machine.wait_for_unit("rtmp-publish.service")
52     machine.wait_for_unit("rtmp-receive.service")
53     machine.wait_for_open_port(9998)
54     machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"publish\".*1$'")
55     machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"read\".*1$'")
56   '';