From ef11b36f846607301d37d47bcb1f7ea3ce92153b Mon Sep 17 00:00:00 2001 From: matt1432 Date: Thu, 21 Nov 2024 11:26:08 -0500 Subject: [PATCH] refactor(gsr): clean up packaging --- devices/binto/modules/gpu-replay.nix | 28 +++++++++++++------ packages/default.nix | 5 +++- .../{default.nix => generic.nix} | 11 ++------ .../gpu-screen-recorder.nix | 16 +++++++++++ .../gpu-screen-recorder/gsr-kms-server.nix | 20 +++++++++++++ 5 files changed, 62 insertions(+), 18 deletions(-) rename packages/gpu-screen-recorder/{default.nix => generic.nix} (85%) create mode 100644 packages/gpu-screen-recorder/gpu-screen-recorder.nix create mode 100644 packages/gpu-screen-recorder/gsr-kms-server.nix diff --git a/devices/binto/modules/gpu-replay.nix b/devices/binto/modules/gpu-replay.nix index 6c8de65c..3dc116dd 100644 --- a/devices/binto/modules/gpu-replay.nix +++ b/devices/binto/modules/gpu-replay.nix @@ -5,28 +5,27 @@ self, ... }: let - inherit (lib) concatStringsSep removePrefix; - + inherit (lib) concatStringsSep getExe removePrefix; inherit (config.vars) mainUser; + inherit (self.packages.${pkgs.system}) gpu-screen-recorder gsr-kms-server; + + hyprPkgs = config.home-manager.users.${mainUser}.wayland.windowManager.hyprland.finalPackage; cfgDesktop = config.roles.desktop; - - pkg = self.packages.${pkgs.system}.gpu-screen-recorder; - hyprPkgs = config.home-manager.users.${mainUser}.wayland.windowManager.hyprland.finalPackage; in { security.wrappers = { gpu-screen-recorder = { owner = "root"; group = "video"; capabilities = "cap_sys_nice+ep"; - source = "${pkg.gsr}/bin/gpu-screen-recorder"; + source = getExe gpu-screen-recorder; }; gsr-kms-server = { owner = "root"; group = "video"; capabilities = "cap_sys_admin+ep"; - source = "${pkg.kms}/bin/gsr-kms-server"; + source = getExe gsr-kms-server; }; }; @@ -34,7 +33,9 @@ in { home.packages = [ (pkgs.writeShellApplication { name = "gpu-save-replay"; - runtimeInputs = [pkgs.procps]; + + runtimeInputs = with pkgs; [procps]; + text = '' pkill --signal SIGUSR1 -f gpu-screen-recorder ''; @@ -42,7 +43,16 @@ in { (pkgs.writeShellApplication { name = "gsr-start"; - runtimeInputs = [pkgs.pulseaudio hyprPkgs pkgs.xorg.xrandr]; + + runtimeInputs = [ + pkgs.pulseaudio + pkgs.xorg.xrandr + + gpu-screen-recorder + gsr-kms-server + hyprPkgs + ]; + text = '' main="${removePrefix "desc:" cfgDesktop.mainMonitor}" WINDOW=$(hyprctl -j monitors | jq '.[] |= (.description |= gsub(","; ""))' | jq -r ".[] | select(.description | test(\"$main\")) | .name") diff --git a/packages/default.nix b/packages/default.nix index 7bc8645a..20af2f3b 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -4,7 +4,10 @@ pkgs, ... }: { - gpu-screen-recorder = pkgs.callPackage ./gpu-screen-recorder { + gpu-screen-recorder = pkgs.callPackage ./gpu-screen-recorder/gpu-screen-recorder.nix { + inherit (inputs) gpu-screen-recorder-src; + }; + gsr-kms-server = pkgs.callPackage ./gpu-screen-recorder/gsr-kms-server.nix { inherit (inputs) gpu-screen-recorder-src; }; diff --git a/packages/gpu-screen-recorder/default.nix b/packages/gpu-screen-recorder/generic.nix similarity index 85% rename from packages/gpu-screen-recorder/default.nix rename to packages/gpu-screen-recorder/generic.nix index 983ecbf8..af45ab7d 100644 --- a/packages/gpu-screen-recorder/default.nix +++ b/packages/gpu-screen-recorder/generic.nix @@ -62,6 +62,8 @@ in ]; fixupPhase = '' + runHook preFixup + wrapProgram $out/bin/gpu-screen-recorder \ --prefix LD_LIBRARY_PATH : "${ makeLibraryPath [ @@ -70,16 +72,9 @@ in ] }" - # This is needed to force gsr to lookup kms in PATH - # to get the security wrapper - mkdir -p $gsr $kms/bin - cp -r $out/bin $gsr - mv $gsr/bin/gsr-kms-server $kms/bin - rm $out/bin/gsr-kms-server + runHook postFixup ''; - outputs = ["out" "gsr" "kms"]; - meta = { description = "Screen recorder that has minimal impact on system performance by recording a window using the GPU only"; homepage = "https://git.dec05eba.com/gpu-screen-recorder/about/"; diff --git a/packages/gpu-screen-recorder/gpu-screen-recorder.nix b/packages/gpu-screen-recorder/gpu-screen-recorder.nix new file mode 100644 index 00000000..8728e399 --- /dev/null +++ b/packages/gpu-screen-recorder/gpu-screen-recorder.nix @@ -0,0 +1,16 @@ +{ + callPackage, + gpu-screen-recorder-src, + ... +}: let + gsr = callPackage ./generic.nix {inherit gpu-screen-recorder-src;}; +in + gsr.overrideAttrs (o: { + postFixup = '' + # This is needed to force gsr to lookup kms in PATH + # to get the security wrapper + rm $out/bin/gsr-kms-server + ''; + + meta = o.meta // {mainProgram = o.pname;}; + }) diff --git a/packages/gpu-screen-recorder/gsr-kms-server.nix b/packages/gpu-screen-recorder/gsr-kms-server.nix new file mode 100644 index 00000000..6155984e --- /dev/null +++ b/packages/gpu-screen-recorder/gsr-kms-server.nix @@ -0,0 +1,20 @@ +{ + callPackage, + gpu-screen-recorder-src, + ... +}: let + pname = "gsr-kms-server"; + gsr = callPackage ./generic.nix {inherit gpu-screen-recorder-src;}; +in + gsr.overrideAttrs (o: { + inherit pname; + + postFixup = '' + # This is needed to force gsr to lookup kms in PATH + # to get the security wrapper + rm $out/bin/gpu-screen-recorder + rm $out/bin/.gpu-screen-recorder-wrapped + ''; + + meta = o.meta // {mainProgram = pname;}; + })