Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions nixos/modules/hardware/video/nvidia.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This module provides the proprietary NVIDIA X11 / OpenGL drivers.

{ config, lib, pkgs, pkgs_i686, ... }:
{ stdenv, config, lib, pkgs, pkgs_i686, ... }:

with lib;

Expand All @@ -23,7 +23,11 @@ let
else null;

nvidia_x11 = nvidiaForKernel config.boot.kernelPackages;
nvidia_libs32 = (nvidiaForKernel pkgs_i686.linuxPackages).override { libsOnly = true; kernel = null; };
nvidia_libs32 =
if versionOlder nvidia_x11.version "391" then
((nvidiaForKernel pkgs_i686.linuxPackages).override { libsOnly = true; kernel = null; }).out
else
(nvidiaForKernel config.boot.kernelPackages).lib32;

enabled = nvidia_x11 != null;

Expand Down Expand Up @@ -98,7 +102,7 @@ in
assertions = [
{
assertion = config.services.xserver.displayManager.gdm.wayland;
message = "NVidia drivers don't support wayland";
message = "NVIDIA drivers don't support wayland";
}
{
assertion = !optimusCfg.enable ||
Expand Down Expand Up @@ -161,7 +165,7 @@ in
};

hardware.opengl.package = nvidia_x11.out;
hardware.opengl.package32 = nvidia_libs32.out;
hardware.opengl.package32 = nvidia_libs32;

environment.systemPackages = [ nvidia_x11.bin nvidia_x11.settings ]
++ lib.filter (p: p != null) [ nvidia_x11.persistenced ];
Expand Down
60 changes: 36 additions & 24 deletions pkgs/os-specific/linux/nvidia-x11/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,44 @@ buildPhase() {
fi
}


installPhase() {
# Install libGL and friends.

# since version 391, 32bit libraries are bundled in the 32/ sub-directory
if [ "$i686bundled" = "1" ]; then
mkdir -p "$lib32/lib"
cp -prd 32/*.so.* 32/tls "$lib32/lib/"
fi

mkdir -p "$out/lib"
cp -prd *.so.* tls "$out/lib/"
rm $out/lib/lib{glx,nvidia-wfb}.so.* # handled separately
rm -f $out/lib/libnvidia-gtk* # built from source
if [ "$useGLVND" = "1" ]; then
# Pre-built libglvnd
rm $out/lib/lib{GL,GLX,EGL,GLESv1_CM,GLESv2,OpenGL,GLdispatch}.so.*
fi
# Use ocl-icd instead
rm $out/lib/libOpenCL.so*
# Move VDPAU libraries to their place
mkdir $out/lib/vdpau
mv $out/lib/libvdpau* $out/lib/vdpau

# Install ICDs.
install -Dm644 nvidia.icd $out/etc/OpenCL/vendors/nvidia.icd
if [ -e nvidia_icd.json.template ]; then
sed "s#__NV_VK_ICD__#libGLX_nvidia.so#" nvidia_icd.json.template > nvidia_icd.json
install -Dm644 nvidia_icd.json $out/share/vulkan/icd.d/nvidia.json
fi
if [ "$useGLVND" = "1" ]; then
install -Dm644 10_nvidia.json $out/share/glvnd/egl_vendor.d/nvidia.json
fi

for i in $lib32 $out; do
rm -f $i/lib/lib{glx,nvidia-wfb}.so.* # handled separately
rm -f $i/lib/libnvidia-gtk* # built from source
if [ "$useGLVND" = "1" ]; then
# Pre-built libglvnd
rm $i/lib/lib{GL,GLX,EGL,GLESv1_CM,GLESv2,OpenGL,GLdispatch}.so.*
fi
# Use ocl-icd instead
rm -f $i/lib/libOpenCL.so*
# Move VDPAU libraries to their place
mkdir $i/lib/vdpau
mv $i/lib/libvdpau* $i/lib/vdpau

# Install ICDs.
install -Dm644 nvidia.icd $i/etc/OpenCL/vendors/nvidia.icd
if [ -e nvidia_icd.json.template ]; then
sed "s#__NV_VK_ICD__#libGLX_nvidia.so#" nvidia_icd.json.template > nvidia_icd.json
install -Dm644 nvidia_icd.json $i/share/vulkan/icd.d/nvidia.json
fi
if [ "$useGLVND" = "1" ]; then
install -Dm644 10_nvidia.json $i/share/glvnd/egl_vendor.d/nvidia.json
fi

done


if [ -n "$bin" ]; then
# Install the X drivers.
Expand All @@ -60,7 +72,7 @@ installPhase() {
mkdir -p $bin/lib/xorg/modules/drivers
cp -p nvidia_drv.so $bin/lib/xorg/modules/drivers
mkdir -p $bin/lib/xorg/modules/extensions
cp -p libglx.so.* $bin/lib/xorg/modules/extensions
cp -p libglx*.so* $bin/lib/xorg/modules/extensions

# Install the kernel module.
mkdir -p $bin/lib/modules/$kernelVersion/misc
Expand All @@ -78,7 +90,7 @@ installPhase() {
fi

# All libs except GUI-only are installed now, so fixup them.
for libname in `find "$out/lib/" -name '*.so.*'` `test -z "$bin" || find "$bin/lib/" -name '*.so.*'`
for libname in $(find "$out/lib/" $(test -n "$lib32" && echo "$lib32/lib/") $(test -n "$bin" && echo "$bin/lib/") -name '*.so.*')
do
# I'm lazy to differentiate needed libs per-library, as the closure is the same.
# Unfortunately --shrink-rpath would strip too much.
Expand Down
8 changes: 6 additions & 2 deletions pkgs/os-specific/linux/nvidia-x11/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ rec {
patches = lib.optional (kernel.meta.branch == "4.19") ./drm_mode_connector.patch;
};

beta = stable; # not enough interest to maintain beta ATM

beta = generic {
version = "410.57";
sha256_64bit = "08534rv3wcmzslbwq11kd3s7cxm72p48dia6540c0586xwgjwg2w";
settingsSha256 = "1phhhzlc8n3rqdhrn757mnlqmsp616d079a6h1qjpa6jba9z9915";
persistencedSha256 = "1z7c1ff0y486yp9i5w0siwh9dnprml22x2avarbjfgqwm4f652lw";
};

legacy_340 = generic {
version = "340.104";
Expand Down
25 changes: 16 additions & 9 deletions pkgs/os-specific/linux/nvidia-x11/generic.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ version
, sha256_32bit
, sha256_32bit ? null
, sha256_64bit
, settingsSha256
, persistencedSha256
Expand All @@ -22,36 +22,43 @@

with stdenv.lib;

assert (!libsOnly) -> kernel != null;
assert !libsOnly -> kernel != null;
assert versionOlder version "391" -> sha256_32bit != null;
assert ! versionOlder version "391" -> stdenv.hostPlatform.system == "x86_64-linux";

let
nameSuffix = optionalString (!libsOnly) "-${kernel.version}";
pkgSuffix = optionalString (versionOlder version "304") "-pkg0";
i686bundled = versionAtLeast version "391";


self = stdenv.mkDerivation {
name = "nvidia-x11-${version}${nameSuffix}";

builder = ./builder.sh;

src =
if stdenv.hostPlatform.system == "i686-linux" then
fetchurl {
url = "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run";
sha256 = sha256_32bit;
}
else if stdenv.hostPlatform.system == "x86_64-linux" then
if stdenv.hostPlatform.system == "x86_64-linux" then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the order of i686 and x86_64 switched here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember what happened correctly, my system seemed to always evaluate i686 as true for some reason so I never got up to x86_64.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in some intermediate commits, there was an additional check, which made this order more logical. I have tested with the reverted order and it works as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll try changing it back tomorrow if the PR isn't merged by then.

fetchurl {
url = "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run";
sha256 = sha256_64bit;
}
else if stdenv.hostPlatform.system == "i686-linux" then
fetchurl {
url = "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run";
sha256 = sha256_32bit;
}
else throw "nvidia-x11 does not support platform ${stdenv.hostPlatform.system}";

patches = if libsOnly then null else patches;
inherit prePatch;
inherit version useGLVND useProfiles;
inherit (stdenv.hostPlatform) system;
inherit i686bundled;

outputs = [ "out" ] ++ optional (!libsOnly) "bin";
outputs = [ "out" ]
++ optional i686bundled "lib32"
++ optional (!libsOnly) "bin";
outputDev = if libsOnly then null else "bin";

kernel = if libsOnly then null else kernel.dev;
Expand Down