nixpkgs/nixos/modules/services/networking/mjpg-streamer.nix

81 lines
1.8 KiB
Nix
Raw Normal View History

2016-03-12 14:38:13 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.mjpg-streamer;
in {
options = {
services.mjpg-streamer = {
enable = mkEnableOption (lib.mdDoc "mjpg-streamer webcam streamer");
2016-03-12 14:38:13 +00:00
inputPlugin = mkOption {
type = types.str;
default = "input_uvc.so";
description = lib.mdDoc ''
2016-03-12 14:38:13 +00:00
Input plugin. See plugins documentation for more information.
'';
};
outputPlugin = mkOption {
type = types.str;
default = "output_http.so -w @www@ -n -p 5050";
description = lib.mdDoc ''
Output plugin. `@www@` is substituted for default mjpg-streamer www directory.
2016-03-12 14:38:13 +00:00
See plugins documentation for more information.
'';
};
user = mkOption {
type = types.str;
default = "mjpg-streamer";
description = lib.mdDoc "mjpg-streamer user name.";
2016-03-12 14:38:13 +00:00
};
group = mkOption {
type = types.str;
default = "video";
description = lib.mdDoc "mjpg-streamer group name.";
2016-03-12 14:38:13 +00:00
};
};
};
config = mkIf cfg.enable {
users.users = optionalAttrs (cfg.user == "mjpg-streamer") {
mjpg-streamer = {
uid = config.ids.uids.mjpg-streamer;
group = cfg.group;
};
2016-03-12 14:38:13 +00:00
};
systemd.services.mjpg-streamer = {
description = "mjpg-streamer webcam streamer";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Restart = "on-failure";
RestartSec = 1;
};
2016-03-12 14:38:13 +00:00
script = ''
IPLUGIN="${cfg.inputPlugin}"
OPLUGIN="${cfg.outputPlugin}"
OPLUGIN="''${OPLUGIN//@www@/${pkgs.mjpg-streamer}/share/mjpg-streamer/www}"
exec ${pkgs.mjpg-streamer}/bin/mjpg_streamer -i "$IPLUGIN" -o "$OPLUGIN"
'';
};
};
}