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

mediamtx: 0.23.8 -> 1.0.0, refactor module, add test
This commit is contained in:
WilliButz 2023-08-16 11:30:18 +02:00 committed by GitHub
commit da5c3bde30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 39 deletions

View file

@ -1,79 +1,66 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.services.mediamtx; cfg = config.services.mediamtx;
package = pkgs.mediamtx;
format = pkgs.formats.yaml {}; format = pkgs.formats.yaml {};
in in
{ {
meta.maintainers = with lib.maintainers; [ fpletz ];
options = { options = {
services.mediamtx = { services.mediamtx = {
enable = mkEnableOption (lib.mdDoc "MediaMTX"); enable = lib.mkEnableOption (lib.mdDoc "MediaMTX");
settings = mkOption { package = lib.mkPackageOptionMD pkgs "mediamtx" { };
settings = lib.mkOption {
description = lib.mdDoc '' description = lib.mdDoc ''
Settings for MediaMTX. Settings for MediaMTX. Refer to the defaults at
Read more at <https://github.com/aler9/mediamtx/blob/main/mediamtx.yml> <https://github.com/bluenviron/mediamtx/blob/main/mediamtx.yml>.
''; '';
type = format.type; type = format.type;
default = {};
default = {
logLevel = "info";
logDestinations = [
"stdout"
];
# we set this so when the user uses it, it just works (see LogsDirectory below). but it's not used by default.
logFile = "/var/log/mediamtx/mediamtx.log";
};
example = { example = {
paths = { paths = {
cam = { cam = {
runOnInit = "ffmpeg -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH"; runOnInit = "\${lib.getExe pkgs.ffmpeg} -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH";
runOnInitRestart = true; runOnInitRestart = true;
}; };
}; };
}; };
}; };
env = mkOption { env = lib.mkOption {
type = with types; attrsOf anything; type = with lib.types; attrsOf anything;
description = lib.mdDoc "Extra environment variables for MediaMTX"; description = lib.mdDoc "Extra environment variables for MediaMTX";
default = {}; default = {};
example = { example = {
MTX_CONFKEY = "mykey"; MTX_CONFKEY = "mykey";
}; };
}; };
allowVideoAccess = lib.mkEnableOption (lib.mdDoc ''
Enable access to video devices like cameras on the system.
'');
}; };
}; };
config = mkIf (cfg.enable) { config = lib.mkIf cfg.enable {
# NOTE: mediamtx watches this file and automatically reloads if it changes # NOTE: mediamtx watches this file and automatically reloads if it changes
environment.etc."mediamtx.yaml".source = format.generate "mediamtx.yaml" cfg.settings; environment.etc."mediamtx.yaml".source = format.generate "mediamtx.yaml" cfg.settings;
systemd.services.mediamtx = { systemd.services.mediamtx = {
environment = cfg.env;
after = [ "network.target" ]; after = [ "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = with pkgs; [ environment = cfg.env;
ffmpeg
];
serviceConfig = { serviceConfig = {
DynamicUser = true; DynamicUser = true;
User = "mediamtx"; User = "mediamtx";
Group = "mediamtx"; Group = "mediamtx";
SupplementaryGroups = lib.mkIf cfg.allowVideoAccess "video";
LogsDirectory = "mediamtx"; ExecStart = "${cfg.package}/bin/mediamtx /etc/mediamtx.yaml";
# user likely may want to stream cameras, can't hurt to add video group
SupplementaryGroups = "video";
ExecStart = "${package}/bin/mediamtx /etc/mediamtx.yaml";
}; };
}; };
}; };

View file

@ -463,6 +463,7 @@ in {
matrix-conduit = handleTest ./matrix/conduit.nix {}; matrix-conduit = handleTest ./matrix/conduit.nix {};
matrix-synapse = handleTest ./matrix/synapse.nix {}; matrix-synapse = handleTest ./matrix/synapse.nix {};
mattermost = handleTest ./mattermost.nix {}; mattermost = handleTest ./mattermost.nix {};
mediamtx = handleTest ./mediamtx.nix {};
mediatomb = handleTest ./mediatomb.nix {}; mediatomb = handleTest ./mediatomb.nix {};
mediawiki = handleTest ./mediawiki.nix {}; mediawiki = handleTest ./mediawiki.nix {};
meilisearch = handleTest ./meilisearch.nix {}; meilisearch = handleTest ./meilisearch.nix {};

57
nixos/tests/mediamtx.nix Normal file
View file

@ -0,0 +1,57 @@
import ./make-test-python.nix ({ pkgs, lib, ...} :
{
name = "mediamtx";
meta.maintainers = with lib.maintainers; [ fpletz ];
nodes = {
machine = { config, ... }: {
services.mediamtx = {
enable = true;
settings = {
metrics = true;
paths.all.source = "publisher";
};
};
systemd.services.rtmp-publish = {
description = "Publish an RTMP stream to mediamtx";
after = [ "mediamtx.service" ];
bindsTo = [ "mediamtx.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
DynamicUser = true;
Restart = "on-failure";
RestartSec = "1s";
TimeoutStartSec = "10s";
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";
};
};
systemd.services.rtmp-receive = {
description = "Receive an RTMP stream from mediamtx";
after = [ "rtmp-publish.service" ];
bindsTo = [ "rtmp-publish.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
DynamicUser = true;
Restart = "on-failure";
RestartSec = "1s";
TimeoutStartSec = "10s";
ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -y -re -i rtmp://localhost:1935/test -f flv /dev/null";
};
};
};
};
testScript = ''
start_all()
machine.wait_for_unit("mediamtx.service")
machine.wait_for_unit("rtmp-publish.service")
machine.wait_for_unit("rtmp-receive.service")
machine.wait_for_open_port(9998)
machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"publish\".*1$'")
machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"read\".*1$'")
'';
})

View file

@ -1,20 +1,21 @@
{ lib { lib
, fetchFromGitHub , fetchFromGitHub
, buildGoModule , buildGoModule
, nixosTests
}: }:
buildGoModule rec { buildGoModule rec {
pname = "mediamtx"; pname = "mediamtx";
version = "0.23.8"; version = "1.0.0";
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "aler9"; owner = "bluenviron";
repo = pname; repo = pname;
rev = "v${version}"; rev = "v${version}";
hash = "sha256-ICH102Z18dbabXVYgxCX4JTQ75v0A9wx2pIsZHIXDFg="; hash = "sha256-SKNCQu5uRAxKpQbceha50K4ShV7mE0VI1PGFVAlWq4Q=";
}; };
vendorHash = "sha256-uqcv05AHwwPxrix+FWSWpV8vKFqKQsMn8qEgD71zgo8="; vendorHash = "sha256-mPnAlFHCJKXOdmKP3Ff7cQJMStKtu4Sa7iYuot5/IKE=";
# Tests need docker # Tests need docker
doCheck = false; doCheck = false;
@ -23,13 +24,15 @@ buildGoModule rec {
"-X github.com/bluenviron/mediamtx/internal/core.version=v${version}" "-X github.com/bluenviron/mediamtx/internal/core.version=v${version}"
]; ];
passthru.tests = { inherit (nixosTests) mediamtx; };
meta = with lib; { meta = with lib; {
description = description =
"Ready-to-use RTSP server and RTSP proxy that allows to read and publish video and audio streams" "Ready-to-use RTSP server and RTSP proxy that allows to read and publish video and audio streams"
; ;
inherit (src.meta) homepage; inherit (src.meta) homepage;
license = licenses.mit; license = licenses.mit;
maintainers = with maintainers; [ ]; mainProgram = "mediamtx";
maintainers = with maintainers; [ fpletz ];
}; };
} }