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

feature request: nixGL integration #3968

Closed
michaelCTS opened this issue May 8, 2023 · 42 comments · Fixed by #5355
Closed

feature request: nixGL integration #3968

michaelCTS opened this issue May 8, 2023 · 42 comments · Fixed by #5355
Assignees

Comments

@michaelCTS
Copy link

Description

NixOS/nixpkgs#9415 which tracks the problem of libGL in nix on non NixOS systems has been open for about 8 years now. Luckily, nixGL exists which provides a wrapper around programs that require openGL (games, gpu accelerated terminals, browsers, etc.).

It would be great if there were an option to wrap all GUI applications or user-specified applications with nixGL. I'm assuming there's a generic way and bepoke method per application. Care should be taken for the desktop entries to call with nixGL

workarounds.opengl.packages

Is given a list of package names (or maybe packages themselves) that it has to wrap

lib.wrapWithLibGL

It could be a wrapper that takes a package and spits out another which is called by libGL.

@Smona
Copy link
Contributor

Smona commented Jun 19, 2023

I posted an implementation I've been using to wrap programs with nixGL, which i think could be general enough to be provided as a utility on lib, and wouldn't add a hard nixGL dependency to home manager. With a little more work (to null out the buildInputs on the wrapper derivation), it could be completely transparent, and it still allows home manager to further override packages like firefox and emacs. Hopefully that can provide some inspiration?

@teto
Copy link
Collaborator

teto commented Jun 21, 2023

a good first step would be to have nixGL in nixpkgs

@stale
Copy link

stale bot commented Sep 21, 2023

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@stale stale bot added the status: stale label Sep 21, 2023
@viraptor
Copy link

hold on a moment stale-bot!

@stale stale bot removed the status: stale label Sep 21, 2023
@izelnakri
Copy link

izelnakri commented Oct 5, 2023

I've accomplished the (nixGL packageName) behavior after utilizing the hacks of @Smona @robhanlon22 here after researching this issue & trials for about a week. Seems absolutely necessary to have this feature as a lib.nixGL function @rycee for non-nixOS systems.

@michaelCTS
Copy link
Author

Can you create a PR @izelnakri ?

@rycee
Copy link
Member

rycee commented Oct 7, 2023

Maybe something that would be good to have under the targets.genericLinux namespace?

Copy link

stale bot commented Jan 5, 2024

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@stale stale bot added the status: stale label Jan 5, 2024
@viraptor
Copy link

viraptor commented Jan 6, 2024

This still needs solving.

@stale stale bot removed the status: stale label Jan 6, 2024
@diegodorado
Copy link

would love to see this implemented in home manager itself

Copy link

stale bot commented Apr 23, 2024

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@michaelCTS
Copy link
Author

Still a valid issue

@michaelCTS
Copy link
Author

For those following, I created a PR. You can test it by amending your home.nix

{ config, pkgs, ...}:
let
  michaelCtsHm = builtins.fetchTarball "https://github.com/michaelCTS/home-manager/archive/refs/heads/feat/add-nixgl-workaround.zip";
  nixGlModule = "${michaelCtsHm}/modules/misc/nixgl.nix";
in
{
  imports = [ nixGlModule ];
  workarounds.nixgl.packages = with pkgs; [
    # A package of your choice here. alacritty is just an example
    { pkg = alacritty; }
  ];
}

See the the nixgl module source (either in the nix store or the PR itself) for the objects to pass to workaround.nixgl.packages.

With that, you should be able to open the package in your desktop environment. I tested it in openbox, but it should work with KDE, Gnome and others as well.

@joefiorini
Copy link

@michaelCTS just tried this and ran into an issue. If I have programs.kitty.enable = true then I get a collision since it's trying to add the binary from both the main kitty package and the wrapped one. But if I don't use the enable flag then I don't get home-manager's configuration abilities, right? Is it possible to have this be part of the program configuration (like programs.kitty.enableNixgl = true or something?)

@Smona Smona mentioned this issue Apr 30, 2024
6 tasks
@Smona
Copy link
Contributor

Smona commented Apr 30, 2024

@michaelCTS thank you for creating that PR! you've inspired me to finally put together my own utilizing the wrapper I posted near the top of this issue. I hope there are no hard feelings for waiting until you posted yours 😅 I am not immune to Cunningham's Law, but ultimately I hope the implementation that gets merged is the one that works best for everyone.

@joefiorini if you want you can give #5355 a try. All you should need to do is set the nixGL.prefix option, since I've integrated kitty by default in the PR.

@michaelCTS
Copy link
Author

@Smona I don't mind. It'll be up to the maintainers to decide which solution they prefer. It's just about time this issue is resolved. Whichever solution is chosen doesn't matter to me. It can always be iterated upon later and IMO there shouldn't be a focus on perfection, otherwise people will keep talking and never do anything.

I modified my PR to make the wrapper available as well. We have different approaches of wrapping the package, so I think that will be the major difference. The one you use from stackoverflow does double the disk-space usage of the package IINM whereas what I used from the nixos wiki simply links to the existing package and writes one new bin.

@Smona
Copy link
Contributor

Smona commented May 1, 2024

@michaelCTS (see edit below) great point about disk usage. I had misremembered it using symlinks, but that's certainly a downside.

I only have strong opinions about the API for HM users (which is harder to iterate on), not the specific wrapper used. I originally tried using runCommand/makeWrapper, but I found that the result could not be integrated with HM modules because it did not include attributes from the original derivation. If your wrapper accomplishes that, such that wrapped packages can be used just like the original derivation, then it's certainly the better candidate 🙌. If not, I think the approach in my PR could be made to work with symlinks (it's unlikely I'll have time to do that myself).

