9 cfg = config.services.mediamtx;
10 format = pkgs.formats.yaml { };
13 meta.maintainers = with lib.maintainers; [ fpletz ];
17 enable = lib.mkEnableOption "MediaMTX";
19 package = lib.mkPackageOption pkgs "mediamtx" { };
21 settings = lib.mkOption {
23 Settings for MediaMTX. Refer to the defaults at
24 <https://github.com/bluenviron/mediamtx/blob/main/mediamtx.yml>.
31 runOnInit = "\${lib.getExe pkgs.ffmpeg} -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH";
32 runOnInitRestart = true;
39 type = with lib.types; attrsOf anything;
40 description = "Extra environment variables for MediaMTX";
43 MTX_CONFKEY = "mykey";
47 allowVideoAccess = lib.mkEnableOption ''
48 access to video devices like cameras on the system
53 config = lib.mkIf cfg.enable {
54 # NOTE: mediamtx watches this file and automatically reloads if it changes
55 environment.etc."mediamtx.yaml".source = format.generate "mediamtx.yaml" cfg.settings;
57 systemd.services.mediamtx = {
58 after = [ "network.target" ];
59 wantedBy = [ "multi-user.target" ];
61 environment = cfg.env;
67 SupplementaryGroups = lib.mkIf cfg.allowVideoAccess "video";
68 ExecStart = "${cfg.package}/bin/mediamtx /etc/mediamtx.yaml";