summary refs log tree commit diff
path: root/nixos/modules/services/video
diff options
context:
space:
mode:
authordavidak <davidak@users.noreply.github.com>2021-08-03 07:44:35 +0200
committerGitHub <noreply@github.com>2021-08-03 07:44:35 +0200
commitbd27e2e8316ac6eab11aa35c586e743286f23ecf (patch)
tree5d8292cbe52e2bdae9165a21c47f75b058cd6531 /nixos/modules/services/video
parentf87f6fbf0de58b6ac221b80331c31abcd135a805 (diff)
parentb6e764bd6824422b6fcf949d24a1dfc7687bbc68 (diff)
downloadnixpkgs-bd27e2e8316ac6eab11aa35c586e743286f23ecf.tar
nixpkgs-bd27e2e8316ac6eab11aa35c586e743286f23ecf.tar.gz
nixpkgs-bd27e2e8316ac6eab11aa35c586e743286f23ecf.tar.bz2
nixpkgs-bd27e2e8316ac6eab11aa35c586e743286f23ecf.tar.lz
nixpkgs-bd27e2e8316ac6eab11aa35c586e743286f23ecf.tar.xz
nixpkgs-bd27e2e8316ac6eab11aa35c586e743286f23ecf.tar.zst
nixpkgs-bd27e2e8316ac6eab11aa35c586e743286f23ecf.zip
Merge pull request #123045 from kira-bruneau/replay-sorcery
replay-sorcery: init at 0.5.0
Diffstat (limited to 'nixos/modules/services/video')
-rw-r--r--nixos/modules/services/video/replay-sorcery.nix70
1 files changed, 70 insertions, 0 deletions
diff --git a/nixos/modules/services/video/replay-sorcery.nix b/nixos/modules/services/video/replay-sorcery.nix
new file mode 100644
index 00000000000..d78e782c796
--- /dev/null
+++ b/nixos/modules/services/video/replay-sorcery.nix
@@ -0,0 +1,70 @@
+{ 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 = literalExample ''
+          {
+            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 = {
+        source = "${pkgs.replay-sorcery}/bin/replay-sorcery";
+        capabilities = "cap_sys_admin+ep";
+      };
+    };
+
+    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 ];
+  };
+}