Feel free to rip any other ideas from that PR, glad it could be of some help! In particular, I think these ideas are worth consideration:

  • Not adding packages to home.packages via a package list settings, but instead letting users pass wrapped packages into home.packages or program modules themselves. This way package specifications are not duplicated.
  • Wrapping all binary outputs for wrapped derivations, since there is a decent chance a package which needs GPU for one binary may need it for other binaries. This would also simplify the interface of lib.nixGl.wrap. There doesn't seem to be any way in your current PR to wrap multiple binaries in a single package.
  • Making the wrapper return the original derivation (no-op) if targets.genericLinux.nixgl.src is not set. This would allow modules to wrap their packages by default (but this one will be easy to iterate on later)

Thanks again for pushing this forward!

EDIT: I looked into it again and the wrapper in my PR does actually symlink the non-bin outputs, because -s is passed to cp, which makes it use symlinks. From man cp:

       -s, --symbolic-link
              make symbolic links instead of copying

So there is no disk usage downside to that wrapper.

@michaelCTS
Copy link
Author

Your right @Smona! I didn't see the -s. Maybe using ln -s would be better as a -s can be easily missed but ln is very commonly used for linking.

I'll close my PR in favor of yours. You'll probably be a more active maintainer. Hopefully it can be merged quickly.

Cheers

@Smona
Copy link
Contributor

Smona commented May 6, 2024

@michaelCTS I agree that ln -s would be clearer, since even I got a bit turned around by the cp -rs call! I think I remember the cp -rs being important for some reason, either resetting the mode with --no-preserve mode and/or because it links differently: rather than creating links to the top-level directory like ln -s does, it actually creates the directory tree in the destination, and individually softlinks each file (which actually does introduce a very small disk usage disadvantage due to the increased number of inodes). I wish I had left a comment, because it could be totally unnecessary and just a copy/paste that I assumed to be useful.

In the interest of getting the initial implementation merged I might hold off on further refactoring on that branch if the current strategy looks good to maintainers, but changing the linking strategy is absolutely something we can iterate on in the future without breaking changes :)

@giggio
Copy link

giggio commented May 28, 2024

For anyone who wants to test #5355, I couldn't find an extensive way to do this, and I wanted to use Kitty, so this is what I did. I am using home-manager with flakes. I am new to all of this, so it might be obvious to many of the ones reading this, but it was not obvious to me. You can see the working sample at my dotfiles repo:
https://github.com/giggio/dotfiles/blob/main/config/home-manager/home.nix
https://github.com/giggio/dotfiles/blob/main/config/home-manager/flake.nix
And this is is the commit with the diffs:
giggio/dotfiles@c5e6901

I added NixGL to my input on flake.nix:

    nixGL = {
      url = "github:nix-community/nixGL/310f8e49a149e4c9ea52f1adf70cdc768ec53f8a";
      inputs.nixpkgs.follows = "nixpkgs";
    };

In home.nix:

I added @Smona's patch to my imports:

  imports = [
    (builtins.fetchurl {
      url = "https://raw.githubusercontent.com/Smona/home-manager/nixgl-compat/modules/misc/nixgl.nix";
      sha256 = "74f9fb98f22581eaca2e3c518a0a3d6198249fb1490ab4a08f33ec47827e85db";
    })
  ];

I added an alias for nixGL, like so:

let
  nixGLIntel = inputs.nixGL.packages."${pkgs.system}".nixGLIntel;
#...

I installed it by adding nixGLIntel to packages. And, in packages, kitty was changed to (config.lib.nixGL.wrap kitty).

And I added the option:

  nixGL.prefix = "${nixGLIntel}/bin/nixGLIntel";

This changed my kitty executable, which now looks like so:

$ cat `which kitty`
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
exec -a "$0" /nix/store/vbhv6ijhy65ma7z8i67dkci7ddiwzvrf-nixGLIntel/bin/nixGLIntel /nix/store/cmkk0l1qs0hph06nlp0ji1arkpxp44xs-kitty-0.34.1/bin/kitty "$@"

I hope this helps someone.

@Smona I hope your PR is merged soon so I can remove the customizations. Thanks for that!

@o-dasher
Copy link

@giggio thank you so much for this little tutorial, everything works as expected!

@timoleistner
Copy link

timoleistner commented Jul 17, 2024

Somehow @giggio's approach gives me this error

error: hash mismatch in file downloaded from 'https://raw.githubusercontent.com/Smona/home-manager/nixgl-compat/modules/misc/nixgl.nix':
         specified: sha256:1nw5gs14gv1kiyhb82j9n6gj96317l58ll9w5v5fm095yacgpybl
         got:       sha256:0g5yk54766vrmxz26l3j9qnkjifjis3z2izgpsfnczhw243dmxz9

any ideas?

Edit: Alright fixed it by obtaining the new sha256 sum by doing curl https://raw.githubusercontent.com/Smona/home-manager/nixgl-compat/modules/misc/nixgl.nix | sha256sum

(its e9f7da06111c7e669dbeef47f1878ed245392d4e7250237eaf791b734899be3c)

Now I get :

error: attribute 'currentTime' missing
       at /nix/store/wnf3rly6jbw4ywqhzgn0vl6lk8hwgkg3-source/nixGL.nix:223:18:
          222|           # Add an impure parameter to force the rebuild on each access.
          223|           time = builtins.currentTime;
             |                  ^
          224|           preferLocalBuild = true;

Ok thats what I get for trying something different and trying nixGLDefault works with nixGLIntel.

Edit 2: Now I have the same problem @joefiorini mentioned with having colliding packages when wayland.windowManager.hyprland.enable = true I have colliding packages. If setting this option to false the config for this package is not used.

Edit 3:
Everything works now when adding the wrapped hyprland to wayland.windowManager.hyprland.package, instead of including it in home.packages. Thanks to @Smona.

@diegoroccia
Copy link

Thank you all for the great work! I have been following the various threads, patches and so on, but now I am a bit lost how to get rid of those since, as far as I read, home-manager supports nixGL natively. Where can I find a doc page with up to date info?

