From 34fd3a91adf14bcec660f07fb1c93b1d5acf8c55 Mon Sep 17 00:00:00 2001 From: NullBite Date: Tue, 16 Apr 2024 00:44:42 -0400 Subject: [PATCH] system: Add auto-offload wrapper command This command will *always* exist when OpenGL is enabled. If graphical offload is enabled, it will make sure the GPU is actually enabled using glxinfo (there's probably a better way to do this) and fallback to executing normally, otherwise it will just exec the passed command. --- system/hardware/opengl.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/system/hardware/opengl.nix b/system/hardware/opengl.nix index b48a19b..49b5fa3 100644 --- a/system/hardware/opengl.nix +++ b/system/hardware/opengl.nix @@ -5,6 +5,20 @@ in { options.nixfiles.hardware.opengl.enable = lib.mkEnableOption "OpenGL configuration"; config = lib.mkIf cfg.enable { + environment.systemPackages = let + offload-enabled = config.hardware.nvidia.prime.offload.enableOffloadCmd; + glxinfo = lib.getExe' pkgs.glxinfo "glxinfo"; + auto-offload = pkgs.writeShellScriptBin "auto-offload" ( + (if offload-enabled then '' + if nvidia-offload ${glxinfo} > /dev/null 2>&1 ; then + exec nvidia-offload "$@" + fi + '' else "") + + + '' + exec "$@" + ''); + in [ auto-offload ]; # Enable OpenGL hardware.opengl = { enable = true;