blob: 399f4d582171d222ce74ace986ca5723da0ecf15 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
{ lib
, config
, options
, pkgs
, ...
}:
let
inherit (lib)
literalExpression
mkEnableOption
mkOption
mkPackageOption
types
;
cfg = config.services.go2rtc;
opt = options.services.go2rtc;
format = pkgs.formats.yaml {};
configFile = format.generate "go2rtc.yaml" cfg.settings;
in
{
meta.buildDocsInSandbox = false;
options.services.go2rtc = with types; {
enable = mkEnableOption "go2rtc streaming server";
package = mkPackageOption pkgs "go2rtc" { };
settings = mkOption {
default = {};
description = ''
go2rtc configuration as a Nix attribute set.
See the [wiki](https://github.com/AlexxIT/go2rtc/wiki/Configuration) for possible configuration options.
'';
type = submodule {
freeformType = format.type;
options = {
# https://github.com/AlexxIT/go2rtc/blob/v1.5.0/README.md#module-api
api = {
listen = mkOption {
type = str;
default = ":1984";
example = "127.0.0.1:1984";
description = ''
API listen address, conforming to a Go address string.
'';
};
};
# https://github.com/AlexxIT/go2rtc/blob/v1.5.0/README.md#source-ffmpeg
ffmpeg = {
bin = mkOption {
type = path;
default = "${lib.getBin pkgs.ffmpeg_6-headless}/bin/ffmpeg";
defaultText = literalExpression "\${lib.getBin pkgs.ffmpeg_6-headless}/bin/ffmpeg";
description = ''
The ffmpeg package to use for transcoding.
'';
};
};
# TODO: https://github.com/AlexxIT/go2rtc/blob/v1.5.0/README.md#module-rtsp
rtsp = {
};
streams = mkOption {
type = attrsOf (either str (listOf str));
default = {};
example = literalExpression ''
{
cam1 = "onvif://admin:password@192.168.1.123:2020";
cam2 = "tcp://192.168.1.123:12345";
}
'';
description = ''
Stream source configuration. Multiple source types are supported.
Check the [configuration reference](https://github.com/AlexxIT/go2rtc/blob/v${cfg.package.version}/README.md#module-streams) for possible options.
'';
};
# TODO: https://github.com/AlexxIT/go2rtc/blob/v1.5.0/README.md#module-webrtc
webrtc = {
};
};
};
};
};
config = lib.mkIf cfg.enable {
systemd.services.go2rtc = {
wants = [ "network-online.target" ];
after = [
"network-online.target"
];
wantedBy = [
"multi-user.target"
];
serviceConfig = {
DynamicUser = true;
User = "go2rtc";
SupplementaryGroups = [
# for v4l2 devices
"video"
];
StateDirectory = "go2rtc";
ExecStart = "${cfg.package}/bin/go2rtc -config ${configFile}";
};
};
};
}
|