at 23.11-beta 2.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.replay-sorcery; 7 configFile = generators.toKeyValue {} cfg.settings; 8in 9{ 10 options = with types; { 11 services.replay-sorcery = { 12 enable = mkEnableOption (lib.mdDoc "the ReplaySorcery service for instant-replays"); 13 14 enableSysAdminCapability = mkEnableOption (lib.mdDoc '' 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 = lib.mdDoc "Automatically start ReplaySorcery when graphical-session.target starts."; 23 }; 24 25 settings = mkOption { 26 type = attrsOf (oneOf [ str int ]); 27 default = {}; 28 description = lib.mdDoc "System-wide configuration for ReplaySorcery (/etc/replay-sorcery.conf)."; 29 example = literalExpression '' 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 owner = "root"; 48 group = "root"; 49 capabilities = "cap_sys_admin+ep"; 50 source = "${pkgs.replay-sorcery}/bin/replay-sorcery"; 51 }; 52 }; 53 54 systemd = { 55 packages = [ pkgs.replay-sorcery ]; 56 user.services.replay-sorcery = { 57 wantedBy = mkIf cfg.autoStart [ "graphical-session.target" ]; 58 partOf = mkIf cfg.autoStart [ "graphical-session.target" ]; 59 serviceConfig = { 60 ExecStart = mkIf cfg.enableSysAdminCapability [ 61 "" # Tell systemd to clear the existing ExecStart list, to prevent appending to it. 62 "${config.security.wrapperDir}/replay-sorcery" 63 ]; 64 }; 65 }; 66 }; 67 }; 68 69 meta = { 70 maintainers = with maintainers; [ kira-bruneau ]; 71 }; 72}