about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/video/replay-sorcery.nix
blob: abe7202a4a8629e1a3ae523fdde77f2a8337a9a0 (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
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.replay-sorcery;
  configFile = generators.toKeyValue {} cfg.settings;
in
{
  options = with types; {
    services.replay-sorcery = {
      enable = mkEnableOption "the ReplaySorcery service for instant-replays";

      enableSysAdminCapability = mkEnableOption ''
        the system admin capability to support hardware accelerated
        video capture. This is equivalent to running ReplaySorcery as
        root, so use with caution'';

      autoStart = mkOption {
        type = bool;
        default = false;
        description = "Automatically start ReplaySorcery when graphical-session.target starts.";
      };

      settings = mkOption {
        type = attrsOf (oneOf [ str int ]);
        default = {};
        description = "System-wide configuration for ReplaySorcery (/etc/replay-sorcery.conf).";
        example = literalExpression ''
          {
            videoInput = "hwaccel"; # requires `services.replay-sorcery.enableSysAdminCapability = true`
            videoFramerate = 60;
          }
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    environment = {
      systemPackages = [ pkgs.replay-sorcery ];
      etc."replay-sorcery.conf".text = configFile;
    };

    security.wrappers = mkIf cfg.enableSysAdminCapability {
      replay-sorcery = {
        owner = "root";
        group = "root";
        capabilities = "cap_sys_admin+ep";
        source = "${pkgs.replay-sorcery}/bin/replay-sorcery";
      };
    };

    systemd = {
      packages = [ pkgs.replay-sorcery ];
      user.services.replay-sorcery = {
        wantedBy = mkIf cfg.autoStart [ "graphical-session.target" ];
        partOf = mkIf cfg.autoStart [ "graphical-session.target" ];
        serviceConfig = {
          ExecStart = mkIf cfg.enableSysAdminCapability [
            "" # Tell systemd to clear the existing ExecStart list, to prevent appending to it.
            "${config.security.wrapperDir}/replay-sorcery"
          ];
        };
      };
    };
  };

  meta = {
    maintainers = with maintainers; [ kira-bruneau ];
  };
}