From c41f4121b0fed9b4e157aae6ebd528b02b905794 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Mon, 13 Nov 2023 00:03:28 -0500 Subject: [PATCH] feat(binto): add gpu-screen-recorder module --- devices/binto/default.nix | 3 +- devices/binto/home/packages.nix | 15 +++++++ devices/binto/modules/desktop.nix | 1 + devices/binto/modules/gpu-replay.nix | 64 ++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 devices/binto/modules/gpu-replay.nix diff --git a/devices/binto/default.nix b/devices/binto/default.nix index e2abf49f..8db28a12 100644 --- a/devices/binto/default.nix +++ b/devices/binto/default.nix @@ -8,13 +8,14 @@ ../../modules/tailscale.nix ./modules/desktop.nix + ./modules/gpu-replay.nix ./modules/nix-gaming.nix ./modules/nvidia.nix ]; services.device-vars = { username = "matt"; - fontSize = 12.5; + fontSize = 10.0; }; users.users.matt = { diff --git a/devices/binto/home/packages.nix b/devices/binto/home/packages.nix index 3529329c..632ab931 100644 --- a/devices/binto/home/packages.nix +++ b/devices/binto/home/packages.nix @@ -1,4 +1,19 @@ { ... }: { + # Disable compositor in X11 for best performance + # TODO: add mic sound + xdg.configFile."gpu-screen-recorder.env".text = '' + WINDOW=focused + CONTAINER=mp4 + QUALITY=very_high + CODEC=auto + AUDIO_CODEC=opus + FRAMERATE=60 + REPLAYDURATION=1200 + OUTPUTDIR=/home/matt/Videos/Replay + MAKEFOLDERS=yes + ADDITIONAL_ARGS="-s 2560x1440" + ''; + xdg.desktopEntries."com.github.iwalton3.jellyfin-media-player" = { name = "Jellyfin Media Player"; comment = "Desktop client for Jellyfin"; diff --git a/devices/binto/modules/desktop.nix b/devices/binto/modules/desktop.nix index c65a2ec6..a3deb14f 100644 --- a/devices/binto/modules/desktop.nix +++ b/devices/binto/modules/desktop.nix @@ -18,6 +18,7 @@ p7zip # for reshade xclip wl-clipboard + vlc flat-remix-icon-theme nextcloud-client libreoffice-qt diff --git a/devices/binto/modules/gpu-replay.nix b/devices/binto/modules/gpu-replay.nix new file mode 100644 index 00000000..e6380754 --- /dev/null +++ b/devices/binto/modules/gpu-replay.nix @@ -0,0 +1,64 @@ +{ pkgs, lib, ... }: let + gsr = (pkgs.gpu-screen-recorder.overrideAttrs (o: { + src = pkgs.fetchgit { + url = "https://repo.dec05eba.com/gpu-screen-recorder"; + rev = "1ac862d155e10f050e6f6cca5381f9f5a3528d98"; + hash = "sha256-wLiBn4VIi+IWY4qVkdFzkHhECTFH97snogVTEwM5yx8="; + }; + + buildInputs = (o.buildInputs or [ ]) ++ (with pkgs; [ + wayland + wayland-protocols + libdrm + libva + xorg.libXrandr + libglvnd + ]); + + postPatch = ""; + + installPhase = '' + strip gsr-kms-server + strip gpu-screen-recorder + + install -Dm755 "gsr-kms-server" "$out/bin/gsr-kms-server" + install -Dm755 "gpu-screen-recorder" "$out/bin/gpu-screen-recorder" + install -Dm644 "extra/gpu-screen-recorder.service" "$out/lib/systemd/user/gpu-screen-recorder.service" + + wrapProgram $out/bin/gpu-screen-recorder --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ + pkgs.addOpenGLRunpath.driverLink + pkgs.libglvnd + ]}" + ''; + })); +in { + environment.systemPackages = with pkgs; [ + pulseaudio # for getting audio sink + gsr + + (writeShellScriptBin "gpu-save-replay" '' + exec ${pkgs.procps}/bin/pkill --signal SIGUSR1 -f gpu-screen-recorder + '') + + # Run this after login to make sure it works + (writeShellScriptBin "gpu-restart-replay" '' + exec systemctl --user restart gpu-screen-recorder.service + '') + ]; + + security.wrappers = { + gpu-screen-recorder = { + owner = "root"; + group = "video"; + capabilities = "cap_sys_nice+ep"; + source = "${gsr}/bin/gpu-screen-recorder"; + }; + + gsr-kms-server = { + owner = "root"; + group = "video"; + capabilities = "cap_sys_admin+ep"; + source = "${gsr}/bin/gsr-kms-server"; + }; + }; +}