mirror of
https://github.com/NixOS/nixos-hardware
synced 2024-12-25 02:59:45 +01:00
9194b8e949
The `-a` from exec sets the `$0` from the process. So `exec -a "$0"` would set the name of the new process to `nvidia-offload` (the name of the script), however this is causing issues with a few programs that try to interpret `$0` in a special way. For example, see `wine`: ``` $ nvidia-offload /nix/store/zhv91s26gsrl1w8yn9800xd03a31r3wj-wine-osu-7.0/bin/wine .osu/drive_c/osu/osu\!.exe /nix/store/zhv91s26gsrl1w8yn9800xd03a31r3wj-wine-osu-7.0/bin/nvidia-offload: could not open ``` What I think `wine` is doing here is trying to re-exec `wine` again, but to do so it tries to figure out the original call of wine by readind `$0`, and will fail in this case because the `$0` was changed because of the `nvidia-offload` script using `-a` flag, as explained above. Instead, let's simplify this. There is no good reason to rename the `$0` from the script anyway (it just sets a few environment variables), so let's just remove it. We may lose the ability to know if the command is being offloaded, but I think having more commands to work is a good trade-off.
26 lines
758 B
Nix
26 lines
758 B
Nix
{ lib, pkgs, ... }:
|
|
|
|
# This creates a new 'nvidia-offload' program that runs the application passed to it on the GPU
|
|
# As per https://nixos.wiki/wiki/Nvidia
|
|
let
|
|
nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
|
|
export __NV_PRIME_RENDER_OFFLOAD=1
|
|
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
|
|
export __GLX_VENDOR_LIBRARY_NAME=nvidia
|
|
export __VK_LAYER_NV_optimus=NVIDIA_only
|
|
exec "$@"
|
|
'';
|
|
in
|
|
{
|
|
services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ];
|
|
environment.systemPackages = [ nvidia-offload ];
|
|
|
|
hardware.nvidia.prime = {
|
|
offload.enable = lib.mkDefault true;
|
|
# Hardware should specify the bus ID for intel/nvidia devices
|
|
};
|
|
|
|
hardware.opengl.extraPackages = with pkgs; [
|
|
vaapiVdpau
|
|
];
|
|
}
|