Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback: Nvidia Support #5

Open
soupglasses opened this issue Oct 2, 2024 · 13 comments
Open

Feedback: Nvidia Support #5

soupglasses opened this issue Oct 2, 2024 · 13 comments

Comments

@soupglasses
Copy link
Owner

No description provided.

@MaximilienNaveau
Copy link

MaximilienNaveau commented Oct 24, 2024

Dear @soupglasses,
I really do appreciate your support for graphical application in none NixOs setup.
I am on Ubuntu22.04 right now and I am trying to setup your system in addition to the home-manager.

I am very new to Nix so I tried to dig into the documentation but couldn't find a proper solution a couple of things.
But first I would like to suggest this line in your README:

# For Ubuntu users.
sudo env "PATH=$PATH" nix run 'github:numtide/system-manager' -- switch --flake '.'

When you want to activate the system manager it needs sudo rights and it's a mess because usually Nix is installed in the user space only. In any case that would be very helpful to add for users to avoid spending time on this small issue.

Here is my flake:
https://github.com/MaximilienNaveau/.my_dot_files/blob/main/flake.nix
See the commented part about NVIDIA? Here comes the actual questions:

  • When I uncomment this line, Nix asks me to allow unfree packages. It might be trivial for some Nix sage but unfortunately the things I try failed miserably 😓
    EDIT: -> answer is https://discourse.nixos.org/t/allow-unfree-in-flakes/29904
  • I am trying to infer from your example how I am supposed to pin the NVIDIA version but I am at loss here... If you had a clue I would extremely appreciate it.
EDIT: ->I tried this `system-graphics.package = pkgs.linuxKernel.packages.linux_libre.nvidia_x11_legacy535.override { libsOnly = true; kernel = null; };` But when I run "kitty" I got: ``` [0.091] [glfw error 65543]: GLX: Failed to create context: BadValue (integer parameter out of range for operation) [0.091] Failed to create GLFW temp window! This usually happens because of old/broken OpenGL drivers. kitty requires working OpenGL 3.1 drivers.```

Again you did a great job! It feels much less hacky than the NixGL tutorials I have seen so far.

Best

@soupglasses
Copy link
Owner Author

Hi there thanks for the feedback!

I'll get a more detailed response here later today for you. But if you are able to open up your Nvidia settings and check which version of the driver you have installed and report back. That'd be more than helpful.

@MaximilienNaveau
Copy link

Here is the snippet of the code I used:

