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