home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

init: workarounds.nixgl module

Open michaelCTS opened this issue 1 year ago • 4 comments

Description

The option allows packages to be wrapped by nixgl in order to make GUI applications work when installed with home-manager. The goal of this PR is just to make it easy to use graphically accelerated programs installed with home-manager in a desktop environment.

No need to install and run nixGL $program. Just add the package to workaround.nixgl.packages like so [ { pkg = pkgs.some_package; }].

Anything more advanced can come in further PRs by other people.

Checklist

  • [x] Change is backwards compatible.

  • [x] Code formatted with ./format.

  • [ ] Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • [ ] Test cases updated/added. See example.

  • [x] Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • [x] Added myself as module maintainer. See example.

Maintainer CC

Closes #3968

michaelCTS avatar Apr 24 '24 10:04 michaelCTS

Well, I tried adding tests, but for some reason this fails

{ lib, pkgs, ... }:                                                                           

with lib;

{
 config = {
  workarounds.nixgl.packages = with pkgs; [{ pkg = alacritty; }];                           
  
  nmt.script = ''
   assertFileRegex .nix-profile/bin/alacritty 'exec "/nix/store/.*/bin/nixGL" .*/alacritty'
   assertLinkExists .nix-profile/share/applications/Alacritty.desktop                      
  '';
 };
}

It doesn't find the files even though when I run home-manage switch I do see them.

user@mikes-workstation:~/projects/home-manager$ nix-shell --pure tests -A run.nixgl-simple                                                    
nixgl-simple: FAILED                                                                                                                          
Expected .nix-profile/bin/alacritty to match exec "/nix/store/.*/bin/nixGL" .*/alacritty but it did not.                                      
For further reference please introspect /nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple                                   
user@mikes-workstation:~/projects/home-manager$ find -H /nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple                   
/nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple                                                                           
/nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple/tested                                                                    
/nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple/script                                                                    
/nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple/output                                                                    
/nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple/result                                                                    
user@mikes-workstation:~/projects/home-manager$ find -H /nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple/tested/           
activate    bin/        hm-version  home-files/ home-path/                                                                                    
user@mikes-workstation:~/projects/home-manager$ ls -l /nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple/tested/bin/         
total 4                                                                                                                                       
lrwxrwxrwx 1 user user 76 Jan  1  1970 home-manager-generation -> /nix/store/vayk06bjilg7xznd743gj5lmrsi5byis-home-manager-generation/activate
user@mikes-workstation:~/projects/home-manager$ ls -al /nix/store/jvnyika0ymigkyn2gp8v89w9i2d78bbz-nmt-report-nixgl-simple/tested/home-files/ 
total 1620                                                                                                                                    
dr-xr-xr-x    5 user user    4096 Jan  1  1970 .                                                                                              
drwxr-xr-x 2266 user user 1638400 Apr 25 14:15 ..                                                                                             
dr-xr-xr-x    2 user user    4096 Jan  1  1970 .cache                                                                                         
dr-xr-xr-x    3 user user    4096 Jan  1  1970 .config                                                                                        
dr-xr-xr-x    2 user user    4096 Jan  1  1970 asserts                                                                                        

michaelCTS avatar Apr 25 '24 14:04 michaelCTS

Thanks for the contribution! I've added a bunch of, hopefully, useful comments. Note, to actually include the module you need to add it to the modules/modules.nix file.

rycee avatar Apr 27 '24 07:04 rycee

I'm really happy that you found the time and will to make a pull request! Many of us have built our own hacks and workarounds, and will appreciate having a solution as part of HM.

I haven't had the time to try this yet, but just looking at the interface, I'm a bit surprised that you chose to implement a list of packages to enable nixgl for. Having followed the various discussions, I got the impression that most of us went with wrapper functions. Is there a particular reason why you chose to go with a list of packages instead?

One reason why a wrapper is more convenient is that you can wrap a package regardless of where it's used, be it in home.packages or in programs.whatever.package. As noted by @joefiorini in #3968, not being able to use nixgl in programs.kitty.package is a real problem.

One more question: does this module require building the home configuration with --impure?

exzombie avatar Apr 27 '24 07:04 exzombie

@rycee I addressed your comments and applied the changes.

Additionally, I added the wrapper to config.lib.nixGl.wrap like @Smona. That should resolves your problem @joefiorini

programs.kitty = {                                          
 enable = true;                                            
 package = config.lib.nixGl.wrap { package = pkgs.kitty; };
};                                                          

One more question: does this module require building the home configuration with --impure?

@exzombie I have no idea what that does. It works without that for me.

michaelCTS avatar Apr 30 '24 11:04 michaelCTS

Closed in favor of #5355

michaelCTS avatar May 06 '24 07:05 michaelCTS