@exzombie
Copy link
Contributor

As always, you can run the home-manager-help command to open the manual for the version of HM that you are currently using. The latest docs are also available online. Don't forget to take a look at the docs for individual configuration options as well 😄

@moritayasuaki
Copy link

moritayasuaki commented Nov 4, 2024

@Smona @giggio Hi, I have always used @Smona 's nixgl.nix in my home-manager/home.nix, and now the nixgl wrapper is merged into home-manager, great!
But now I have trouble with making it work in a new way because I've gotten too used to @giggio 's solution (if anyone has the same situation please let me know). Do you have any suggestions?
Here are excerpts from my home.nix and flake.nix:

home-manager/flake.nix

{
  description = "Home Manager configuration of yasuaki";

  inputs = {
    # Specify the source of Home Manager and Nixpkgs.
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    nixGL.url = "github:guibou/nixGL";
  };

  outputs = { nixpkgs, home-manager, nixGL, ...}: let
    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;
      overlays = [
        nixGL.overlay
      ];
      config.allowUnfree = true;
      config.permittedInsecurePackages = [
      ];
    };
  in
  {
    homeConfigurations."yasuaki" = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
      # Specify your home configuration modules here, for example,
      # the path to your home.nix.
      modules = [
        ./home.nix
        ({ ... }: {
          nixGL.prefix = "${pkgs.lib.getExe pkgs.nixgl.nixGLIntel}";
        })
      ];
    };
  };
}

home-manager/home.nix

{ config, pkgs, lib, ... }:
{
  imports = [
    (builtins.fetchurl {
      url = "https://raw.githubusercontent.com/Smona/home-manager/nixgl-compat/modules/misc/nixgl.nix";
      sha256 = "01dkfr9wq3ib5hlyq9zq662mp0jl42fw3f6gd2qgdf8l8ia78j7i";
    })
  ];

  # Home Manager needs a bit of information about you and the paths it should
  # manage.
  home.username = "yasuaki";
  home.homeDirectory = "/home/yasuaki";

  # This value determines the Home Manager release that your configuration is
  # compatible with. This helps avoid breakage when a new Home Manager release
  # introduces backwards incompatible changes.
  #
  # You should not change this value, even if you update Home Manager. If you do
  # want to update the value, then make sure to first check the Home Manager
  # release notes.
  home.stateVersion = "23.05"; # Please read the comment before changing.

  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages =
    let
      cui-apps = (with pkgs; [
        fd
        ripgrep
        elan
      ]);
      cui-apps-stable = (with pkgs; [
      ]);
      gui-apps = (with pkgs; [
        evince
        bitwarden
      ]);
    in
    cui-apps ++
    lib.lists.forEach gui-apps config.lib.nixGL.wrap;
}

@moritayasuaki
Copy link

It’s now working property. I just needed to name the flake input nixgl by using "github:nix-community/nixGL" in flake.nix and pass it to Home Manager via extraSpecialArgs (which is written in the description). I think it would be helpful to add an example of flake.nix in the description. For newbies, it's a bit difficult to identify what nixgl is, and to understand the role of nixGL in Home Manager versus nixgl from the "github:nix-community/nixGL" flake.

The above example assumes a flake-based setup where nixgl was passed from the flake.

I put a shortened version of my flake.nix

{
  description = "Home Manager configuration of yasuaki";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    nixgl.url = "github:nix-community/nixGL";
    nixgl.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, home-manager, nixgl, ...}: let
    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
    };
  in
  {
    homeConfigurations."yasuaki" = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
      modules = [
        ./home.nix
      ];
      extraSpecialArgs = {
        inherit nixgl;
      };
    };
  };
}

@luiseduardobatista
Copy link

I'm trying to use this implementation but im getting the following error, anyone know why? I'm using Pop!_OS 22.04

error:
       … while evaluating a branch condition
         at /nix/store/ly4s3hw35dd1c2vsd694y2715pc1d2c1-source/lib/lists.nix:125:9:
          124|       fold' = n:
          125|         if n == len
             |         ^
          126|         then nul

       … while calling the 'length' builtin
         at /nix/store/ly4s3hw35dd1c2vsd694y2715pc1d2c1-source/lib/lists.nix:123:13:
          122|     let
          123|       len = length list;
             |             ^
          124|       fold' = n:

       … while evaluating the error message for definitions for `nixGL', which is an option that does not exist

       … while evaluating a definition from `<unknown-file>'

while evaluating an attribute `packages`

while evaluating an attribute `aarch64-darwin`

while evaluating an attribute `default`

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: a 'aarch64-darwin' with features {} is required to build '/nix/store/z634b6kr64a0d7k9gxlhnmcmbd36gfzb-impure-nvidia-version-file.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}

flake.nix:

{
  description = "My flake config";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
    nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
    home-manager.url = "github:nix-community/home-manager/release-24.05";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    nixGL = {
      url = "github:nix-community/nixGL";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    self,
    nixpkgs,
    nixpkgs-unstable,
    home-manager,
    nixGL,
    ...
  } @ inputs: let
    inherit (self) outputs;
    hostname = "nixos";
    system = "x86_64-linux";
    pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
    };
  in {
    nixosConfigurations = {
      ${hostname} = nixpkgs.lib.nixosSystem {
        specialArgs = {inherit inputs outputs;};
        modules = [./nixos/configuration.nix];
      };
    };

    homeConfigurations = {
      "luisb" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = {
          inherit inputs;
          inherit outputs;
          isNixOS = false;
          inherit pkgs-unstable;
          inherit nixGL;
        };
        modules = [
          ./home-manager/home.nix
        ];
      };
    };
  };
}

home.nix:

