nix-community / nixGL

A wrapper tool for nix OpenGL application [maintainer=@guibou]
677 stars 78 forks source link

Make usage with `nix run` easy #97

Closed PaulGrandperrin closed 2 years ago

PaulGrandperrin commented 2 years ago

It is already possible to launch nixGL directly from the command line, but it is far from easy. This is how I did it:

nix run  --impure --expr '((builtins.getFlake "github:guibou/nixGL").overlay (builtins.getFlake "nixpkgs/nixos-21.11").legacyPackages.x86_64-linux {}).nixgl.auto.nixGLDefault.overrideAttrs (o: rec { pname="nixGL"; })' . -- program

Because only an overlay is provided, we need to manually instantiate it with a nixpkgs flake, and then patch the package to have nix run find the correct binary to launch.

With this PR, things becomes much easier and I updated the documentation accordingly.

guibou commented 2 years ago

Thank you for this MR.

I'm not against it, but I'm afraid user will always hit the libc incompatibility that you perfectly described in the documentation.

Could you try to change this part of the document so it is obvious to the user that they need to use the same nixpkgs clone as the one used by their program and if they did not, they will have undefined behavior (it can be crashs, error message as described, or corrupted outputs).

If you have enough motivation to reword the documentation this way, please do it now. Otherwise, tell me, we'll merge the MR and work on the documentation improvement later.

PaulGrandperrin commented 2 years ago

Ok I'll do that but just to understand things correctly, is the requirement:

  1. that nixGL's nixpkgs be strictly the same of the one from the program
  2. that nixGL's nixpkgs the same or older than the one from the program

My limited tests made it look like 2. was true. However, I don't know if it's always true.

PaulGrandperrin commented 2 years ago

It would be nice if there was a convention of an alias in the flake registry pointing to the current system nixpkgs...

guibou commented 2 years ago

Ok I'll do that but just to understand things correctly, is the requirement:

  1. that nixGL's nixpkgs be strictly the same of the one from the program
  2. that nixGL's nixpkgs the same or older than the one from the program

My limited tests made it look like 2. was true. However, I don't know if it's always true.

I guarantee nothing with 2, however it works most of the time as you observed.

We observe problems with libc, so in theory, because this lib is backward compatible, as long as nixpkgs is the same or older, it should be fine. However we may have issue with any other lib which appears in the dependencies of the opengl driver.

TristanCacqueray commented 2 years ago

I just had a need for this PR and it worked perfectly, thanks!

Shouldn't the nixpkgs override example be the first one to avoid issue, and If mixing different nixpkgs is likely to fail, why not removing the problematic example?

Also perhaps it might be good to note that other flakes should "forward" their nixpkgs using: nixGL.inputs.nixpkgs.follows = "nixpkgs"; in their input declaration.

PaulGrandperrin commented 2 years ago

I just had a need for this PR and it worked perfectly, thanks!

Cool!

Shouldn't the nixpkgs override example be the first one to avoid issue, and If mixing different nixpkgs is likely to fail, why not removing the problematic example?

I was making three assumptions:

The documentation about how to deal with the potential error is just below, so I was thinking it was ok.

Also perhaps it might be good to note that other flakes should "forward" their nixpkgs using: nixGL.inputs.nixpkgs.follows = "nixpkgs"; in their input declaration.

Yes!

PaulGrandperrin commented 2 years ago

I updated the doc:

guibou commented 2 years ago

LGTM!

guibou commented 2 years ago

Thank you very much for this work.

PaulGrandperrin commented 2 years ago

ahah, I just pushed a small change!

PaulGrandperrin commented 2 years ago

I deleted the flake.lock so that the client will always pick up the latest version.

PaulGrandperrin commented 2 years ago

@guibou that's something that I wanted to test but I think this is not a good idea. It doesn't work like I wanted.

The issue is that users will get this error:

nix run --impure github:guibou/nixGL -- glxgears                                                                                                           
error: cannot write modified lock file of flake 'github:guibou/nixGL' (use '--no-write-lock-file' to ignore)
(use '--show-trace' to show detailed location information)