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:
let
isIntelX86Platform = system == "x86_64-linux";
nix_pkgs = import nixpkgs {inherit system;};
pkgs = import ./default.nix {
pkgs = nixpkgs.legacyPackages.${system};
pkgs = nix_pkgs;
enable32bits = isIntelX86Platform;
enableIntelX86Extensions = isIntelX86Platform;
};

View File

@ -1,22 +1,42 @@
{ # # Nvidia informations.
{
# # Nvidia informations.
# Version of the system kernel module. Let it to null to enable auto-detection.
nvidiaVersion ? null,
# Hash of the Nvidia driver .run file. null is fine, but fixing a value here
nvidiaVersion ? null
, # Hash of the Nvidia driver .run file. null is fine, but fixing a value here
# will be more reproducible and more efficient.
nvidiaHash ? null,
# Alternatively, you can pass a path that points to a nvidia version file
nvidiaHash ? null
, # Alternatively, you can pass a path that points to a nvidia version file
# and let nixGL extract the version from it. That file must be a copy of
# /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see
# https://github.com/NixOS/nix/issues/3539 ).
nvidiaVersionFile ? null,
# Enable 32 bits driver
nvidiaVersionFile ? null
, # Enable 32 bits driver
# This is one by default, you can switch it to off if you want to reduce a
# bit the size of nixGL closure.
enable32bits ? true
, writeTextFile, shellcheck, 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 }:
, writeTextFile
, shellcheck
, 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
writeExecutable = { name, text }:
@ -41,22 +61,24 @@ let
It contains the builder for different nvidia configuration, parametrized by
the version of the driver and sha256 sum of the driver installer file.
*/
nvidiaPackages = { version, sha256 ? null }: rec {
nvidiaPackages = { version }:
let
nvidiaDrivers = (linuxPackages.nvidia_x11.override { }).overrideAttrs
(oldAttrs: rec {
(oldAttrs: {
pname = "nvidia";
name = "nvidia-x11-${version}-nixGL";
inherit version;
src = let
src =
let
url =
"https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}.run";
in if sha256 != null then
fetchurl { inherit url sha256; }
else
builtins.fetchurl url;
in
fetchurl { inherit url sha256; };
useGLVND = true;
});
in
{
inherit nvidiaDrivers;
nvidiaLibsOnly = nvidiaDrivers.override {
libsOnly = true;
kernel = null;
@ -130,7 +152,8 @@ let
nixGLIntel = writeExecutable {
name = "nixGLIntel";
# add the 32 bits drivers if needed
text = let
text =
let
mesa-drivers = [ mesa.drivers ]
++ lib.optional enable32bits pkgsi686Linux.mesa.drivers;
intel-driver = [ intel-media-driver vaapiIntel ]
@ -138,11 +161,14 @@ let
++ lib.optionals enable32bits [ /* pkgsi686Linux.intel-media-driver */ driversi686Linux.vaapiIntel ];
libvdpau = [ libvdpau-va-gl ]
++ lib.optional enable32bits pkgsi686Linux.libvdpau-va-gl;
glxindirect = runCommand "mesa_glxindirect" { } (''
glxindirect = runCommand "mesa_glxindirect" { } (
''
mkdir -p $out/lib
ln -s ${mesa.drivers}/lib/libGLX_mesa.so.0 $out/lib/libGLX_indirect.so.0
'');
in ''
''
);
in
''
#!${runtimeShell}
export LIBGL_DRIVERS_PATH=${lib.makeSearchPathOutput "lib" "lib/dri" mesa-drivers}
export LIBVA_DRIVERS_PATH=${lib.makeSearchPathOutput "out" "lib/dri" intel-driver}
@ -158,7 +184,8 @@ let
nixVulkanIntel = writeExecutable {
name = "nixVulkanIntel";
text = let
text =
let
# generate a file with the listing of all the icd files
icd = runCommand "mesa_icd" { } (
# 64 bits icd
@ -170,8 +197,10 @@ let
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'');
in ''
+ ''cat f | xargs | sed "s/ /:/g" > $out''
);
in
''
#!${runtimeShell}
if [ -n "$LD_LIBRARY_PATH" ]; then
echo "Warning, nixVulkanIntel overwriting existing LD_LIBRARY_PATH" 1>&2
@ -201,8 +230,10 @@ let
cp ${nixGL}/bin/* "$out/bin/nixGL";
'';
auto = let
_nvidiaVersionFile = if nvidiaVersionFile != null then
auto =
let
_nvidiaVersionFile =
if nvidiaVersionFile != null then
nvidiaVersionFile
else
# HACK: Get the version from /proc. It turns out that /proc is mounted
@ -210,7 +241,8 @@ let
#
# builtins.readFile is not able to read /proc files. See
# https://github.com/NixOS/nix/issues/3539.
runCommand "impure-nvidia-version-file" {
runCommand "impure-nvidia-version-file"
{
# To avoid sharing the build result over time or between machine,
# Add an impure parameter to force the rebuild on each access.
# time = builtins.currentTime;
@ -220,27 +252,33 @@ let
# The nvidia version. Either fixed by the `nvidiaVersion` argument, or
# auto-detected. Auto-detection is impure.
nvidiaVersionAuto = if nvidiaVersion != null then
nvidiaVersionAuto =
if nvidiaVersion != null then
nvidiaVersion
else
# Get if from the nvidiaVersionFile
let
data = builtins.readFile _nvidiaVersionFile;
versionMatch = builtins.match ".*Module ([0-9.]+) .*" data;
in if versionMatch != null then builtins.head versionMatch else null;
in
if versionMatch != null then builtins.head versionMatch else null;
autoNvidia = nvidiaPackages { version = nvidiaVersionAuto; };
in rec {
in
rec {
# The output derivation contains nixGL which point either to
# nixGLNvidia or nixGLIntel using an heuristic.
nixGLDefault = if nvidiaVersionAuto != null then
nixGLDefault =
if nvidiaVersionAuto != null then
nixGLCommon autoNvidia.nixGLNvidia
else
nixGLCommon nixGLIntel;
} // autoNvidia;
};
in top // (if nvidiaVersion != null then
top.nvidiaPackages {
in
top // (if nvidiaVersion != null then
top.nvidiaPackages
{
version = nvidiaVersion;
sha256 = nvidiaHash;
}

View File

@ -1,5 +1,6 @@
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
rust-overlay.overlays.default