{
  inputs,
  lib,
  config,
  pkgs,
  nixGL,
  ixNixOS,
  ...
}:
{
  targets.genericLinux.enable = true;
  
  nixGL.packages = nixGL.packages;

  imports = [
    ./zsh.nix
    ./neovim.nix
    ./devtools.nix
    ./programming-languages.nix
    # ./gnome/gnome.nix
    ./gnome/pop-os.nix
    ./utils.nix
    ./git.nix
    ./ssh.nix
    ./cli.nix
    ./fonts.nix
  ];

  home = {
    username = "luisb";
    homeDirectory = "/home/luisb";
    sessionVariables = {
      EDITOR = "nvim";
      BROWSER = "firefox";
      TERMINAL = "wezterm";
    };
  };

  programs.home-manager.enable = true;
  programs.git.enable = true;
  programs.zsh.enable = true;
  home.stateVersion = "23.05";
}

@exzombie
Copy link
Contributor

@luiseduardobatista As the error message says:

while evaluating the error message for definitions for `nixGL', which is an option that does not exist

You are still on HM 24.05, which does not yet have this. You need 24.11.

@luiseduardobatista
Copy link

@exzombie It worked, thanks for the help

@vuthanhtung2412
Copy link

vuthanhtung2412 commented Dec 3, 2024

programs.kitty = {
  enable = true;
  package = (config.lib.nixGL.wrap pkgs.kitty);
};

is this the correct way to wrap program ? I still have this error when run kitty

 ~#@❯ kitty
[0.103] [glfw error 65542]: GLX: No GLXFBConfigs returned
[0.103] [glfw error 65545]: GLX: Failed to find a suitable GLXFBConfig
[0.103] Failed to create GLFW temp window! This usually happens because of old/broken OpenGL drivers. kitty requires working OpenGL 3.1 drivers.

nixGL kitty still works though. I am running the below setup on Ubuntu 22.04

# flake.nix
{
  description = "Home Manager configuration of thanhtung";

  inputs = {
    # Specify the source of Home Manager and Nixpkgs.
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
    catppuccin.url = "github:catppuccin/nix";
    home-manager = {
      url = "github:nix-community/home-manager/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixGL = {
      url = "github:nix-community/nixGL";
    };
  };

  outputs = { nixpkgs, catppuccin, home-manager, nixGL, ... }:
  let
    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
    };
  in {
    homeConfigurations."tung" = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
   
      extraSpecialArgs = {
          inherit nixGL;
      };
      # Specify your home configuration modules here, for example,
      # the path to your home.nix.
      modules = [ 
        ./home.nix 
        catppuccin.homeManagerModules.catppuccin
      ];

      # Optionally use extraSpecialArgs
      # to pass through arguments to home.nix
    };
  };
}
# home.nix
{ config, pkgs, nixGL,... }:

{
  home.username = "tung"; 
  home.homeDirectory = "/home/tung";

  home.stateVersion = "24.11"; 

  nixGL.packages = nixGL.packages;
  nixGL.defaultWrapper = "nvidia";
  nixpkgs = {
    config = {
      allowUnfree = true;
      allowUnfreePredicate = (pkg: true);
    };
  };
  programs.kitty = {
    enable = true;
    package = (config.lib.nixGL.wrap pkgs.kitty);
  };
  ...
}

@Smona
Copy link
Contributor

Smona commented Dec 3, 2024

@vuthanhtung2412 it looks like your OS has a version of OpenGL that's too old for the version of kitty you're trying to use. You can check this with glxinfo | grep "OpenGL version"

You could try adding a backwards-compat nixpkgs input (e.g. 24.05) and using that just for kitty, or updating opengl / ubuntu to a compatible version.

@vuthanhtung2412
Copy link

vuthanhtung2412 commented Dec 3, 2024

@Smona Thank you a lot for looking into this for me. I tried what you have suggest but it didn't work
I have installed OpenGL with. I installed it with apt since i couldn't found any on https://search.nixos.org/packages

sudo apt-get install freeglut3-dev  
 ~#@❯ glxinfo | grep "OpenGL version"
OpenGL version string: 4.6 (Compatibility Profile) Mesa 23.2.1-1ubuntu3.1~22.04.2

I have also modified my flake.nix and home.nix like below

# flake.nix
{
  description = "Home Manager configuration of thanhtung";

  inputs = {
    # Specify the source of Home Manager and Nixpkgs.
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
    nixpkgs2405.url = "github:nixos/nixpkgs/nixos-24.05";
    catppuccin.url = "github:catppuccin/nix";
    home-manager = {
      url = "github:nix-community/home-manager/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixGL = {
      url = "github:nix-community/nixGL";
    };
  };

  outputs = { nixpkgs, catppuccin, home-manager, nixGL, ... }:
  let
    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
    };
    pkgs2405 = import nixpkgs2405 {
      inherit system;
      config.allowUnfree = true;
    };
  in {
    homeConfigurations."tung" = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
   
      extraSpecialArgs = {
          inherit nixGL;
          inherit pkgs2405;
      };
      # Specify your home configuration modules here, for example,
      # the path to your home.nix.
      modules = [ 
        ./home.nix 
        catppuccin.homeManagerModules.catppuccin
      ];

      # Optionally use extraSpecialArgs
      # to pass through arguments to home.nix
    };
  };
}
# home.nix
{ config, pkgs, nixGL, pkgs2405, ... }:

{
  home.username = "tung"; 
  home.homeDirectory = "/home/tung";

  home.stateVersion = "24.11"; 

  nixGL.packages = nixGL.packages;
  nixGL.defaultWrapper = "nvidia";
  nixpkgs = {
    config = {
      allowUnfree = true;
      allowUnfreePredicate = (pkg: true);
    };
  };
  programs.kitty = {
    enable = true;
    package = (config.lib.nixGL.wrap pkgs2405.kitty);
  };
  ...
}

Some more information that you might find it helpful

  • I had a setup that works before in 24.05 with this patch from you 💯 and I didn't have to install openGL lib
  • All other GPU accelerated programs fails too (blender, obs, warp-terminal)

@level323
Copy link

level323 commented Dec 4, 2024

I've been coding for more than 20 years, but have only recently found Nix and even more recently started having a crack at home-manager. So I regard myself as a nix and home-manager n00b and consequently am far too shy to suggest updates to the official HM documentation to provide more detailed examples of how using the new built-in NixGL wrapping features of HM.

Up until yesterday I was happily using @Smona 's excellent NixGL wrapping technique with my HM configuration. But I have since taken the leap and switched to the built-in NixGL wrapping features of HM. I did a lot of searching to see if I could find other people posting examples of HM configs claimed to be working with the new built-in NixGL wrapping technique, but couldn't find any.

But somehow I managed to get it working. For reasons I explained earlier, I don't feel I have a strong enough grasp of flakes and HM to suggest improvements to official docs or add official examples, but I thought it might be helpful to others if I posted my flake.nix and home.nix here to give others clues/guidance/hints.

Note: If any of you nix/flake/home-manager experts notice any stupid/wrong/inefficient/redundant content in these files, I apologise in advance. Any advice greatly appreciated. But it does work for me!

Here you go. Some irrelevant lines have been removed for brevity. As you can see it's still a work-in-progress (e.g. I don't use HM for configuration management yet, just for installing packages). And, of course, you'll need to change myusername to your actual user name.

flake.nix

# Note: Based on the work of
#    https://github.com/giggio/dotfiles/tree/main/home-manager
#    ...and various other sources
#    
{
  description = "Home Manager configuration for myusername on non-NixOS Linux";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/release-24.11";
    home-manager = {
      url = "github:nix-community/home-manager/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixgl = {
      url = "github:nix-community/nixGL";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { 
    self, 
    nixpkgs, 
    home-manager, 
    nixgl, 
    ... 
  } @ inputs: let
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
    mkHomeManagerConfiguration = { extraSpecialArgs, ... }: home-manager.lib.homeManagerConfiguration ({
      inherit pkgs;

      modules = [ ./home.nix ];

      extraSpecialArgs = {
        inherit inputs;
        inherit nixgl;
      } // extraSpecialArgs;
    });
  in
  {
    formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
    homeConfigurations =
      let
        setup = {
          wsl = false;
          basicSetup = false;
          isNixOS = false;
          isVirtualBox = false;
        };
      in
      {
        # available profiles: myusername, myusername_wsl, myusername_virtualbox_nixos, myusername_nixos, myusername_basic, myusername_wsl_basic, myusername_virtualbox_basic, myusername_virtualbox_nixos_basic, myusername_nixos_basic
        myusername = mkHomeManagerConfiguration {
          extraSpecialArgs = { inherit setup; };
        };
        myusername_wsl = mkHomeManagerConfiguration {
          extraSpecialArgs = {
            setup = setup // { wsl = true; };
          };
        };
        myusername_virtualbox_nixos = mkHomeManagerConfiguration {
          extraSpecialArgs = {
            setup = setup // { isVirtualBox = true; isNixOS = true; };
          };
        };
        myusername_nixos = mkHomeManagerConfiguration {
          extraSpecialArgs = {
            setup = setup // { isNixOS = true; };
          };
        };
        myusername_basic = mkHomeManagerConfiguration {
          extraSpecialArgs = {
            setup = setup // { basicSetup = true; };
          };
        };
        myusername_wsl_basic = mkHomeManagerConfiguration {
          extraSpecialArgs = {
            setup = setup // { wsl = true; basicSetup = true; };
          };
        };
        myusername_virtualbox_basic = mkHomeManagerConfiguration {
          extraSpecialArgs = {
            setup = setup // { isVirtualBox = true; basicSetup = true; };
          };
        };
        myusername_virtualbox_nixos_basic = mkHomeManagerConfiguration {
          extraSpecialArgs = {
            setup = setup // { isVirtualBox = true; isNixOS = true; basicSetup = true; };
          };
        };
        myusername_nixos_basic = mkHomeManagerConfiguration {
          extraSpecialArgs = {
            setup = setup // { isNixOS = true; basicSetup = true; };
          };
        };
      };
  };
}

home.nix

# Note: Based on the work of
#    https://github.com/giggio/dotfiles/tree/main/home-manager
#    ...and various other sources
#    

{ config, pkgs, lib, inputs, setup, nixgl, ... }:

let
  # Nothing here
in
rec {
  nixGL.packages = nixgl.packages;
  nixGL.defaultWrapper = "mesa";
  #nixGL.offloadWrapper = "nvidiaPrime";
  nixGL.installScripts = [ "mesa" ];

  nixpkgs = {
    config = {
      allowUnfreePredicate = pkg: builtins.elem (lib.strings.getName pkg) [
        "code"
        "discord"
        "gh-copilot"
        "vscode"
      ];
      permittedInsecurePackages = [ # todo: remove. This is because of element-desktop. See: https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802
        "jitsi-meet-1.0.8043"
      ];
    };
  };

  home = {
    username = "myusername";
    homeDirectory = "/home/" + home.username;
    stateVersion = "24.11"; # Check if there are state version changes before changing this field: https://nix-community.github.io/home-manager/release-notes.xhtml
    #preferXdgDirectories = true;
    packages =
      let
        basic_pkgs = (with pkgs; [
          # common basic packages
          age
          atuin
          bat
          blesh
          cowsay
          fx
          fzf
        ] ++ (if setup.wsl then [
          # wsl basic packages
          wslu
        ] else [
          # non wsl basic packages
          htop
        ] ++ (with gnomeExtensions; [
          # Removed 
          ## gsconnect # todo: not running, see: https://github.com/NixOS/nixpkgs/issues/173301
          #blur-my-shell
          #burn-my-windows
          #caffeine
        ])
        ) ++ (if setup.isNixOS then [
          # NixOS basic packages
        ] else [
          # non NixOS basic packages
        ]));
        non_basic_pkgs = lib.lists.optionals (!setup.basicSetup) (with pkgs; [
          # common non basic packages
          devbox
          epiphany
          evince
          pdfarranger
          signal-desktop
          syncthing
          sysz
          virt-manager
          virt-viewer
        ] ++ (if setup.wsl then [
          # wsl non basic packages
        ] else [
          # non wsl non basic packages
          whatsapp-for-linux
          #kdePackages.kdenlive
          #glaxnimate
        ]) ++ (if setup.isNixOS then [
          # NixOS non basic packages
          #vscode-fhs
          #microsoft-edge
          # protonup-qt # to use with steam
        ] else [
          # non NixOS non basic packages
          (config.lib.nixGL.wrap marble)
          (config.lib.nixGL.wrap mpv)
          (config.lib.nixGL.wrap kdePackages.okular)
          (config.lib.nixGL.wrap vlc)
        ]));
        all_packages = basic_pkgs ++ non_basic_pkgs;
      in
      all_packages;

    # TODO: Move session management to home-manager
    #sessionPath = [
    #  "$HOME/.local/bin"
    #  "$XDG_DATA_HOME/npm/bin"
    #  "$HOME/.krew/bin"
    #];
    #sessionVariables = {
    #  # this goes into ~/.nix-profile/etc/profile.d/hm-session-vars.sh, which is
    #  # loaded by .profile, and so only reloads if we logout and log back in
    #  LC_ALL = "en_US.UTF-8";
    #  TMP = "/tmp";
    #  TEMP = "/tmp";
    #  EDITOR = "vim";
    #  XDG_DATA_HOME = "\${XDG_DATA_HOME:-$HOME/.local/share}";
    #  XDG_STATE_HOME = "\${XDG_STATE_HOME:-$HOME/.local/state}";
    #  XDG_CACHE_HOME = "\${XDG_CACHE_HOME:-$HOME/.cache}";
    #  NPM_CONFIG_PREFIX = "\${NPM_CONFIG_PREFIX:-$HOME/.local/share/npm}";
    #  BASIC_SETUP = "\${BASIC_SETUP:-false}";
    #};

    # TODO: Move config file management to home-manager
    #file = {
    #  ".cargo/.keep".text = "";
    #  ".local/bin/dotnet-uninstall".source = ./bin/dotnet-uninstall;
    #  ".local/bin/hm".source = ./bin/hm;
    #  ".hushlogin".text = "";
    #  ".XCompose".text =
    #    ''
    #      <dead_acute> <C> : "Ç" Ccedilla # LATIN CAPITAL LETTER C WITH CEDILLA
    #      <dead_acute> <c> : "ç" ccedilla # LATIN SMALL LETTER C WITH CEDILLA
    #    '';
    #  ".tmux.conf".text =
    #    ''
    #      set -g default-terminal "screen-256color"
    #      set-option -g default-shell /bin/bash
    #      set -g history-limit 10000
    #      source "$HOME/.nix-profile/share/tmux/powerline.conf"
    #      set -g status-bg colour233
    #      set-option -g status-position top
    #      set -g mouse

    #      # Smart pane switching with awareness of vim splits
    #      bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys C-h) || tmux select-pane -L"
    #      bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys C-j) || tmux select-pane -D"
    #      bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys C-k) || tmux select-pane -U"
    #      bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys C-l) || tmux select-pane -R"
    #      # bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|vim?)(diff)?$' && tmux send-keys 'C-\\') || tmux select-pane -l"
    #    '';
    #  ".w3m/config".text =
    #    ''
    #      inline_img_protocol 4
    #      auto_image TRUE
    #    '';
    #  ".inputrc".text = "set bell-style none";
    #  ".vimrc".text = "source ~/.vim/.vimrc";
    #};

  };

  programs = {
    home-manager = {
      # Let Home Manager install and manage itself.
      enable = true;
    };

    # Removed by jwc
    #bash = {
    # (lots of lines deleted to save space)

  };

  fonts.fontconfig.enable = !setup.wsl;

  # Added by JWC
  #targets.genericLinux.enable = true;
  targets.genericLinux.enable = !setup.wsl || setup.isNixOS;

  # Added by JWC
  xdg.mime.enable = false;

}

@vuthanhtung2412
Copy link

vuthanhtung2412 commented Dec 4, 2024

@level323 Thank you a lot for sharing you set up 💯 . I made the following changes

# in home.nix
# from 
nixGL.defaultWrapper = "nvidia";
# to 
nixGL.defaultWrapper = "nvidiaPrime"; # or "mesa"
nixGL.installScripts = [ "nvidiaPrime"];
# in flake.nix
# from 
nixGL = {
  url = "github:nix-community/nixGL";
};
# to
nixGL = {
  url = "github:nix-community/nixGL";
  inputs.nixpkgs.follows = "nixpkgs";
};

and it now works like a champ 🎉

 ~#@❯ nvidia-smi
Wed Dec  4 10:16:42 2024       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.120                Driver Version: 550.120        CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce MX250           Off |   00000000:01:00.0 Off |                  N/A |
| N/A   38C    P3             N/A / ERR!  |     233MiB /   2048MiB |      4%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      2802      G   /usr/lib/xorg/Xorg                             86MiB |
|    0   N/A  N/A    571675      G   ...w58c0pgb95wi-kitty-0.37.0/bin/kitty          2MiB |
|    0   N/A  N/A    572044    C+G   ...8nr4r9lac-blender-4.2.3/bin/blender        125MiB |
|    0   N/A  N/A    572551      G   ...xjgnm9qnp-obs-studio-30.2.3/bin/obs         15MiB |
+-----------------------------------------------------------------------------------------+

I think there must be something wrong with nixGL.defaultWrapper "nvidia" option

@exzombie
Copy link
Contributor

exzombie commented Dec 4, 2024

Sigh

I had a complete flake example in the documentation of the NixGL module at some point, but I decided not to include it because it seemed more appropriate to instead extend the other section of the documentation where flakes are discussed. Which would be a separate pull request that I then didn't make. I see now that it was a mistake. The way the NixGL input is passed trough extraSpecialArgs is not specific to NixGL, and I didn't realize that for many people, this would be the first time they encounter this mechanism, and how much wasted effort not having a complete example would cause.

Would one of you people be willing to extend the existing example in the HM documentation and open a pull request? It seems like a good way to get your feet wet contributing to HM 😉

@exzombie
Copy link
Contributor

exzombie commented Dec 4, 2024

I think there must be something wrong with nixGL.defaultWrapper "nvidia" option

If nvidia does not work but nvidiaPrime does, that means that you have an Optimus system where Nvidia is the secondary GPU.

@vuthanhtung2412
Copy link

@exzombie Thank you for the explanation ✋. My Intel chip must have an integrated GPU 😅

@level323
Copy link

level323 commented Dec 4, 2024

Sigh

Thankyou for all you've done on this aspect of HM and all you no doubt continue to do!

[...] The way the NixGL input is passed trough extraSpecialArgs is not specific to NixGL, and I didn't realize that for many people, this would be the first time they encounter this mechanism

I wish this was the only part I still don't understand about flakes! I continue to learn.

Would one of you people be willing to extend the existing example in the HM documentation and open a pull request? It seems like a good way to get your feet wet contributing to HM 😉

I feel hopelessly out of my depth. There's still many parts in my own flake.nix, where I still don't clearly understand what's going on. I pieced it together from other sources and used my coding experience to make educated guesses about what was probably needed, and finally got a working version after many iterations. For example, beyond the fact that it pulls in home.nix, I have very little idea about what is actually going on in the outputs = { ..... } stanza of my flake.nix.

@vuthanhtung2412
Copy link

vuthanhtung2412 commented Dec 9, 2024

Hello team
I activated nixGL for chromium based application like below.

# home.nix
{ config, pkgs, nixGL, pkgs2405, ... }:

{
  home.username = "tung"; 
  home.homeDirectory = "/home/tung";

  home.stateVersion = "24.11"; 

  nixGL.packages = nixGL.packages;
  nixGL.defaultWrapper = "mesa";
  nixGL.offloadWrapper = "nvidiaPrime";

  nixpkgs = {
    config = {
      allowUnfree = true;
      allowUnfreePredicate = (pkg: true);
    };
  };
  ...
  programs = {
    chromium={
      enable = true;
      package = (config.lib.nixGL.wrap pkgs.chromium); # mesa acceleration with iGPU
      # or
      # package = (config.lib.nixGL.wrapOffload pkgs.chromium); 
    };
  };
}

The app is still working fine in both case. However, it display the following errors which may indicate that it is not properly GPU accelerated:

# package = (config.lib.nixGL.wrap pkgs.chromium); 
 ~#@❯ chromium
Gtk-Message: 11:37:15.839: Failed to load module "canberra-gtk-module"
Gtk-Message: 11:37:15.840: Failed to load module "canberra-gtk-module"
[319778:319778:1209/113716.324122:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.ScreenSaver.GetActive: object_path= /org/freedesktop/ScreenSaver: org.freedesktop.DBus.Error.NotSupported: This 
method is not implemented

# package = (config.lib.nixGL.wrapOffload pkgs.chromium); 
 ~#@❯ chromium
...
[323956:323956:1209/113902.839182:ERROR:gl_display.cc(497)] EGL Driver message (Critical) eglInitialize: Invalid visual ID requested.
[323956:323956:1209/113902.839219:ERROR:gl_display.cc(767)] eglInitialize OpenGLES failed with error EGL_NOT_INITIALIZED
[323956:323956:1209/113902.839257:ERROR:gl_display.cc(801)] Initialization of all EGL display types failed.
[323956:323956:1209/113902.839295:ERROR:gl_ozone_egl.cc(26)] GLDisplayEGL::Initialize failed.
[323956:323956:1209/113902.840585:ERROR:viz_main_impl.cc(181)] Exiting GPU process due to errors during initialization

I tried removing GPUCache,GrShaderCache,ShaderCache like this comment but it still not working.

 ~#@❯ SEARCH_DIR=${1:-.}

# Find and delete subfolders with specified names
echo "Searching and clearing cache folders in $SEARCH_DIR..."

find "$SEARCH_DIR" -type d \( -name "*GPUCache*" -o -name "*GrShaderCache*" -o -name "*ShaderCache*" \) -print -exec rm -rf {} +

echo "Done! Cleared all matching subfolders."
Searching and clearing cache folders in ....
./chromium/GrShaderCache
./chromium/Default/GPUCache
./chromium/Default/DawnWebGPUCache
./chromium/ShaderCache
./1Password/Partitions/1password/GPUCache
./1Password/Partitions/1password/DawnWebGPUCache
Done! Cleared all matching subfolders.
 ~#@❯ ll -R | grep -e GPUCache -e GrShaderCache -e ShaderCache

more info about my system

nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.0-49-generic, Ubuntu, 22.04.5 LTS (Jammy Jellyfish), nobuild`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.3`
 - nixpkgs: `/nix/store/pzvsngvb3x5lnma3y855ij1m7s581dhm-source

