Merge pull request #278366 from ck3d/nixos-vdr-updates
nixos/vdr: add option user/group and more admin control
This commit is contained in:
commit
93ae65d7dd
1 changed files with 59 additions and 37 deletions
|
@ -1,18 +1,15 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.vdr;
|
cfg = config.services.vdr;
|
||||||
libDir = "/var/lib/vdr";
|
|
||||||
in {
|
|
||||||
|
|
||||||
###### interface
|
|
||||||
|
|
||||||
|
inherit (lib)
|
||||||
|
mkEnableOption mkPackageOption mkOption types mkIf optional mdDoc;
|
||||||
|
in
|
||||||
|
{
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
services.vdr = {
|
services.vdr = {
|
||||||
enable = mkEnableOption (lib.mdDoc "VDR. Please put config into ${libDir}");
|
enable = mkEnableOption (mdDoc "Start VDR");
|
||||||
|
|
||||||
package = mkPackageOption pkgs "vdr" {
|
package = mkPackageOption pkgs "vdr" {
|
||||||
example = "wrapVdr.override { plugins = with pkgs.vdrPlugins; [ hello ]; }";
|
example = "wrapVdr.override { plugins = with pkgs.vdrPlugins; [ hello ]; }";
|
||||||
|
@ -21,59 +18,84 @@ in {
|
||||||
videoDir = mkOption {
|
videoDir = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
default = "/srv/vdr/video";
|
default = "/srv/vdr/video";
|
||||||
description = lib.mdDoc "Recording directory";
|
description = mdDoc "Recording directory";
|
||||||
};
|
};
|
||||||
|
|
||||||
extraArguments = mkOption {
|
extraArguments = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [ ];
|
||||||
description = lib.mdDoc "Additional command line arguments to pass to VDR.";
|
description = mdDoc "Additional command line arguments to pass to VDR.";
|
||||||
};
|
};
|
||||||
|
|
||||||
enableLirc = mkEnableOption (lib.mdDoc "LIRC");
|
enableLirc = mkEnableOption (mdDoc "LIRC");
|
||||||
|
|
||||||
|
user = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "vdr";
|
||||||
|
description = mdDoc ''
|
||||||
|
User under which the VDR service runs.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
group = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "vdr";
|
||||||
|
description = mdDoc ''
|
||||||
|
Group under which the VDRvdr service runs.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
###### implementation
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [{
|
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
"d ${cfg.videoDir} 0755 vdr vdr -"
|
"d ${cfg.videoDir} 0755 ${cfg.user} ${cfg.group} -"
|
||||||
"Z ${cfg.videoDir} - vdr vdr -"
|
"Z ${cfg.videoDir} - ${cfg.user} ${cfg.group} -"
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services.vdr = {
|
systemd.services.vdr = {
|
||||||
description = "VDR";
|
description = "VDR";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
wants = optional cfg.enableLirc "lircd.service";
|
||||||
|
after = [ "network.target" ]
|
||||||
|
++ optional cfg.enableLirc "lircd.service";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = ''
|
ExecStart =
|
||||||
${cfg.package}/bin/vdr \
|
let
|
||||||
--video="${cfg.videoDir}" \
|
args = [
|
||||||
--config="${libDir}" \
|
"--video=${cfg.videoDir}"
|
||||||
${escapeShellArgs cfg.extraArguments}
|
]
|
||||||
'';
|
++ optional cfg.enableLirc "--lirc=${config.passthru.lirc.socket}"
|
||||||
User = "vdr";
|
++ cfg.extraArguments;
|
||||||
|
in
|
||||||
|
"${cfg.package}/bin/vdr ${lib.escapeShellArgs args}";
|
||||||
|
User = cfg.user;
|
||||||
|
Group = cfg.group;
|
||||||
CacheDirectory = "vdr";
|
CacheDirectory = "vdr";
|
||||||
StateDirectory = "vdr";
|
StateDirectory = "vdr";
|
||||||
|
RuntimeDirectory = "vdr";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.vdr = {
|
environment.systemPackages = [ cfg.package ];
|
||||||
group = "vdr";
|
|
||||||
home = libDir;
|
users.users = mkIf (cfg.user == "vdr") {
|
||||||
isSystemUser = true;
|
vdr = {
|
||||||
|
inherit (cfg) group;
|
||||||
|
home = "/run/vdr";
|
||||||
|
isSystemUser = true;
|
||||||
|
extraGroups = [
|
||||||
|
"video"
|
||||||
|
"audio"
|
||||||
|
]
|
||||||
|
++ optional cfg.enableLirc "lirc";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
users.groups.vdr = {};
|
users.groups = mkIf (cfg.group == "vdr") { vdr = { }; };
|
||||||
}
|
|
||||||
|
|
||||||
(mkIf cfg.enableLirc {
|
};
|
||||||
services.lirc.enable = true;
|
|
||||||
users.users.vdr.extraGroups = [ "lirc" ];
|
|
||||||
services.vdr.extraArguments = [
|
|
||||||
"--lirc=${config.passthru.lirc.socket}"
|
|
||||||
];
|
|
||||||
})]);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue