nixpkgs/nixos/modules/services/video/mediamtx.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.8 KiB
Nix
Raw Normal View History

2021-12-04 11:58:36 +00:00
{ config, lib, pkgs, ... }:
let
cfg = config.services.mediamtx;
2021-12-04 11:58:36 +00:00
format = pkgs.formats.yaml {};
in
{
meta.maintainers = with lib.maintainers; [ fpletz ];
2021-12-04 11:58:36 +00:00
options = {
services.mediamtx = {
enable = lib.mkEnableOption (lib.mdDoc "MediaMTX");
2021-12-04 11:58:36 +00:00
package = lib.mkPackageOption pkgs "mediamtx" { };
settings = lib.mkOption {
2021-12-04 11:58:36 +00:00
description = lib.mdDoc ''
Settings for MediaMTX. Refer to the defaults at
<https://github.com/bluenviron/mediamtx/blob/main/mediamtx.yml>.
2021-12-04 11:58:36 +00:00
'';
type = format.type;
default = {};
2021-12-04 11:58:36 +00:00
example = {
paths = {
cam = {
runOnInit = "\${lib.getExe pkgs.ffmpeg} -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH";
2021-12-04 11:58:36 +00:00
runOnInitRestart = true;
};
};
};
};
env = lib.mkOption {
type = with lib.types; attrsOf anything;
description = lib.mdDoc "Extra environment variables for MediaMTX";
2021-12-04 11:58:36 +00:00
default = {};
example = {
MTX_CONFKEY = "mykey";
2021-12-04 11:58:36 +00:00
};
};
allowVideoAccess = lib.mkEnableOption (lib.mdDoc ''
access to video devices like cameras on the system
'');
2021-12-04 11:58:36 +00:00
};
};
config = lib.mkIf cfg.enable {
# NOTE: mediamtx watches this file and automatically reloads if it changes
environment.etc."mediamtx.yaml".source = format.generate "mediamtx.yaml" cfg.settings;
2021-12-04 11:58:36 +00:00
systemd.services.mediamtx = {
2021-12-04 11:58:36 +00:00
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = cfg.env;
2021-12-04 11:58:36 +00:00
serviceConfig = {
DynamicUser = true;
User = "mediamtx";
Group = "mediamtx";
SupplementaryGroups = lib.mkIf cfg.allowVideoAccess "video";
ExecStart = "${cfg.package}/bin/mediamtx /etc/mediamtx.yaml";
2021-12-04 11:58:36 +00:00
};
};
};
}