libGL problem references
NixOS/nixpkgs#269104
NixOS/nixpkgs#269345
NixOS/nixpkgs#244742

@dominicmeyer
Copy link

Hello team I activated nixGL for chromium based application like below.

# home.nix
{ config, pkgs, nixGL, pkgs2405, ... }:

{
  home.username = "tung"; 
  home.homeDirectory = "/home/tung";

  home.stateVersion = "24.11"; 

  nixGL.packages = nixGL.packages;
  nixGL.defaultWrapper = "mesa";
  nixGL.offloadWrapper = "nvidiaPrime";

  nixpkgs = {
    config = {
      allowUnfree = true;
      allowUnfreePredicate = (pkg: true);
    };
  };
  ...
  programs = {
    chromium={
      enable = true;
      package = (config.lib.nixGL.wrap pkgs.chromium); # mesa acceleration with iGPU
      # or
      # package = (config.lib.nixGL.wrapOffload pkgs.chromium); 
    };
  };
}

The app is still working fine in both case. However, it display the following errors which may indicate that it is not properly GPU accelerated:

# package = (config.lib.nixGL.wrap pkgs.chromium); 
 ~#@❯ chromium
Gtk-Message: 11:37:15.839: Failed to load module "canberra-gtk-module"
Gtk-Message: 11:37:15.840: Failed to load module "canberra-gtk-module"
[319778:319778:1209/113716.324122:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.ScreenSaver.GetActive: object_path= /org/freedesktop/ScreenSaver: org.freedesktop.DBus.Error.NotSupported: This 
method is not implemented

# package = (config.lib.nixGL.wrapOffload pkgs.chromium); 
 ~#@❯ chromium
...
[323956:323956:1209/113902.839182:ERROR:gl_display.cc(497)] EGL Driver message (Critical) eglInitialize: Invalid visual ID requested.
[323956:323956:1209/113902.839219:ERROR:gl_display.cc(767)] eglInitialize OpenGLES failed with error EGL_NOT_INITIALIZED
[323956:323956:1209/113902.839257:ERROR:gl_display.cc(801)] Initialization of all EGL display types failed.
[323956:323956:1209/113902.839295:ERROR:gl_ozone_egl.cc(26)] GLDisplayEGL::Initialize failed.
[323956:323956:1209/113902.840585:ERROR:viz_main_impl.cc(181)] Exiting GPU process due to errors during initialization

I tried removing GPUCache,GrShaderCache,ShaderCache like this comment but it still not working.

 ~#@❯ SEARCH_DIR=${1:-.}

# Find and delete subfolders with specified names
echo "Searching and clearing cache folders in $SEARCH_DIR..."

find "$SEARCH_DIR" -type d \( -name "*GPUCache*" -o -name "*GrShaderCache*" -o -name "*ShaderCache*" \) -print -exec rm -rf {} +

echo "Done! Cleared all matching subfolders."
Searching and clearing cache folders in ....
./chromium/GrShaderCache
./chromium/Default/GPUCache
./chromium/Default/DawnWebGPUCache
./chromium/ShaderCache
./1Password/Partitions/1password/GPUCache
./1Password/Partitions/1password/DawnWebGPUCache
Done! Cleared all matching subfolders.
 ~#@❯ ll -R | grep -e GPUCache -e GrShaderCache -e ShaderCache

more info about my system

nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.0-49-generic, Ubuntu, 22.04.5 LTS (Jammy Jellyfish), nobuild`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.3`
 - nixpkgs: `/nix/store/pzvsngvb3x5lnma3y855ij1m7s581dhm-source

libGL problem references NixOS/nixpkgs#269104 NixOS/nixpkgs#269345 NixOS/nixpkgs#244742

Same issue here, is there a known fix?

@vuthanhtung2412
Copy link

I think it is a problem of chromium based app itself. For me it still run on the iGPU (mesa) so i give up on the nvidia set up already. It is kind of a deep rabbit hole

@carnotweat
Copy link

For anyone who wants to test #5355, I couldn't find an extensive way to do this, and I wanted to use Kitty, so this is what I did. I am using home-manager with flakes. I am new to all of this, so it might be obvious to many of the ones reading this, but it was not obvious to me. You can see the working sample at my dotfiles repo: https://github.com/giggio/dotfiles/blob/main/config/home-manager/home.nix https://github.com/giggio/dotfiles/blob/main/config/home-manager/flake.nix And this is is the commit with the diffs: giggio/dotfiles@c5e6901

I added NixGL to my input on flake.nix:

    nixGL = {
      url = "github:nix-community/nixGL/310f8e49a149e4c9ea52f1adf70cdc768ec53f8a";
      inputs.nixpkgs.follows = "nixpkgs";
    };

In home.nix:

I added @Smona's patch to my imports:

  imports = [
    (builtins.fetchurl {
      url = "https://raw.githubusercontent.com/Smona/home-manager/nixgl-compat/modules/misc/nixgl.nix";
      sha256 = "74f9fb98f22581eaca2e3c518a0a3d6198249fb1490ab4a08f33ec47827e85db";
    })
  ];

I added an alias for nixGL, like so:

let
  nixGLIntel = inputs.nixGL.packages."${pkgs.system}".nixGLIntel;
#...

I installed it by adding nixGLIntel to packages. And, in packages, kitty was changed to (config.lib.nixGL.wrap kitty).

And I added the option:

  nixGL.prefix = "${nixGLIntel}/bin/nixGLIntel";

This changed my kitty executable, which now looks like so:

$ cat `which kitty`
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
exec -a "$0" /nix/store/vbhv6ijhy65ma7z8i67dkci7ddiwzvrf-nixGLIntel/bin/nixGLIntel /nix/store/cmkk0l1qs0hph06nlp0ji1arkpxp44xs-kitty-0.34.1/bin/kitty "$@"

I hope this helps someone.

@Smona I hope your PR is merged soon so I can remove the customizations. Thanks for that!

When I try it on x86_64-linux, I get

   error: a 'aarch64-darwin' with features {} is required to build '/nix/store/9ag5fyidmahk5nalq9qxyhp4n6mjgdbk-impure-nvidia-version-file.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test

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

Successfully merging a pull request may close this issue.