···11+{ config, lib, pkgs, ... }:
22+33+with lib;
44+55+let
66+ cfg = config.services.replay-sorcery;
77+ configFile = generators.toKeyValue {} cfg.settings;
88+in
99+{
1010+ options = with types; {
1111+ services.replay-sorcery = {
1212+ enable = mkEnableOption "the ReplaySorcery service for instant-replays";
1313+1414+ enableSysAdminCapability = mkEnableOption ''
1515+ the system admin capability to support hardware accelerated
1616+ video capture. This is equivalent to running ReplaySorcery as
1717+ root, so use with caution'';
1818+1919+ autoStart = mkOption {
2020+ type = bool;
2121+ default = false;
2222+ description = "Automatically start ReplaySorcery when graphical-session.target starts.";
2323+ };
2424+2525+ settings = mkOption {
2626+ type = attrsOf (oneOf [ str int ]);
2727+ default = {};
2828+ description = "System-wide configuration for ReplaySorcery (/etc/replay-sorcery.conf).";
2929+ example = literalExample ''
3030+ {
3131+ videoInput = "hwaccel"; # requires `services.replay-sorcery.enableSysAdminCapability = true`
3232+ videoFramerate = 60;
3333+ }
3434+ '';
3535+ };
3636+ };
3737+ };
3838+3939+ config = mkIf cfg.enable {
4040+ environment = {
4141+ systemPackages = [ pkgs.replay-sorcery ];
4242+ etc."replay-sorcery.conf".text = configFile;
4343+ };
4444+4545+ security.wrappers = mkIf cfg.enableSysAdminCapability {
4646+ replay-sorcery = {
4747+ source = "${pkgs.replay-sorcery}/bin/replay-sorcery";
4848+ capabilities = "cap_sys_admin+ep";
4949+ };
5050+ };
5151+5252+ systemd = {
5353+ packages = [ pkgs.replay-sorcery ];
5454+ user.services.replay-sorcery = {
5555+ wantedBy = mkIf cfg.autoStart [ "graphical-session.target" ];
5656+ partOf = mkIf cfg.autoStart [ "graphical-session.target" ];
5757+ serviceConfig = {
5858+ ExecStart = mkIf cfg.enableSysAdminCapability [
5959+ "" # Tell systemd to clear the existing ExecStart list, to prevent appending to it.
6060+ "${config.security.wrapperDir}/replay-sorcery"
6161+ ];
6262+ };
6363+ };
6464+ };
6565+ };
6666+6767+ meta = {
6868+ maintainers = with maintainers; [ kira-bruneau ];
6969+ };
7070+}
+9-3
pkgs/tools/video/replay-sorcery/default.nix
···2323 sha256 = "sha256-HPkSOwfwcg4jLUzKfqdXgLu7mgD5H4wb9d2BrqWQeHc=";
2424 };
25252626- # Patch in libnotify if support is enabled.
2727- patches = lib.optional notifySupport (substituteAll {
2626+ patches = [
2727+ # Use global config generated by NixOS (/etc/replay-sorcery.conf)
2828+ # instead of $out/etc/replay-sorcery.conf.
2929+ ./fix-global-config.patch
3030+ ] ++ lib.optional notifySupport (substituteAll {
3131+ # Patch in libnotify if support is enabled. Can't use makeWrapper
3232+ # since it would break the security wrapper in the NixOS module.
2833 src = ./hardcode-libnotify.patch;
2934 inherit libnotify;
3035 });
···4247 "-DRS_SYSTEMD_DIR=${placeholder "out"}/lib/systemd/user"
43484449 # SETUID & SETGID permissions required for hardware accelerated
4545- # video capture can't be set during the build.
5050+ # video capture can't be set during the build. Use the NixOS
5151+ # module if you want hardware accelerated video capture.
4652 "-DRS_SETID=OFF"
4753 ];
4854