-
-
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
Howto run commands automatically with nixGL? #44
Comments
Thank you for your feedback, it is highly appreciated.
You can create your own derivation and wrap them with In theory, you can also run your shell launcher in |
What is your opinion on wrapping For example, have a script in .profile that replaces copies the |
I solved it for now by adding the export part in the nixGL script to my In my case that's:
It's not perfect, This will add these paths every time .profile is executed. |
The scripts in this gist switch automatically between intel and nivida drivers: https://gist.github.com/rvanlaar/5ca5ed3cd4314c12e8518b5672ae3774 |
Thank you. It is appreciated. I had a look at your script and indeed that's an interesting approach. However I'm afraid of the robusntess of it. It needs the egpu utility installed (which may not be installed by nix because it may need host system specific configuration, I don't know). Another problem of having a "global" nixGL installation (so, basically, something in However I'm not saying that your solution is unacceptable because it does not fix all issues. I do think that there is value in your proposal because I do think that improving the quality of life of a few users, even if that's not all users, is a good reason. I just don't want to complexify nixGL for the other users (those for which your proposal won't work). Let me think about it. |
The points you raise are valid, those are issues I have with my current script as well. It's not robust enough yet:
What could be an option is to have nixGL scripts that can be sourced from .profile, so have them without the "$@" at the end. That would solve |
You have really good point here. Indeed, I'll give a try at this refactoring when time is available. Thank you! |
That would be great. I really love how open you are to improvements to nixGL. Just had this idea: Have a minimal OpenGL program in nixGL that crashes without the proper libs? It could be used as follows (in pseudo code): nixGLIntel test_gl
intel=$?
nixGLNvidia test_gl
nvida=$?
if [ intel -eq 0 ]; then
source /path/to/nixGLintel
elif [ nvidia -eq 0]; then
source /path/to/nixGLnvidia
fi
# Test if the paths are set correctly
test_gl
status=$?
if [ status -gt 0 ]; then
echo "Problem loading nixGL scripts."
exit 1
fi |
This is what I do for reference on a non-nixos system:
|
An update. I've stopped using nix packages for graphical applications. Two things changed,
Having the nixGLIntel exports in my .profile per default resulted in a broken desktop environment. It crashed after login. I'm also looking forward again to having the latest VScode and firefox working together with gnome-shell again. |
I was also interested in having working .desktop files. The following simple wrapper, adapted from here, meets my requirements. It that just wraps the binaries themselves, and no change to .desktop files is needed as those will transparently call wrapped binaries: # a `home.nix` that is fed into home-manager
{pkgs, lib, ...}:
let
# ...
nixGLWrap = 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 "exec ${lib.getExe pkgs.nixgl.nixGLIntel} $bin \$@" > $wrapped_bin
chmod +x $wrapped_bin
done
'';
in {
# ...
programs.alacritty = {
enable = true;
package = nixGLWrap pkgs.alacritty;
# ...
};
} |
@hab25 solution worked great for me. I have replaced # a `home.nix` that is fed into home-manager
{config, pkgs, lib, ...}:
let
# ...
nixgl = import <nixgl> {} ;
nixGLWrap = 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 "exec ${lib.getExe nixgl.auto.nixGLDefault} $bin \$@" > $wrapped_bin
chmod +x $wrapped_bin
done
'';
in {
# ...
home.packages = [
nixgl.auto.nixGLDefault
(nixGLWrap pkgs.kitty)
(nixGLWrap pkgs.inkscape)
# ...
];
} I'm not sure if there will be unintended consequences, such as reported in Issue #116. My use case, is to use Home Manager as a replacement for |
There is a bug in the code I previously shared, it makes it so you can't pass an argument that contains spaces to the wrapped program (e.g. To fix it, change, in the code, (that is,
#116 does happen, but it has been tolerable; the only time I've noticed it is when trying to call |
I modified the wrapper to simply replace the desktop files of packages and symlink every other file, so now all of the menus just work. To launch programs from a terminal you still need to use the prefix nixGLIntel, or you can set up some aliases in your ~/.bashrc The below bash script is to install packages as root so that all users have access to the installed programs. If you have a Nvidia card, you will need to modify the script and add the impure flag. I have this running on Ubuntu, but it should work on any other distro. You will need to log out and then back in again for the desktop files to appear in your menu. This could help out with #90 and #114
|
Thanks a lot for the nixGLWrap solution, it works very well! In case you also started to get the following warning, I found a way to get rid of the warning:
My new code: nixGLWrap = 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 "exec ${lib.getExe' nixGL.auto.nixGLDefault "nixGL"} $bin \"\$@\"" > $wrapped_bin
chmod +x $wrapped_bin
done
''; So basically just replace |
These pointers were helpful. I'm a Nix beginner but I needed to customize additional command line arguments. I based on the cookbook and am now using: nixGLWrap = let
wrap = pkg: program: args: pkgs.writeShellScriptBin program ''
exec ${pkgs.nixgl.nixGLIntel}/bin/nixGLIntel ${pkg}/bin/${program} ${args} "$@"
'';
in
pkg: programArgs: pkgs.symlinkJoin {
name = "${pkg.name}-nixgl-wrapper";
paths = (lib.mapAttrsToList (wrap pkg) programArgs) ++ [ pkg ];
}; Used like: (nixGLWrap pkgs.ungoogled-chromium {
chromium = "--ozone-platform=wayland --enable-features=TouchpadOverscrollHistoryNavigation";
}) |
I much appreciate the effort you put into this package.
It made me able to use nix on ubuntu.
Could you shed light on how to solve the following?
I normally start programs via the gnome shell launcher.
In the firefox example, I went on to investigate due to it being extremely slow.
That's not something I normally do.
The text was updated successfully, but these errors were encountered: