nixfiles/system/hardware/opengl.nix
NullBite 34fd3a91ad
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.
2024-04-16 00:44:42 -04:00

30 lines
849 B
Nix

{ config, lib, pkgs, ...}:
let
cfg = config.nixfiles.hardware.opengl;
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;
driSupport = lib.mkDefault true;
driSupport32Bit = lib.mkDefault config.hardware.opengl.driSupport;
};
};
}