prohibit sha-less nixgl

pull/5/head
pegasust 2023-01-12 13:01:11 -07:00
parent 4a5981d050
commit 8b1ba34164
3 changed files with 237 additions and 197 deletions

View File

@ -8,8 +8,9 @@
(flake-utils.lib.eachDefaultSystem (system: (flake-utils.lib.eachDefaultSystem (system:
let let
isIntelX86Platform = system == "x86_64-linux"; isIntelX86Platform = system == "x86_64-linux";
nix_pkgs = import nixpkgs {inherit system;};
pkgs = import ./default.nix { pkgs = import ./default.nix {
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nix_pkgs;
enable32bits = isIntelX86Platform; enable32bits = isIntelX86Platform;
enableIntelX86Extensions = isIntelX86Platform; enableIntelX86Extensions = isIntelX86Platform;
}; };

View File

@ -1,22 +1,42 @@
{ # # Nvidia informations. {
# Version of the system kernel module. Let it to null to enable auto-detection. # # Nvidia informations.
nvidiaVersion ? null, # Version of the system kernel module. Let it to null to enable auto-detection.
# Hash of the Nvidia driver .run file. null is fine, but fixing a value here nvidiaVersion ? null
# will be more reproducible and more efficient. , # Hash of the Nvidia driver .run file. null is fine, but fixing a value here
nvidiaHash ? null, # will be more reproducible and more efficient.
# Alternatively, you can pass a path that points to a nvidia version file nvidiaHash ? null
# and let nixGL extract the version from it. That file must be a copy of , # Alternatively, you can pass a path that points to a nvidia version file
# /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see # and let nixGL extract the version from it. That file must be a copy of
# https://github.com/NixOS/nix/issues/3539 ). # /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see
nvidiaVersionFile ? null, # https://github.com/NixOS/nix/issues/3539 ).
# Enable 32 bits driver nvidiaVersionFile ? null
# This is one by default, you can switch it to off if you want to reduce a , # Enable 32 bits driver
# bit the size of nixGL closure. # This is one by default, you can switch it to off if you want to reduce a
enable32bits ? true # bit the size of nixGL closure.
, writeTextFile, shellcheck, pcre, runCommand, linuxPackages enable32bits ? true
, fetchurl, lib, runtimeShell, bumblebee, libglvnd, vulkan-validation-layers , writeTextFile
, mesa, libvdpau-va-gl, intel-media-driver, vaapiIntel, pkgsi686Linux, driversi686Linux , shellcheck
, zlib, libdrm, xorg, wayland, gcc }: , pcre
, runCommand
, linuxPackages
, fetchurl
, lib
, runtimeShell
, bumblebee
, libglvnd
, vulkan-validation-layers
, mesa
, libvdpau-va-gl
, intel-media-driver
, vaapiIntel
, pkgsi686Linux
, driversi686Linux
, zlib
, libdrm
, xorg
, wayland
, gcc
}:
let let
writeExecutable = { name, text }: writeExecutable = { name, text }:
@ -38,160 +58,169 @@ let
}; };
top = rec { top = rec {
/* /*
It contains the builder for different nvidia configuration, parametrized by It contains the builder for different nvidia configuration, parametrized by
the version of the driver and sha256 sum of the driver installer file. the version of the driver and sha256 sum of the driver installer file.
*/ */
nvidiaPackages = { version, sha256 ? null }: rec { nvidiaPackages = { version }:
nvidiaDrivers = (linuxPackages.nvidia_x11.override { }).overrideAttrs let
(oldAttrs: rec { nvidiaDrivers = (linuxPackages.nvidia_x11.override { }).overrideAttrs
pname = "nvidia"; (oldAttrs: {
name = "nvidia-x11-${version}-nixGL"; pname = "nvidia";
inherit version; name = "nvidia-x11-${version}-nixGL";
src = let inherit version;
url = src =
"https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}.run"; let
in if sha256 != null then url =
fetchurl { inherit url sha256; } "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}.run";
else in
builtins.fetchurl url; fetchurl { inherit url sha256; };
useGLVND = true; useGLVND = true;
}); });
in
{
inherit nvidiaDrivers;
nvidiaLibsOnly = nvidiaDrivers.override {
libsOnly = true;
kernel = null;
};
nvidiaLibsOnly = nvidiaDrivers.override { nixGLNvidiaBumblebee = writeExecutable {
libsOnly = true; name = "nixGLNvidiaBumblebee-${version}";
kernel = null;
};
nixGLNvidiaBumblebee = writeExecutable {
name = "nixGLNvidiaBumblebee-${version}";
text = ''
#!${runtimeShell}
export LD_LIBRARY_PATH=${
lib.makeLibraryPath [ nvidiaDrivers ]
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
${
bumblebee.override {
nvidia_x11 = nvidiaDrivers;
nvidia_x11_i686 = nvidiaDrivers.lib32;
}
}/bin/optirun --ldpath ${
lib.makeLibraryPath ([ libglvnd nvidiaDrivers ]
++ lib.optionals enable32bits [
nvidiaDrivers.lib32
pkgsi686Linux.libglvnd
])
} "$@"
'';
};
# TODO: 32bit version? Not tested.
nixNvidiaWrapper = api:
writeExecutable {
name = "nix${api}Nvidia-${version}";
text = '' text = ''
#!${runtimeShell} #!${runtimeShell}
${lib.optionalString (api == "Vulkan") export LD_LIBRARY_PATH=${
"export VK_LAYER_PATH=${vulkan-validation-layers}/share/vulkan/explicit_layer.d"} lib.makeLibraryPath [ nvidiaDrivers ]
NVIDIA_JSON=(${nvidiaLibsOnly}/share/glvnd/egl_vendor.d/*nvidia.json) }"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
${lib.optionalString enable32bits "NVIDIA_JSON32=(${nvidiaLibsOnly.lib32}/share/glvnd/egl_vendor.d/*nvidia.json)"} ${
bumblebee.override {
${''export __EGL_VENDOR_LIBRARY_FILENAMES=''${NVIDIA_JSON[*]}${ nvidia_x11 = nvidiaDrivers;
lib.optionalString enable32bits nvidia_x11_i686 = nvidiaDrivers.lib32;
'':''${NVIDIA_JSON32[*]}''
}"''${__EGL_VENDOR_LIBRARY_FILENAMES:+:$__EGL_VENDOR_LIBRARY_FILENAMES}"''
}
${
lib.optionalString (api == "Vulkan")
''export VK_ICD_FILENAMES=${nvidiaLibsOnly}/share/vulkan/icd.d/nvidia_icd.json${
lib.optionalString enable32bits
":${nvidiaLibsOnly.lib32}/share/vulkan/icd.d/nvidia_icd.json"
}"''${VK_ICD_FILENAMES:+:$VK_ICD_FILENAMES}"''
} }
export LD_LIBRARY_PATH=${ }/bin/optirun --ldpath ${
lib.makeLibraryPath ([ libglvnd nvidiaLibsOnly ] lib.makeLibraryPath ([ libglvnd nvidiaDrivers ]
++ lib.optional (api == "Vulkan") vulkan-validation-layers ++ lib.optionals enable32bits [
++ lib.optionals enable32bits [ nvidiaDrivers.lib32
nvidiaLibsOnly.lib32 pkgsi686Linux.libglvnd
pkgsi686Linux.libglvnd ])
]) } "$@"
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec "$@"
''; '';
}; };
# TODO: 32bit version? Not tested. # TODO: 32bit version? Not tested.
nixGLNvidia = nixNvidiaWrapper "GL"; nixNvidiaWrapper = api:
writeExecutable {
name = "nix${api}Nvidia-${version}";
text = ''
#!${runtimeShell}
${lib.optionalString (api == "Vulkan")
"export VK_LAYER_PATH=${vulkan-validation-layers}/share/vulkan/explicit_layer.d"}
NVIDIA_JSON=(${nvidiaLibsOnly}/share/glvnd/egl_vendor.d/*nvidia.json)
${lib.optionalString enable32bits "NVIDIA_JSON32=(${nvidiaLibsOnly.lib32}/share/glvnd/egl_vendor.d/*nvidia.json)"}
# TODO: 32bit version? Not tested. ${''export __EGL_VENDOR_LIBRARY_FILENAMES=''${NVIDIA_JSON[*]}${
nixVulkanNvidia = nixNvidiaWrapper "Vulkan"; lib.optionalString enable32bits
}; '':''${NVIDIA_JSON32[*]}''
}"''${__EGL_VENDOR_LIBRARY_FILENAMES:+:$__EGL_VENDOR_LIBRARY_FILENAMES}"''
}
${
lib.optionalString (api == "Vulkan")
''export VK_ICD_FILENAMES=${nvidiaLibsOnly}/share/vulkan/icd.d/nvidia_icd.json${
lib.optionalString enable32bits
":${nvidiaLibsOnly.lib32}/share/vulkan/icd.d/nvidia_icd.json"
}"''${VK_ICD_FILENAMES:+:$VK_ICD_FILENAMES}"''
}
export LD_LIBRARY_PATH=${
lib.makeLibraryPath ([ libglvnd nvidiaLibsOnly ]
++ lib.optional (api == "Vulkan") vulkan-validation-layers
++ lib.optionals enable32bits [
nvidiaLibsOnly.lib32
pkgsi686Linux.libglvnd
])
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec "$@"
'';
};
# TODO: 32bit version? Not tested.
nixGLNvidia = nixNvidiaWrapper "GL";
# TODO: 32bit version? Not tested.
nixVulkanNvidia = nixNvidiaWrapper "Vulkan";
};
nixGLIntel = writeExecutable { nixGLIntel = writeExecutable {
name = "nixGLIntel"; name = "nixGLIntel";
# add the 32 bits drivers if needed # add the 32 bits drivers if needed
text = let text =
mesa-drivers = [ mesa.drivers ] let
++ lib.optional enable32bits pkgsi686Linux.mesa.drivers; mesa-drivers = [ mesa.drivers ]
intel-driver = [ intel-media-driver vaapiIntel ] ++ lib.optional enable32bits pkgsi686Linux.mesa.drivers;
# Note: intel-media-driver is disabled for i686 until https://github.com/NixOS/nixpkgs/issues/140471 is fixed intel-driver = [ intel-media-driver vaapiIntel ]
++ lib.optionals enable32bits [ /* pkgsi686Linux.intel-media-driver */ driversi686Linux.vaapiIntel ]; # Note: intel-media-driver is disabled for i686 until https://github.com/NixOS/nixpkgs/issues/140471 is fixed
libvdpau = [ libvdpau-va-gl ] ++ lib.optionals enable32bits [ /* pkgsi686Linux.intel-media-driver */ driversi686Linux.vaapiIntel ];
++ lib.optional enable32bits pkgsi686Linux.libvdpau-va-gl; libvdpau = [ libvdpau-va-gl ]
glxindirect = runCommand "mesa_glxindirect" { } ('' ++ lib.optional enable32bits pkgsi686Linux.libvdpau-va-gl;
mkdir -p $out/lib glxindirect = runCommand "mesa_glxindirect" { } (
ln -s ${mesa.drivers}/lib/libGLX_mesa.so.0 $out/lib/libGLX_indirect.so.0 ''
''); mkdir -p $out/lib
in '' ln -s ${mesa.drivers}/lib/libGLX_mesa.so.0 $out/lib/libGLX_indirect.so.0
#!${runtimeShell} ''
export LIBGL_DRIVERS_PATH=${lib.makeSearchPathOutput "lib" "lib/dri" mesa-drivers} );
export LIBVA_DRIVERS_PATH=${lib.makeSearchPathOutput "out" "lib/dri" intel-driver} in
${''export __EGL_VENDOR_LIBRARY_FILENAMES=${mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json${ ''
lib.optionalString enable32bits #!${runtimeShell}
":${pkgsi686Linux.mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json" export LIBGL_DRIVERS_PATH=${lib.makeSearchPathOutput "lib" "lib/dri" mesa-drivers}
}"''${__EGL_VENDOR_LIBRARY_FILENAMES:+:$__EGL_VENDOR_LIBRARY_FILENAMES}"'' export LIBVA_DRIVERS_PATH=${lib.makeSearchPathOutput "out" "lib/dri" intel-driver}
} ${''export __EGL_VENDOR_LIBRARY_FILENAMES=${mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json${
export LD_LIBRARY_PATH=${lib.makeLibraryPath mesa-drivers}:${lib.makeSearchPathOutput "lib" "lib/vdpau" libvdpau}:${glxindirect}/lib:${lib.makeLibraryPath [libglvnd]}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" lib.optionalString enable32bits
exec "$@" ":${pkgsi686Linux.mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json"
''; }"''${__EGL_VENDOR_LIBRARY_FILENAMES:+:$__EGL_VENDOR_LIBRARY_FILENAMES}"''
}
export LD_LIBRARY_PATH=${lib.makeLibraryPath mesa-drivers}:${lib.makeSearchPathOutput "lib" "lib/vdpau" libvdpau}:${glxindirect}/lib:${lib.makeLibraryPath [libglvnd]}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec "$@"
'';
}; };
nixVulkanIntel = writeExecutable { nixVulkanIntel = writeExecutable {
name = "nixVulkanIntel"; name = "nixVulkanIntel";
text = let text =
# generate a file with the listing of all the icd files let
icd = runCommand "mesa_icd" { } ( # generate a file with the listing of all the icd files
# 64 bits icd icd = runCommand "mesa_icd" { } (
'' # 64 bits icd
ls ${mesa.drivers}/share/vulkan/icd.d/*.json > f ''
'' ls ${mesa.drivers}/share/vulkan/icd.d/*.json > f
# 32 bits ones ''
+ lib.optionalString enable32bits '' # 32 bits ones
ls ${pkgsi686Linux.mesa.drivers}/share/vulkan/icd.d/*.json >> f + lib.optionalString enable32bits ''
'' ls ${pkgsi686Linux.mesa.drivers}/share/vulkan/icd.d/*.json >> f
# concat everything as a one line string with ":" as seperator ''
+ ''cat f | xargs | sed "s/ /:/g" > $out''); # concat everything as a one line string with ":" as seperator
in '' + ''cat f | xargs | sed "s/ /:/g" > $out''
#!${runtimeShell} );
if [ -n "$LD_LIBRARY_PATH" ]; then in
echo "Warning, nixVulkanIntel overwriting existing LD_LIBRARY_PATH" 1>&2 ''
fi #!${runtimeShell}
export VK_LAYER_PATH=${vulkan-validation-layers}/share/vulkan/explicit_layer.d if [ -n "$LD_LIBRARY_PATH" ]; then
ICDS=$(cat ${icd}) echo "Warning, nixVulkanIntel overwriting existing LD_LIBRARY_PATH" 1>&2
export VK_ICD_FILENAMES=$ICDS"''${VK_ICD_FILENAMES:+:$VK_ICD_FILENAMES}" fi
export LD_LIBRARY_PATH=${ export VK_LAYER_PATH=${vulkan-validation-layers}/share/vulkan/explicit_layer.d
lib.makeLibraryPath [ ICDS=$(cat ${icd})
zlib export VK_ICD_FILENAMES=$ICDS"''${VK_ICD_FILENAMES:+:$VK_ICD_FILENAMES}"
libdrm export LD_LIBRARY_PATH=${
xorg.libX11 lib.makeLibraryPath [
xorg.libxcb zlib
xorg.libxshmfence libdrm
wayland xorg.libX11
gcc.cc xorg.libxcb
] xorg.libxshmfence
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" wayland
exec "$@" gcc.cc
''; ]
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec "$@"
'';
}; };
nixGLCommon = nixGL: nixGLCommon = nixGL:
@ -201,48 +230,57 @@ let
cp ${nixGL}/bin/* "$out/bin/nixGL"; cp ${nixGL}/bin/* "$out/bin/nixGL";
''; '';
auto = let auto =
_nvidiaVersionFile = if nvidiaVersionFile != null then let
nvidiaVersionFile _nvidiaVersionFile =
else if nvidiaVersionFile != null then
# HACK: Get the version from /proc. It turns out that /proc is mounted nvidiaVersionFile
# inside of the build sandbox and varies from machine to machine. else
# # HACK: Get the version from /proc. It turns out that /proc is mounted
# builtins.readFile is not able to read /proc files. See # inside of the build sandbox and varies from machine to machine.
# https://github.com/NixOS/nix/issues/3539. #
runCommand "impure-nvidia-version-file" { # builtins.readFile is not able to read /proc files. See
# To avoid sharing the build result over time or between machine, # https://github.com/NixOS/nix/issues/3539.
# Add an impure parameter to force the rebuild on each access. runCommand "impure-nvidia-version-file"
# time = builtins.currentTime; {
preferLocalBuild = true; # To avoid sharing the build result over time or between machine,
allowSubstitutes = false; # Add an impure parameter to force the rebuild on each access.
} "cp /proc/driver/nvidia/version $out 2> /dev/null || touch $out"; # time = builtins.currentTime;
preferLocalBuild = true;
allowSubstitutes = false;
} "cp /proc/driver/nvidia/version $out 2> /dev/null || touch $out";
# The nvidia version. Either fixed by the `nvidiaVersion` argument, or # The nvidia version. Either fixed by the `nvidiaVersion` argument, or
# auto-detected. Auto-detection is impure. # auto-detected. Auto-detection is impure.
nvidiaVersionAuto = if nvidiaVersion != null then nvidiaVersionAuto =
nvidiaVersion if nvidiaVersion != null then
else nvidiaVersion
# Get if from the nvidiaVersionFile else
let # Get if from the nvidiaVersionFile
data = builtins.readFile _nvidiaVersionFile; let
versionMatch = builtins.match ".*Module ([0-9.]+) .*" data; data = builtins.readFile _nvidiaVersionFile;
in if versionMatch != null then builtins.head versionMatch else null; versionMatch = builtins.match ".*Module ([0-9.]+) .*" data;
in
if versionMatch != null then builtins.head versionMatch else null;
autoNvidia = nvidiaPackages {version = nvidiaVersionAuto; }; autoNvidia = nvidiaPackages { version = nvidiaVersionAuto; };
in rec { in
# The output derivation contains nixGL which point either to rec {
# nixGLNvidia or nixGLIntel using an heuristic. # The output derivation contains nixGL which point either to
nixGLDefault = if nvidiaVersionAuto != null then # nixGLNvidia or nixGLIntel using an heuristic.
nixGLCommon autoNvidia.nixGLNvidia nixGLDefault =
else if nvidiaVersionAuto != null then
nixGLCommon nixGLIntel; nixGLCommon autoNvidia.nixGLNvidia
} // autoNvidia; else
nixGLCommon nixGLIntel;
} // autoNvidia;
}; };
in top // (if nvidiaVersion != null then in
top.nvidiaPackages { top // (if nvidiaVersion != null then
version = nvidiaVersion; top.nvidiaPackages
sha256 = nvidiaHash; {
} version = nvidiaVersion;
sha256 = nvidiaHash;
}
else else
{ }) { })

View File

@ -1,5 +1,6 @@
flake_input@{ kpcli-py, nixgl, rust-overlay, neovim-nightly-overlay, ... }: [ flake_input@{ kpcli-py, nixgl, rust-overlay, neovim-nightly-overlay, ... }: [
# TODO: this is quite harmful to add globally. nixGL is built not to be pure
nixgl.overlays.default nixgl.overlays.default
rust-overlay.overlays.default rust-overlay.overlays.default