For anyone who wants to follow at home, I wanted to document the simplest config that gets you to where I am. You need a local copy of the builder.sh from the nvidia_x11 package, because it’s been modified, in my case it’s next to my config and called nvidia_x11_builder.sh
The following is in my configuration.nix:
{ lib, config, pkgs, ... }:
let
nvidia-acceleration-overlay = (self: super: {
linuxPackages = super.linuxPackages.extend (final: prev: {
nvidia_x11.args = [ "-e" ./nvidia_x11_builder.sh ];
nvidia_x11.libPath = super.pkgs.lib.makeLibraryPath [ super.pkgs.libdrm super.pkgs.xorg.libXext super.pkgs.xorg.libX11 super.pkgs.xorg.libXv super.pkgs.xorg.libXrandr super.pkgs.xorg.libxcb super.pkgs.zlib super.pkgs.stdenv.cc.cc super.pkgs.wayland super.pkgs.libglvnd ];
nvidia_x11.libPath32 = super.pkgsi686Linux.lib.makeLibraryPath [ super.pkgsi686Linux.libdrm super.pkgsi686Linux.xorg.libXext super.pkgsi686Linux.xorg.libX11 super.pkgsi686Linux.xorg.libXv super.pkgsi686Linux.xorg.libXrandr super.pkgsi686Linux.xorg.libxcb super.pkgsi686Linux.zlib super.pkgsi686Linux.stdenv.cc.cc super.pkgsi686Linux.wayland super.pkgsi686Linux.libglvnd ];
});
mesa = super.mesa.overrideAttrs ( old: rec {
mesonFlags = super.mesa.mesonFlags ++ [ "-Dgbm-backends-path=/run/opengl-driver/lib/gbm:${placeholder "out"}/lib/gbm:${placeholder "out"}/lib" ];
});
wlroots = prev.wlroots.overrideAttrs(old: {
postPatch = ''
sed -i 's/assert(argb8888 &&/assert(true || argb8888 ||/g' 'render/wlr_renderer.c'
'';
});
xwayland = super.xwayland.overrideAttrs (old: rec {
version = "21.1.3";
src = super.fetchFromGitLab {
domain = "gitlab.freedesktop.org";
owner = "xorg";
repo = "xserver";
rev = "21e3dc3b5a576d38b549716bda0a6b34612e1f1f";
sha256 = "sha256-i2jQY1I9JupbzqSn1VA5JDPi01nVA6m8FwVQ3ezIbnQ=";
};
});
});
in
{
imports = [ ./nvidia.nix ./sway.nix ];
nixpkgs.overlays = [ nvidia-acceleration-overlay ];
}
Then you also need to following in a file called nvidia.nix:
{ config, pkgs, lib, ... }:
let
nvidiaPackage = config.boot.kernelPackages.nvidiaPackages.stable;
in
{
config = {
environment.etc."gbm/nvidia-drm_gbm.so".source = "${nvidiaPackage}/lib/libnvidia-allocator.so";
environment.etc."egl/egl_external_platform.d".source = "/run/opengl-driver/share/egl/egl_external_platform.d/";
hardware.opengl.enable = true;
hardware.opengl.driSupport = true;
hardware.opengl.driSupport32Bit = true;
hardware.pulseaudio.support32Bit = true;
hardware.opengl.extraPackages = with pkgs; [
vaapiVdpau
libvdpau-va-gl
libva
];
environment.systemPackages = with pkgs; [
firefox
vulkan-tools
libva-utils
];
hardware.nvidia.modesetting.enable = true;
hardware.nvidia.package = nvidiaPackage;
hardware.nvidia.powerManagement.enable = false;
services.xserver = {
videoDrivers = [ "nvidia" ];
displayManager.gdm.wayland = true;
displayManager.gdm.nvidiaWayland = true;
};
};
}
…and your sway config in sway.nix along with the following:
{ config, pkgs, lib, ... }:
{
programs.sway = {
enable = true;
extraOptions = [
"--unsupported-gpu"
"--my-next-gpu-wont-be-nvidia"
];
extraSessionCommands = ''
export MOZ_ENABLE_WAYLAND=1
export QT_QPA_PLATFORM=wayland
export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"
export SDL_VIDEODRIVER=wayland
export XDG_CURRENT_DESKTOP="sway"
export XDG_SESSION_TYPE="wayland"
export _JAVA_AWT_WM_NONREPARENTING=1
export GBM_BACKEND=nvidia-drm
export GBM_BACKENDS_PATH=/etc/gbm
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export WLR_NO_HARDWARE_CURSORS=1
'';
};
}
This doesn’t get you to steam, but it does get you acceleration working in wayland and sway.