Skip to content

Commit f6332c0

Browse files
nixos/ustreamer: init; ustreamer: 6.12 -> 6.18 (#367415)
2 parents e00cd56 + 813b1d3 commit f6332c0

File tree

5 files changed

+137
-20
lines changed

5 files changed

+137
-20
lines changed

nixos/doc/manual/release-notes/rl-2505.section.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

5656
- [Bat](https://github.com/sharkdp/bat), a {manpage}`cat(1)` clone with wings. Available as [programs.bat](options.html#opt-programs.bat).
5757

58+
- [µStreamer](https://github.com/pikvm/ustreamer), a lightweight MJPEG-HTTP streamer. Available as [services.ustreamer](options.html#opt-services.ustreamer).
59+
5860
- [Whoogle Search](https://github.com/benbusby/whoogle-search), a self-hosted, ad-free, privacy-respecting metasearch engine. Available as [services.whoogle-search](options.html#opt-services.whoogle-search.enable).
5961

6062
- [agorakit](https://github.com/agorakit/agorakit), an organization tool for citizens' collectives. Available with [services.agorakit](options.html#opt-services.agorakit.enable).

nixos/modules/module-list.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@
14171417
./services/video/mirakurun.nix
14181418
./services/video/photonvision.nix
14191419
./services/video/mediamtx.nix
1420+
./services/video/ustreamer.nix
14201421
./services/video/v4l2-relayd.nix
14211422
./services/video/wivrn.nix
14221423
./services/wayland/cage.nix
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
utils,
6+
...
7+
}:
8+
let
9+
inherit (lib)
10+
getExe
11+
mkEnableOption
12+
mkIf
13+
mkOption
14+
mkPackageOption
15+
optionals
16+
types
17+
;
18+
19+
cfg = config.services.ustreamer;
20+
in
21+
{
22+
options.services.ustreamer = {
23+
enable = mkEnableOption "µStreamer, a lightweight MJPEG-HTTP streamer";
24+
25+
package = mkPackageOption pkgs "ustreamer" { };
26+
27+
autoStart = mkOption {
28+
description = ''
29+
Wether to start µStreamer on boot. Disabling this will use socket
30+
activation. The service will stop gracefully after some inactivity.
31+
Disabling this will set `--exit-on-no-clients=300`
32+
'';
33+
type = types.bool;
34+
default = true;
35+
example = false;
36+
};
37+
38+
listenAddress = mkOption {
39+
description = ''
40+
Address to expose the HTTP server. This accepts values for
41+
ListenStream= defined in {manpage}`systemd.socket(5)`
42+
'';
43+
type = types.str;
44+
default = "0.0.0.0:8080";
45+
example = "/run/ustreamer.sock";
46+
};
47+
48+
device = mkOption {
49+
description = ''
50+
The v4l2 device to stream.
51+
'';
52+
type = types.path;
53+
default = "/dev/video0";
54+
example = "/dev/v4l/by-id/usb-0000_Dummy_abcdef-video-index0";
55+
};
56+
57+
extraArgs = mkOption {
58+
description = ''
59+
Extra arguments to pass to `ustreamer`. See {manpage}`ustreamer(1)`
60+
'';
61+
type = with types; listOf str;
62+
default = [ ];
63+
example = [ "--resolution=1920x1080" ];
64+
};
65+
};
66+
67+
config = mkIf cfg.enable {
68+
services.ustreamer.extraArgs =
69+
[
70+
"--device=${cfg.device}"
71+
]
72+
++ optionals (!cfg.autoStart) [
73+
"--exit-on-no-clients=300"
74+
];
75+
76+
systemd.services."ustreamer" = {
77+
description = "µStreamer, a lightweight MJPEG-HTTP streamer";
78+
after = [ "network.target" ];
79+
requires = [ "ustreamer.socket" ];
80+
wantedBy = mkIf cfg.autoStart [ "multi-user.target" ];
81+
serviceConfig = {
82+
ExecStart = utils.escapeSystemdExecArgs (
83+
[
84+
(getExe cfg.package)
85+
"--systemd"
86+
]
87+
++ cfg.extraArgs
88+
);
89+
Restart = if cfg.autoStart then "always" else "on-failure";
90+
91+
DynamicUser = true;
92+
SupplementaryGroups = [ "video" ];
93+
94+
NoNewPrivileges = true;
95+
ProcSubset = "pid";
96+
ProtectProc = "noaccess";
97+
ProtectClock = "yes";
98+
DeviceAllow = [ cfg.device ];
99+
};
100+
};
101+
102+
systemd.sockets."ustreamer" = {
103+
wantedBy = [ "sockets.target" ];
104+
partOf = [ "ustreamer.service" ];
105+
socketConfig = {
106+
ListenStream = cfg.listenAddress;
107+
};
108+
};
109+
};
110+
}

nixos/tests/ustreamer.nix

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,13 @@ import ./make-test-python.nix (
4646
'';
4747
in
4848
{
49-
environment.systemPackages = [ pkgs.ustreamer ];
50-
networking.firewall.enable = false;
51-
systemd.services.ustreamer = {
52-
description = "ustreamer service";
53-
wantedBy = [ "multi-user.target" ];
54-
serviceConfig = {
55-
DynamicUser = true;
56-
ExecStart = "${pkgs.ustreamer}/bin/ustreamer --host=0.0.0.0 --port 8000 --device /dev/video9 --device-timeout=8";
57-
PrivateTmp = true;
58-
BindReadOnlyPaths = "/dev/video9";
59-
SupplementaryGroups = [
60-
"video"
61-
];
62-
Restart = "always";
63-
};
49+
services.ustreamer = {
50+
enable = true;
51+
device = "/dev/video9";
52+
extraArgs = [ "--device-timeout=8" ];
6453
};
54+
networking.firewall.allowedTCPPorts = [ 8080 ];
55+
6556
boot.extraModulePackages = [ config.boot.kernelPackages.akvcam ];
6657
boot.kernelModules = [ "akvcam" ];
6758
boot.extraModprobeConfig = ''
@@ -74,10 +65,10 @@ import ./make-test-python.nix (
7465
start_all()
7566
7667
camera.wait_for_unit("ustreamer.service")
77-
camera.wait_for_open_port(8000)
68+
camera.wait_for_open_port(8080)
7869
7970
client.wait_for_unit("multi-user.target")
80-
client.succeed("curl http://camera:8000")
71+
client.succeed("curl http://camera:8080")
8172
'';
8273
}
8374
)

pkgs/by-name/us/ustreamer/package.nix

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
jansson,
1515
libopus,
1616
nixosTests,
17+
systemdLibs,
18+
which,
19+
withSystemd ? true,
1720
withJanus ? true,
1821
}:
1922
stdenv.mkDerivation rec {
2023
pname = "ustreamer";
21-
version = "6.12";
24+
version = "6.18";
2225

2326
src = fetchFromGitHub {
2427
owner = "pikvm";
2528
repo = "ustreamer";
2629
rev = "v${version}";
27-
hash = "sha256-iaCgPHgklk7tbhJhQmyjKggb1bMWBD+Zurgfk9sCQ3E=";
30+
hash = "sha256-VzhTfr0Swrv3jZUvBYYy5l0+iSokIztpeyA1CuG/roY=";
2831
};
2932

3033
buildInputs =
@@ -34,6 +37,9 @@ stdenv.mkDerivation rec {
3437
libjpeg
3538
libdrm
3639
]
40+
++ lib.optionals withSystemd [
41+
systemdLibs
42+
]
3743
++ lib.optionals withJanus [
3844
janus-gateway
3945
glib
@@ -43,13 +49,19 @@ stdenv.mkDerivation rec {
4349
libopus
4450
];
4551

46-
nativeBuildInputs = [ pkg-config ];
52+
nativeBuildInputs = [
53+
pkg-config
54+
which
55+
];
4756

4857
makeFlags =
4958
[
5059
"PREFIX=${placeholder "out"}"
5160
"WITH_V4P=1"
5261
]
62+
++ lib.optionals withSystemd [
63+
"WITH_SYSTEMD=1"
64+
]
5365
++ lib.optionals withJanus [
5466
"WITH_JANUS=1"
5567
# Workaround issues with Janus C Headers
@@ -77,5 +89,6 @@ stdenv.mkDerivation rec {
7789
matthewcroughan
7890
];
7991
platforms = platforms.linux;
92+
mainProgram = "ustreamer";
8093
};
8194
}

0 commit comments

Comments
 (0)