-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Making nixGL works with Home Manager #114
Comments
flakes is what you are searching for.
I don't think you can do this. I would try to add this to home.package instead and hope it gets in $PATH before alacrity. If that does not work I would try to make the wrapper you created a full package, without writeShellScript*. |
Thanks a lot for the comment @SuperSandro2000. Forgot to mention that I did add |
For some inspiration, I wrapped my google-chrome with nixGL like this: Gerschtli/nix-config@ab51b30 Maybe there could be a library function exported by this flake to get the needed lines directly without reading the package. @guibou What do you think? If we can agree on an API, I could create a PR :) |
https://github.com/dali99/nix-dotfiles/blob/9639108c536fd7f1ab4d5606d5f5ee1b51bd0a4c/profiles/xsession/default.nix#L121 I have this for my non-nixos machines. This successfully starts my window manager and lets me run gui programs without wrapping those induvidually |
@thanhnguyen2187 nixGLVulkanMesaWrap = pkg:
pkgs.runCommand "${pkg.name}-nixgl-wrapper" { } ''
mkdir $out
ln -s ${pkg}/* $out
rm $out/bin
mkdir $out/bin
for bin in ${pkg}/bin/*; do
wrapped_bin=$out/bin/$(basename $bin)
echo "${lib.getExe pkgs.nixgl.nixGLIntel} ${
lib.getExe pkgs.nixgl.nixVulkanIntel
} $bin \$@" > $wrapped_bin
chmod +x $wrapped_bin
done
''; here you can see what I have done so you can easly set it up |
I have been following a similar approach, but combining
|
Okay! After lots of hacking around I think I've found a way to solve this problem in the general case. In one of my home-manager modules, I define this option, which i set per-machine to something like {
options.nixGLPrefix = lib.mkOption {
type = lib.types.str;
default = "";
description = ''
Will be prepended to commands which require working OpenGL.
This needs to be set to the right nixGL package on non-NixOS systems.
'';
};
} Then, I use this function to wrap any packages that I want to be run in the nixGL context: # Call once on import to load global context
{ pkgs, config }:
# Wrap a single package
pkg:
if config.nixGLPrefix == "" then
pkg
else
# Wrap the package's binaries with nixGL, while preserving the rest of
# the outputs and derivation attributes.
(pkg.overrideAttrs (old: {
name = "nixGL-${pkg.name}";
buildCommand = ''
set -eo pipefail
${
# Heavily inspired by https://stackoverflow.com/a/68523368/6259505
pkgs.lib.concatStringsSep "\n" (map (outputName: ''
echo "Copying output ${outputName}"
set -x
cp -rs --no-preserve=mode "${pkg.${outputName}}" "''$${outputName}"
set +x
'') (old.outputs or [ "out" ]))}
rm -rf $out/bin/*
shopt -s nullglob # Prevent loop from running if no files
for file in ${pkg.out}/bin/*; do
echo "#!${pkgs.bash}/bin/bash" > "$out/bin/$(basename $file)"
echo "exec -a \"\$0\" ${config.nixGLPrefix} $file \"\$@\"" >> "$out/bin/$(basename $file)"
chmod +x "$out/bin/$(basename $file)"
done
shopt -u nullglob # Revert nullglob back to its normal default state
'';
})) And here is an example of how I would use it: let nixGL = import ./nixGL.nix { inherit pkgs config; };
in {
home.packages = with pkgs;
[
(nixGL keybase-gui)
(nixGL spotify)
(nixGL vlc)
# ...
];
programs.chromium = {
enable = true;
package = (nixGL pkgs.chromium);
};
} This has worked for me for every GUI app I install with nix on Ubuntu 22. I'm using it for firefox, kitty, and the emacs-community-overlay with doom emacs, all of which are passed into their respective home manager modules and decorated with additional options after they're wrapped. Basically, it wraps the passed derivation, preserving every attribute except the build command, which symlinks all the derivation output files to I think with a little more work, this function could be modified to directly take a Pros:
Cons / TODO:
|
Do you mind explaning this:
Where this should go ? I'm using flakes so i can handle multiple users/machines. Does it go into the modules array for each homeManagerConfiguration ? Edit: I've managed to make it work without this option by using nixGLDefault in the nixGL wrapper as below:
|
@lamarios I would recommend reading the docs about writing home manager modules, or more specifically NixOS modules. You can either add the option to your # options.nix
{ lib, ... }:
{
options.nixGLPrefix = lib.mkOption {
type = lib.types.str;
default = "";
description = ''
Will be prepended to commands which require working OpenGL.
This needs to be set to the right nixGL package on non-NixOS systems.
'';
};
} # home.nix
{
imports = [ ./options.nix ];
# ...
} |
@lamarios take a look at my dotfiles https://github.com/rengare/dotfiles/tree/main/nix |
Thanks both, managed to get it working. I have a bit of a hard time with how things come together in nix. I didn't know that just importing the options.nix file would actually make the option available just like that. |
So, how is the home-manager support going to look like? For example, aagl-on-nix and nix-gaming both works on a simple import, then the modules and pkgs are available to access with a prefix, and that's honestly a lot easier than learning how flakes works (I still don't really get it -- anyone have an article with good examples?). |
Here's a simple version to wrap all of the executables in an underlying package that works quite nicely, inspired by @Smona's work. let
nixGL = import <nixgl> { };
nixGLWrap = pkg:
let
bin = "${pkg}/bin";
executables = builtins.attrNames (builtins.readDir bin);
in
pkgs.buildEnv {
name = "nixGL-${pkg.name}";
paths = map
(name: pkgs.writeShellScriptBin name ''
exec -a "$0" ${nixGL.auto.nixGLDefault}/bin/nixGL ${bin}/${name} "$@"
'')
executables;
};
in
programs.kitty.package = nixGLWrap pkgs.kitty; A small downside to this approach is that the composed package does not contain all of the contents of the original package, so if you need to refer to other files from the original package, you'll need to use the unwrapped version. |
Here's an improvement to the above that uses { pkgs }:
pkg:
let
nixGL = import <nixgl> { };
bins = "${pkg}/bin";
in
pkgs.buildEnv {
name = "nixGL-${pkg.name}";
paths =
[ pkg ] ++
(map
(bin: pkgs.hiPrio (
pkgs.writeShellScriptBin bin ''
exec -a "$0" "${nixGL.auto.nixGLDefault}/bin/nixGL" "${bins}/${bin}" "$@"
''
))
(builtins.attrNames (builtins.readDir bins)));
} |
This works great, unfortunately I now understand what was meant by "does not contain all of the contents of the original package". It seems the .desktop files are no longer installed with the package making launchers like wofi not able to pick them up. |
It should work if you add both the original package and the wrapper env to |
I have been using a bunch of wrappers for a while now, and I've been quite happy with how they work. But I haven't had time to clean up this stuff and create a HM module that others could easily use. And I won't have time for months yet. So I'll just leave this stuff here, maybe someone will pick it up. Perhaps combining it with the hiPrio stuff, which I didn't know about. My goals:
To use this, nixGL has to be an input of your HM flake, and you need to copy its default package to your flake outputs. Like so:
Then, the config file quoted below will add the function for wrapping packages to You can use the wrapper like so:
This "check" wrapper will only wrap the package if you have enabled the Another pecularity is that the Hopefully, someone will find this useful 😄
|
Hey everyone, First of all, thanks a lot for providing these very useful wrapper functions and explanations. It has been key to helping me get home-manager working with graphical apps and giving me some deeper understanding as to how nix works in general. If any of you have a minute, kindly check out my new issue #163 which is trying to deal with a particular edge case when installing a nixgl wrapped version of alacritty. In addition, if anyone has any advice on how to purify the installation and wrapping of packages using Nvidia NixGL then I am all ears. |
@RicSanOP, the wrappers I posted achieve purity by not integrating the nixGL Nvidia wrappers into the home-manager configuration, but by calling |
@exzombie I am trying to run your wrappers. I have pretty much copy pasted your above code into my Unfortunately, I am getting this error when trying to run
My current guess is that I am not setting things up correctly within the
|
@RicSanOP, there's |
@exzombie I simply copy pasted from what you had above just to get it working. Right now my
and this is now the current
the rest is a copy paste of the large wrapper blob you provided in your initial comment. I still get the same error regarding the missing I am providing my entire
|
@RicSanOP
I made adjustments to your flake and moved the wrapper functions out of
|
Hey @exzombie , thanks a lot for the help. The above modifications have surely gotten home-manager to successfully switch. Now the
and
which only happens when the following line (marked with **) from the
Here is the output when a graphical program successfully runs using the intel option
Here is the output when a graphical program unsuccessfully runs using the nvidia option
Do you have any ideas as to what is going on or how to fix it? I am glad this is close to working. Perhaps after I get this working and properly organized, I will take a look into getting that home-manager module made. Really appreciate your help and patience so far. |
It appears something changed in nixGL. Now I'm afraid to update my own flake 😅. I can start brave from your configuration by changing the flake inputs to
I'm not sure whether it's necessary to revert to older nixpgks, it's there because I tried that first. But what really fixed it was using the specific nixGL commit that I had in my own
works well enough. I don't know why it would fail when calling build on the flake cached in nix store 🤔 |
@rengare Your flake wrapper helper (Mesa at least) are working great for me, thank you! |
For cross reference, there is also nix-community/home-manager#3968 May we continue there, and close this issue? |
Home manager now has an official nixGL integration, so I think this issue can be closed 🙂 |
Hi.
Thanks for the awesome work!
I am using Home Manager within Pop OS 22.04 and have got stuck trying to make nixGL works. My configuration basically looks like this:
Try running
home-manager switch
gives me this:While
nix-env -iA nixgl.auto.nixGLDefault
, and thennixGL alacritty
works as expected.I found a few issues on nixGL is not a proper package of nixpkgs, and guess that it probably is the issue. I wonder if there is a workaround? Using
nix
and Home Manager feels so good that I do not want to come back to good oldapt
...Thanks!
The text was updated successfully, but these errors were encountered: