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.
This commit is contained in:
NullBite 2024-04-16 00:44:42 -04:00
parent 0fd3f6455b
commit 34fd3a91ad
Signed by: nullbite
GPG Key ID: 6C4D545385D4925A

View File

@ -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;