{
  description = "Home Manager configuration for mnaveau";

  inputs = {
    nixpkgs = {
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    system-manager = {
      url = "github:numtide/system-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nix-system-graphics = {
      url = "github:soupglasses/nix-system-graphics";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, home-manager, system-manager, nix-system-graphics, ... }:
    let 
      system = "x86_64-linux";
      username = "mnaveau";
      # pkgs = nixpkgs.legacyPackages.${system};
      pkgs = import nixpkgs { system = "x86_64-linux"; config.allowUnfree = true; };
    in {
      defaultPackage.x86_64-linux = home-manager.defaultPackage.x86_64-linux;
      defaultPackage.x86_64-darwin = home-manager.defaultPackage.x86_64-darwin;

      systemConfigs.default = system-manager.lib.makeSystemConfig {
        modules = [
          nix-system-graphics.systemModules.default
          ({
            config = {
              nixpkgs.hostPlatform = "${system}";
              system-manager.allowAnyDistro = true;
              system-graphics.enable = true;
              # system-graphics.package = pkgs.linuxPackages.nvidia_x11.override { libsOnly = true; kernel = null; };
              system-graphics.package = pkgs.linuxKernel.packages.linux_libre.nvidia_x11_legacy535.override { libsOnly = true; kernel = null; };
            };
          })
        ];
      };

      homeConfigurations = {
        "${username}" = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [ ./home.nix ];
        };
      };
    };
}

Here the output of cat /proc/driver/nvidia/version:
NVRM version: NVIDIA UNIX x86_64 Kernel Module 535.183.01 Sun May 12 19:39:15 UTC 2024 GCC version: gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

@soupglasses
Copy link
Owner Author

Sorry for not getting back earlier, this should help you get it working:

You can either run home-manager switch to get the system-manager binary. Or run nix develop and it will create a temporary shell for you until you write exit where the binary will also be available in.

You can then check if it worked with the following command:

nix shell 'nixpkgs#mesa-demos' --command glxgears

If there is anything else, feel free to ask! 😄

{
  description = "Home Manager configuration for mnaveau";

  inputs = {
    nixpkgs = {
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    system-manager = {
      url = "github:numtide/system-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nix-system-graphics = {
      url = "github:soupglasses/nix-system-graphics";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, home-manager, system-manager, nix-system-graphics, ... }:
    let
      system = "x86_64-linux";
      username = "mnaveau";
      # pkgs = nixpkgs.legacyPackages.${system};
      pkgs = import nixpkgs { system = "x86_64-linux"; config.allowUnfree = true; };
    in {
      defaultPackage.x86_64-linux = home-manager.defaultPackage.x86_64-linux;
      defaultPackage.x86_64-darwin = home-manager.defaultPackage.x86_64-darwin;

      systemConfigs.default = system-manager.lib.makeSystemConfig {
        modules = [
          nix-system-graphics.systemModules.default
          ({
            config = {
              nixpkgs.hostPlatform = "${system}";
              system-manager.allowAnyDistro = true;
              system-graphics = let
                nvidia-drivers = pkgs.linuxPackages.nvidia_x11_legacy535.override {
                  libsOnly = true;
                  kernel = null;
                };
              in {
                enable = true;
                enable32Bit = true;
                package = nvidia-drivers;
                package32 = nvidia-drivers.lib32;
              };
            };
          })
        ];
      };

      devShells."${system}".default = pkgs.mkShellNoCC {
        packages = [
          system-manager.packages."${system}".default
        ];
      };

      homeConfigurations = {
        "${username}" = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [
            ./home.nix
            ({
              home.packages = [ system-manager.packages."${system}".default ];
            })
          ];
        };
      };
    };
}

@MaximilienNaveau
Copy link

Hi,
took into account your changes (my github is up to date https://github.com/MaximilienNaveau/.my_dot_files/blob/main/flake.nix)

But I got no luck running the glxgear nor kitty.

$ which glxgears
$HOME/.nix-profile/bin/glxgearswhich glxgears

$ glxgears
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  152 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  36
  Current serial number in output stream:  37
  
$ which kitty
/home/mnaveau/.nix-profile/bin/kitty

$ kitty
[0.236] [glfw error 65543]: GLX: Failed to create context: BadValue (integer parameter out of range for operation)
[0.236] Failed to create GLFW temp window! This usually happens because of old/broken OpenGL drivers. kitty requires working OpenGL 3.1 drivers.

If you have any clue or guideline I would be very interested.

@MaximilienNaveau
Copy link

MaximilienNaveau commented Oct 29, 2024

$ sudo env "PATH=$PATH" system-manager switch --flake .
success
$ ls -lha /run/opengl-driver/ /run/opengl-driver-32/
/run/opengl-driver/:
total 1.9M
dr-xr-xr-x    2 root root   4.0K Jan  1  1970 ./
drwxrwxr-t 2985 root nixbld 1.9M Oct 29 09:42 ../
lrwxrwxrwx    2 root root     69 Jan  1  1970 bin -> /nix/store/yfs50l79acfmq5brcqpymiks3z1pnr7h-nvidia-x11-535.154.05/bin/
lrwxrwxrwx    2 root root     69 Jan  1  1970 etc -> /nix/store/yfs50l79acfmq5brcqpymiks3z1pnr7h-nvidia-x11-535.154.05/etc/
lrwxrwxrwx    2 root root     69 Jan  1  1970 lib -> /nix/store/yfs50l79acfmq5brcqpymiks3z1pnr7h-nvidia-x11-535.154.05/lib/
lrwxrwxrwx    2 root root     71 Jan  1  1970 share -> /nix/store/yfs50l79acfmq5brcqpymiks3z1pnr7h-nvidia-x11-535.154.05/share/

/run/opengl-driver-32/:
total 1.9M
dr-xr-xr-x    2 root root   4.0K Jan  1  1970 ./
drwxrwxr-t 2985 root nixbld 1.9M Oct 29 09:42 ../
lrwxrwxrwx    2 root root     75 Jan  1  1970 etc -> /nix/store/6jrk9nqd645rymlgn3ybmakj782afj2g-nvidia-x11-535.154.05-lib32/etc/
lrwxrwxrwx    2 root root     75 Jan  1  1970 lib -> /nix/store/6jrk9nqd645rymlgn3ybmakj782afj2g-nvidia-x11-535.154.05-lib32/lib/
lrwxrwxrwx    2 root root     77 Jan  1  1970 share -> /nix/store/6jrk9nqd645rymlgn3ybmakj782afj2g-nvidia-x11-535.154.05-lib32/share/

Still no luck after after the switch command

when I run

$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module  535.183.01  Sun May 12 19:39:15 UTC 2024
GCC version:  gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

I believe the version of nvidia are slightly different. Could that be the issue?

@soupglasses
Copy link
Owner Author

soupglasses commented Oct 29, 2024

I'd be surprised. But you can try to generate it manually. Put it where your previous definition of nvidia-drivers are.

nvidia-drivers = (pkgs.linuxPackages.nvidiaPackages.mkDriver {
    version = "535.183.01";
    sha256_64bit = "sha256-9nB6+92pQH48vC5RKOYLy82/AvrimVjHL6+11AXouIM=";
    sha256_aarch64 = "";
    openSha256 = "";
    settingsSha256 = "";
    persistencedSha256 = "";
    patches = pkgs.linuxPackages.nvidiaPackages.legacy_535.patches;
}).override { libsOnly = true; kernel = null; };

@soupglasses
Copy link
Owner Author

Updated the comment a bit to also include the patches for 535. Unsure if its needed when we just build the libs, but i added them to be sure.

@soupglasses
Copy link
Owner Author

Also please run nix shell 'nixpkgs#mesa-demos' --command glxgears in a terminal window installed by your distribution specifically instead of relying upon your nix-profile one.

Also try to reboot if the above doesnt work either.

Repository owner deleted a comment from steinwurf-sofie Oct 29, 2024
@MaximilienNaveau
Copy link

It seems that the installation of the exact version and patches are needed in order for things to work...
Now I can run glxgears and kitty without issues. A lot of thanks for the support and kindness in the answer!

I designed this simple update scripts in order to make things easier for me:

home-manager switch --flake .
sudo env "PATH=$PATH" system-manager switch --flake .

Seems that now I can run graphical software from the nixpkgs.

@RafaelKr
Copy link

RafaelKr commented Nov 5, 2024

I'd be surprised. But you can try to generate it manually. Put it where your previous definition of nvidia-drivers are.

I'm using Linux Mint 22 (Ubuntu based) with Nvidia Driver 550.120 and kernel 6.8.0-48 on my Lenovo Legion Slim 5 16AHP9 with an RTX 4070 card.

I can confirm that it only works when I use the exact same driver version which is installed on system level.

$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module  550.120  Fri Sep 13 10:10:01 UTC 2024
GCC version:  gcc version 13.2.0 (Ubuntu 13.2.0-23ubuntu4)
nvidia-drivers =
  (pkgs.linuxPackages.nvidiaPackages.mkDriver {
    # use same version as OS version from /proc/driver/nvidia/version
    version = "550.120";
    sha256_64bit = "sha256-gBkoJ0dTzM52JwmOoHjMNwcN2uBN46oIRZHAX8cDVpc=";
    sha256_aarch64 = "";
    openSha256 = "";
    settingsSha256 = "";
    persistencedSha256 = "";
    patches = pkgs.linuxPackages.nvidiaPackages.production.patches;
  }).override
    {
      libsOnly = true;
      kernel = null;
    };

If I use any other version (v550.78 from nixpkgs/nixos-24.05 or v550.127.05 from nixpkgs/unstable) I get the BadValue (integer parameter out of range for operation) error when running glxgears or kitty.

# results in error "BadValue (integer parameter out of range for operation)" when running glxgears
nvidia-drivers = pkgs.linuxPackages.nvidia_x11_production.override {
  libsOnly = true;
  kernel = null;
};

@soupglasses
Copy link
Owner Author

Huh. Very interesting. I wonder how this works when the open kernel driver is used. Maybe its not so tied to versions like this. But this might just be a genuine limitation for nvidia drivers.

@liarokapisv
Copy link

liarokapisv commented Feb 9, 2025

I'd be surprised. But you can try to generate it manually. Put it where your previous definition of nvidia-drivers are.

nvidia-drivers = (pkgs.linuxPackages.nvidiaPackages.mkDriver {
version = "535.183.01";
sha256_64bit = "sha256-9nB6+92pQH48vC5RKOYLy82/AvrimVjHL6+11AXouIM=";
sha256_aarch64 = "";
openSha256 = "";
settingsSha256 = "";
persistencedSha256 = "";
patches = pkgs.linuxPackages.nvidiaPackages.legacy_535.patches;
}).override { libsOnly = true; kernel = null; };

This has stopped working for me on a new laptop install.
It seems I get a "Couldn't get an RGB, Double-buffered visual" error when running anything from mesa-utils.

/proc/driver/nvidia/version is 535.183.01.
The /run/opengl-driver seems to be populated with the nvidia-x11-535.183.01 package contents.
Any ideas?

As a sidenote, curiously, cat-ing the version file does not show any GCC version.

EDIT: It seems they couldn't find the mesa lib paths, I had to add pkgs.mesa.drivers to extraPackages. May be relevant to #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants