1 { config, lib, pkgs, ... }:
4 cfg = config.services.mediamtx;
5 format = pkgs.formats.yaml {};
8 meta.maintainers = with lib.maintainers; [ fpletz ];
12 enable = lib.mkEnableOption "MediaMTX";
14 package = lib.mkPackageOption pkgs "mediamtx" { };
16 settings = lib.mkOption {
18 Settings for MediaMTX. Refer to the defaults at
19 <https://github.com/bluenviron/mediamtx/blob/main/mediamtx.yml>.
26 runOnInit = "\${lib.getExe pkgs.ffmpeg} -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH";
27 runOnInitRestart = true;
34 type = with lib.types; attrsOf anything;
35 description = "Extra environment variables for MediaMTX";
38 MTX_CONFKEY = "mykey";
42 allowVideoAccess = lib.mkEnableOption ''
43 access to video devices like cameras on the system
48 config = lib.mkIf cfg.enable {
49 # NOTE: mediamtx watches this file and automatically reloads if it changes
50 environment.etc."mediamtx.yaml".source = format.generate "mediamtx.yaml" cfg.settings;
52 systemd.services.mediamtx = {
53 after = [ "network.target" ];
54 wantedBy = [ "multi-user.target" ];
56 environment = cfg.env;
62 SupplementaryGroups = lib.mkIf cfg.allowVideoAccess "video";
63 ExecStart = "${cfg.package}/bin/mediamtx /etc/mediamtx.yaml";