From 335ce768c741737e91c3ce08e6dd2d3fcb7d0cd6 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Mon, 19 Feb 2018 16:23:11 +0100 Subject: [PATCH 1/2] Nvidia libs only - Avoid building (and fetching) linux kernel --- default.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/default.nix b/default.nix index 1608188..df8a238 100644 --- a/default.nix +++ b/default.nix @@ -7,8 +7,13 @@ let in with pkgs; rec { + nvidiaLibsOnly = linuxPackages.nvidia_x11.override { + libsOnly = true; + kernel = null; + }; + nixGLNvidiaBumblebee = runCommand "nixGLNvidiaBumblebee-${version}" { - buildInputs = [ libglvnd linuxPackages.nvidia_x11 bumblebee ]; + buildInputs = [ libglvnd nvidiaLibsOnly bumblebee ]; meta = with pkgs.stdenv.lib; { description = "A tool to launch OpenGL application on system other than NixOS - Nvidia bumblebee version"; @@ -18,7 +23,7 @@ rec { mkdir -p $out/bin cat > $out/bin/nixGLNvidiaBumblebee << FOO #!/usr/bin/env sh - export LD_LIBRARY_PATH=${linuxPackages.nvidia_x11}/lib + export LD_LIBRARY_PATH=${nvidiaLibsOnly}/lib ${bumblebee}/bin/optirun --ldpath ${libglvnd}/lib "\$@" FOO @@ -26,7 +31,7 @@ rec { ''; nixGLNvidia = runCommand "nixGLNvidia-${version}" { - buildInputs = [ libglvnd linuxPackages.nvidia_x11 ]; + buildInputs = [ libglvnd nvidiaLibsOnly ]; meta = with pkgs.stdenv.lib; { description = "A tool to launch OpenGL application on system other than NixOS - Nvidia version"; @@ -36,7 +41,7 @@ rec { mkdir -p $out/bin cat > $out/bin/nixGLNvidia << FOO #!/usr/bin/env sh - export LD_LIBRARY_PATH=${linuxPackages.nvidia_x11}/lib:${libglvnd}/lib + export LD_LIBRARY_PATH=${nvidiaLibsOnly}/lib:${libglvnd}/lib "\$@" FOO From 52149c57804a75326c99c36df56cf63601112d45 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Mon, 19 Feb 2018 16:30:03 +0100 Subject: [PATCH 2/2] Nvidia with version --- README.md | 64 +++++++++++++++++++++++++++++++++++------------------ default.nix | 14 +++++++++--- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index eb4eccd..db7afd9 100644 --- a/README.md +++ b/README.md @@ -28,21 +28,52 @@ Clone this git repository: ``` git clone https://github.com/guibou/nixGL -``` - -Build / install - -``` cd nixGL -nix-build -A XXX +``` + +## Optional (if NVIDIA) Grab your NVIDIA driver version + +Using `glxinfo` from your host system, grab the driver version, here `390.25`: + +``` +$ glxinfo | grep NVIDIA +... +OpenGL core profile version string: 4.5.0 NVIDIA 390.25 +... +``` + +## Build + +For intel: + +``` +nix-build -A nixGLIntel +``` + +For NVIDIA alone: + +``` +nix-build -A nixGLNvidia --argstr nvidiaVersion 390.25 +``` + +(replace `390.25` with the host driver version gathered earlier.) + +For Nvidia with bumblebee: + +``` +nix-build -A nixGLNvidiaBumblebee --argstr nvidiaVersion 390.25 +``` + +(replace `390.25` with the host driver version gathered earlier.) + +## Install + +``` nix-env -i ./result ``` -XXX can be one of: +(Note, you can iterate many time on this process to install as many driver as needed. Common example are `nixGLIntel` with `nixGLNvidiaBumblebee`) -- `nixGLNvidia`: Nvidia driver without bumblebee -- `nixGLNvidiaBumblebee`: Nvidia driver with bumblebee -- `nixGLIntel`: Intel driver # Usage @@ -61,15 +92,4 @@ OpenGL version string: 4.6.0 NVIDIA 390.25 # Limitations -The idea is really simple and should work reliably in most cases. It -can be easily extended to AMD drivers, I just don't have the hardware -to test. Contact me. - -*Important*: You need an host system driver which match the nixpkgs one. For example, at the time of this writing, nixpkgs contains nvidia `390.25`. Your host system must contain the same version. This limitation can be lifted by using a different version of nixpkgs: - -```shell -export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-14.12.tar.gz -nix-build -A nixGLNvidia -``` - -Contact me if this limitation is too important, it may be easy to automate this process. \ No newline at end of file +Does not work now for AMD drivers because I dont' have the hardware. diff --git a/default.nix b/default.nix index df8a238..4adba09 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,6 @@ -{ system ? builtins.currentSystem }: +{ system ? builtins.currentSystem, + nvidiaVersion ? null +}: let pkgs = import { inherit system; }; @@ -7,10 +9,16 @@ let in with pkgs; rec { - nvidiaLibsOnly = linuxPackages.nvidia_x11.override { + nvidiaLibsOnly = (linuxPackages.nvidia_x11.override { libsOnly = true; kernel = null; - }; + }).overrideAttrs(oldAttrs: rec { + name = "nvidia-${nvidiaVersion}"; + src = fetchurl { + url = "http://download.nvidia.com/XFree86/Linux-x86_64/${nvidiaVersion}/NVIDIA-Linux-x86_64-${nvidiaVersion}.run"; + sha256 = null; + }; + }); nixGLNvidiaBumblebee = runCommand "nixGLNvidiaBumblebee-${version}" { buildInputs = [ libglvnd nvidiaLibsOnly bumblebee ];