Merge pull request #248405 from fpletz/pkgs/mediamtx-1.0.0

mediamtx: 0.23.8 -> 1.0.0, refactor module, add test

authored by WilliButz and committed by GitHub da5c3bde 8f937650

+87 -39
+20 -33
nixos/modules/services/video/mediamtx.nix
··· 1 1 { config, lib, pkgs, ... }: 2 2 3 - with lib; 4 - 5 3 let 6 4 cfg = config.services.mediamtx; 7 - package = pkgs.mediamtx; 8 5 format = pkgs.formats.yaml {}; 9 6 in 10 7 { 8 + meta.maintainers = with lib.maintainers; [ fpletz ]; 9 + 11 10 options = { 12 11 services.mediamtx = { 13 - enable = mkEnableOption (lib.mdDoc "MediaMTX"); 12 + enable = lib.mkEnableOption (lib.mdDoc "MediaMTX"); 14 13 15 - settings = mkOption { 14 + package = lib.mkPackageOptionMD pkgs "mediamtx" { }; 15 + 16 + settings = lib.mkOption { 16 17 description = lib.mdDoc '' 17 - Settings for MediaMTX. 18 - Read more at <https://github.com/aler9/mediamtx/blob/main/mediamtx.yml> 18 + Settings for MediaMTX. Refer to the defaults at 19 + <https://github.com/bluenviron/mediamtx/blob/main/mediamtx.yml>. 19 20 ''; 20 21 type = format.type; 21 - 22 - default = { 23 - logLevel = "info"; 24 - logDestinations = [ 25 - "stdout" 26 - ]; 27 - # we set this so when the user uses it, it just works (see LogsDirectory below). but it's not used by default. 28 - logFile = "/var/log/mediamtx/mediamtx.log"; 29 - }; 30 - 22 + default = {}; 31 23 example = { 32 24 paths = { 33 25 cam = { 34 - runOnInit = "ffmpeg -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH"; 26 + runOnInit = "\${lib.getExe pkgs.ffmpeg} -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH"; 35 27 runOnInitRestart = true; 36 28 }; 37 29 }; 38 30 }; 39 31 }; 40 32 41 - env = mkOption { 42 - type = with types; attrsOf anything; 33 + env = lib.mkOption { 34 + type = with lib.types; attrsOf anything; 43 35 description = lib.mdDoc "Extra environment variables for MediaMTX"; 44 36 default = {}; 45 37 example = { 46 38 MTX_CONFKEY = "mykey"; 47 39 }; 48 40 }; 41 + 42 + allowVideoAccess = lib.mkEnableOption (lib.mdDoc '' 43 + Enable access to video devices like cameras on the system. 44 + ''); 49 45 }; 50 46 }; 51 47 52 - config = mkIf (cfg.enable) { 48 + config = lib.mkIf cfg.enable { 53 49 # NOTE: mediamtx watches this file and automatically reloads if it changes 54 50 environment.etc."mediamtx.yaml".source = format.generate "mediamtx.yaml" cfg.settings; 55 51 56 52 systemd.services.mediamtx = { 57 - environment = cfg.env; 58 - 59 53 after = [ "network.target" ]; 60 54 wantedBy = [ "multi-user.target" ]; 61 55 62 - path = with pkgs; [ 63 - ffmpeg 64 - ]; 56 + environment = cfg.env; 65 57 66 58 serviceConfig = { 67 59 DynamicUser = true; 68 60 User = "mediamtx"; 69 61 Group = "mediamtx"; 70 - 71 - LogsDirectory = "mediamtx"; 72 - 73 - # user likely may want to stream cameras, can't hurt to add video group 74 - SupplementaryGroups = "video"; 75 - 76 - ExecStart = "${package}/bin/mediamtx /etc/mediamtx.yaml"; 62 + SupplementaryGroups = lib.mkIf cfg.allowVideoAccess "video"; 63 + ExecStart = "${cfg.package}/bin/mediamtx /etc/mediamtx.yaml"; 77 64 }; 78 65 }; 79 66 };
+1
nixos/tests/all-tests.nix
··· 463 463 matrix-conduit = handleTest ./matrix/conduit.nix {}; 464 464 matrix-synapse = handleTest ./matrix/synapse.nix {}; 465 465 mattermost = handleTest ./mattermost.nix {}; 466 + mediamtx = handleTest ./mediamtx.nix {}; 466 467 mediatomb = handleTest ./mediatomb.nix {}; 467 468 mediawiki = handleTest ./mediawiki.nix {}; 468 469 meilisearch = handleTest ./meilisearch.nix {};
+57
nixos/tests/mediamtx.nix
··· 1 + import ./make-test-python.nix ({ pkgs, lib, ...} : 2 + 3 + { 4 + name = "mediamtx"; 5 + meta.maintainers = with lib.maintainers; [ fpletz ]; 6 + 7 + nodes = { 8 + machine = { config, ... }: { 9 + services.mediamtx = { 10 + enable = true; 11 + settings = { 12 + metrics = true; 13 + paths.all.source = "publisher"; 14 + }; 15 + }; 16 + 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 + }; 30 + 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 + }; 46 + 47 + testScript = '' 48 + start_all() 49 + 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 + ''; 57 + })
+9 -6
pkgs/servers/mediamtx/default.nix
··· 1 1 { lib 2 2 , fetchFromGitHub 3 3 , buildGoModule 4 + , nixosTests 4 5 }: 5 6 6 7 buildGoModule rec { 7 8 pname = "mediamtx"; 8 - version = "0.23.8"; 9 + version = "1.0.0"; 9 10 10 11 src = fetchFromGitHub { 11 - owner = "aler9"; 12 + owner = "bluenviron"; 12 13 repo = pname; 13 14 rev = "v${version}"; 14 - hash = "sha256-ICH102Z18dbabXVYgxCX4JTQ75v0A9wx2pIsZHIXDFg="; 15 + hash = "sha256-SKNCQu5uRAxKpQbceha50K4ShV7mE0VI1PGFVAlWq4Q="; 15 16 }; 16 17 17 - vendorHash = "sha256-uqcv05AHwwPxrix+FWSWpV8vKFqKQsMn8qEgD71zgo8="; 18 + vendorHash = "sha256-mPnAlFHCJKXOdmKP3Ff7cQJMStKtu4Sa7iYuot5/IKE="; 18 19 19 20 # Tests need docker 20 21 doCheck = false; ··· 23 24 "-X github.com/bluenviron/mediamtx/internal/core.version=v${version}" 24 25 ]; 25 26 27 + passthru.tests = { inherit (nixosTests) mediamtx; }; 28 + 26 29 meta = with lib; { 27 30 description = 28 31 "Ready-to-use RTSP server and RTSP proxy that allows to read and publish video and audio streams" 29 32 ; 30 33 inherit (src.meta) homepage; 31 34 license = licenses.mit; 32 - maintainers = with maintainers; [ ]; 35 + mainProgram = "mediamtx"; 36 + maintainers = with maintainers; [ fpletz ]; 33 37 }; 34 - 35 38 }