···1+{ config, lib, pkgs, ... }:
2+3+with lib;
4+5+let
6+ cfg = config.services.replay-sorcery;
7+ configFile = generators.toKeyValue {} cfg.settings;
8+in
9+{
10+ options = with types; {
11+ services.replay-sorcery = {
12+ enable = mkEnableOption "the ReplaySorcery service for instant-replays";
13+14+ enableSysAdminCapability = mkEnableOption ''
15+ the system admin capability to support hardware accelerated
16+ video capture. This is equivalent to running ReplaySorcery as
17+ root, so use with caution'';
18+19+ autoStart = mkOption {
20+ type = bool;
21+ default = false;
22+ description = "Automatically start ReplaySorcery when graphical-session.target starts.";
23+ };
24+25+ settings = mkOption {
26+ type = attrsOf (oneOf [ str int ]);
27+ default = {};
28+ description = "System-wide configuration for ReplaySorcery (/etc/replay-sorcery.conf).";
29+ example = literalExample ''
30+ {
31+ videoInput = "hwaccel"; # requires `services.replay-sorcery.enableSysAdminCapability = true`
32+ videoFramerate = 60;
33+ }
34+ '';
35+ };
36+ };
37+ };
38+39+ config = mkIf cfg.enable {
40+ environment = {
41+ systemPackages = [ pkgs.replay-sorcery ];
42+ etc."replay-sorcery.conf".text = configFile;
43+ };
44+45+ security.wrappers = mkIf cfg.enableSysAdminCapability {
46+ replay-sorcery = {
47+ source = "${pkgs.replay-sorcery}/bin/replay-sorcery";
48+ capabilities = "cap_sys_admin+ep";
49+ };
50+ };
51+52+ systemd = {
53+ packages = [ pkgs.replay-sorcery ];
54+ user.services.replay-sorcery = {
55+ wantedBy = mkIf cfg.autoStart [ "graphical-session.target" ];
56+ partOf = mkIf cfg.autoStart [ "graphical-session.target" ];
57+ serviceConfig = {
58+ ExecStart = mkIf cfg.enableSysAdminCapability [
59+ "" # Tell systemd to clear the existing ExecStart list, to prevent appending to it.
60+ "${config.security.wrapperDir}/replay-sorcery"
61+ ];
62+ };
63+ };
64+ };
65+ };
66+67+ meta = {
68+ maintainers = with maintainers; [ kira-bruneau ];
69+ };
70+}
+9-3
pkgs/tools/video/replay-sorcery/default.nix
···23 sha256 = "sha256-HPkSOwfwcg4jLUzKfqdXgLu7mgD5H4wb9d2BrqWQeHc=";
24 };
2526- # Patch in libnotify if support is enabled.
27- patches = lib.optional notifySupport (substituteAll {
0000028 src = ./hardcode-libnotify.patch;
29 inherit libnotify;
30 });
···42 "-DRS_SYSTEMD_DIR=${placeholder "out"}/lib/systemd/user"
4344 # SETUID & SETGID permissions required for hardware accelerated
45- # video capture can't be set during the build.
046 "-DRS_SETID=OFF"
47 ];
48
···23 sha256 = "sha256-HPkSOwfwcg4jLUzKfqdXgLu7mgD5H4wb9d2BrqWQeHc=";
24 };
2526+ patches = [
27+ # Use global config generated by NixOS (/etc/replay-sorcery.conf)
28+ # instead of $out/etc/replay-sorcery.conf.
29+ ./fix-global-config.patch
30+ ] ++ lib.optional notifySupport (substituteAll {
31+ # Patch in libnotify if support is enabled. Can't use makeWrapper
32+ # since it would break the security wrapper in the NixOS module.
33 src = ./hardcode-libnotify.patch;
34 inherit libnotify;
35 });
···47 "-DRS_SYSTEMD_DIR=${placeholder "out"}/lib/systemd/user"
4849 # SETUID & SETGID permissions required for hardware accelerated
50+ # video capture can't be set during the build. Use the NixOS
51+ # module if you want hardware accelerated video capture.
52 "-DRS_SETID=OFF"
53 ];
54