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

glava: init at v1.4.5 #42103

Merged
merged 1 commit into from Jul 7, 2018
Merged

glava: init at v1.4.5 #42103

merged 1 commit into from Jul 7, 2018

Conversation

eadwu
Copy link
Member

@eadwu eadwu commented Jun 16, 2018

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it would be nice to have this in nixpkgs, it throws an error when I actually run it:

Using backend: 'glx'
Failed to load GLX functions (libGL and libGLX do not exist!)

fixupPhase = ''
mkdir -p $out/bin

ln -sT $out/usr/bin/glava $out/bin/glava
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binaries shouldn't be in $out/usr/bin in any case, so you should move it to $out/bin/glava instead and remove the /usr folder

];

patchPhase = ''
cp -rt glad --no-preserve=all ${glad}/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more conventional to have the target at the end: cp -r --no-preserve=all ${glad}/* glad

buildInputs = [
libX11
libXext
python3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python should be in nativeBuildInputs (it's only used during the build afaik)

@eadwu
Copy link
Member Author

eadwu commented Jul 4, 2018

The way I get libGL.so into the mix is through hardware.opengl.extraPackages. Don't really know how to apply that in the build process.

  hardware = {
    opengl = {
      enable = true;
      extraPackages = with pkgs; [
        libGL
      ];
    };
  };

@eadwu
Copy link
Member Author

eadwu commented Jul 4, 2018

Seems to work if I just copy the libs from libGL through cp -r ${libGL}/lib $out/lib. Don't know whether or not I should just copy the required libs from the package.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I figured it out, it apparently uses dlopen to find the library files: https://github.com/wacossusca34/glava/blob/ebade264ea1855afe88421ccc3ec22fc835696dc/glx_wcb.c#L191-L192

To make this work, you need to add patchelf --set-rpath "${makeLibraryPath [ libGL ]}" in postFixup. Pretty sure at least. Or you could patch the source directly.

(Having applied the bad fix for now), the next error I get is when running glava --copy-config, because it expects the default config to be in /etc/xdg/glava, but it's really in /nix/store/<hash>-glava/etc/xdg/glava. You can use substituteInPlace to patch this: https://github.com/wacossusca34/glava/blob/ebade264ea1855afe88421ccc3ec22fc835696dc/glava.c#L57


fixupPhase = ''
mv $out/usr/bin $out/bin
rm -rf $out/usr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: rmdir $out/usr, since this dir is empty here

] ++ optional enableGlfw glfw;

nativeBuildInputs = [
pkgconfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builds fine without pkgconfig.

fixupPhase = ''
cp -r ${libGL}/lib $out/lib
mv $out/usr/bin $out/bin
rm -rf $out/usr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Since this directory will be empty, you can use rmdir $out/usr, also makes sure that we don't accidentally remove something in case it ever installs anything else in /usr.

@@ -0,0 +1,85 @@
{ stdenv, fetchurl, fetchFromGitHub, pkgconfig
, libGL, libX11, libXext, python3, libXrandr, libXrender, libpulseaudio, libXcomposite
, enableGlfw ? false, glfw }:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about OpenGL, but why is this disabled by default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to be a required dependency so I just left it out by default.
GLFW 3.1+ (optional, disable with DISABLE_GLFW=1)

@eadwu
Copy link
Member Author

eadwu commented Jul 4, 2018

glava --copy-config now works though the resulting directory has symlinks for its directories to /nix/store/*glava-VERSION/etc/xdg/glava

glava/bars
glava/circle
glava/graph
glava/radial
glava/util
glava/wave

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, it runs well :D

Yeah the --copy-config is a problem. I think the easiest solution would be to wrap the binary with a small shell script that catches the --copy-config flag and does its own copying of the config (with no symlinking), without passing the flag onto the actual glava executable. Feel free to create such a wrapper, but I'm fine without one.

Edit: Let me know whether you wanna try to make the wrapper or not, I'll wait with merging.

@eadwu
Copy link
Member Author

eadwu commented Jul 7, 2018

Actually that just looks like the default behavior so I'll just leave it like that.
https://github.com/wacossusca34/glava/blob/dd5586a76e5cde938558ed8a6364b24111f4b1a8/glava.c#L68

@infinisil
Copy link
Member

infinisil commented Jul 7, 2018

The problem is that the symlinks will be to /nix/store/hash-glava/... which will be garbage collected eventually, breaking the config.

@eadwu
Copy link
Member Author

eadwu commented Jul 7, 2018

Currently I have the following, though I can't seem to expand $out

  writeScript "glava" ''
    #!${stdenv.shell}
    case "$1" in
      --copy-config)
        cp -r $out/etc/xdg/glava ~/.config/glava
        ;;
      *)
        $out/usr/bin/glava $@
    esac
  ''

@eadwu
Copy link
Member Author

eadwu commented Jul 7, 2018

Ended up just replacing $out in fixupPhase

@infinisil
Copy link
Member

There are a couple things to correct again, I hope you don't mind the constant back-and-forth! Here's a patch:

diff --git a/pkgs/applications/misc/glava/default.nix b/pkgs/applications/misc/glava/default.nix
index 64bc20fc11a..d115d1ae1d2 100644
--- a/pkgs/applications/misc/glava/default.nix
+++ b/pkgs/applications/misc/glava/default.nix
@@ -30,10 +30,14 @@ let
     #!${stdenv.shell}
     case "$1" in
       --copy-config)
-        cp -r --no-preserve=all $out/etc/xdg/glava ~/.config/glava
+        # The binary would symlink it, which won't work in Nix because the
+        # garbage collector will eventually remove the original files after
+        # updates
+        echo "Nix wrapper: Copying glava config to ~/.config/glava"
+        cp -r --no-preserve=all @out@/etc/xdg/glava ~/.config/glava
         ;;
       *)
-        $out/usr/bin/glava $@
+        exec @out@/bin/.glava-unwrapped "$@"
     esac
   '';
 in
@@ -77,11 +81,14 @@ in
 
     fixupPhase = ''
       mkdir -p $out/bin
-      patchelf \
-        --set-rpath "$(patchelf --print-rpath $out/usr/bin/glava):${makeLibraryPath [ libGL ]}" \
-        $out/usr/bin/glava
-      cp ${wrapperScript} $out/bin/glava
-      substituteInPlace $out/bin/glava --replace "\$out" "$out"
+      mv $out/usr/bin/glava $out/bin/.glava-unwrapped
+      rm -rf $out/usr
+
+      patchelf $out/bin/.glava-unwrapped \
+        --set-rpath "$(patchelf --print-rpath $out/bin/.glava-unwrapped):${makeLibraryPath [ libGL ]}" \
+
+      substitute ${wrapperScript} $out/bin/glava --subst-var out
+      chmod +x $out/bin/glava
     '';
 
     meta = with stdenv.lib; {

Things to note:

  • Using @out@ in the wrapper, substituting with --subst-var out which automatically replaces it with the value of $out
  • Added comments and echo to the wrapper
  • Using exec and "$@" instead of $@ to correctly handle arguments with spaces
  • Removing $out/usr again, had to use rm -rf after all heh

@eadwu
Copy link
Member Author

eadwu commented Jul 7, 2018

It's fine, applied patch

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@infinisil infinisil merged commit 129f94f into NixOS:master Jul 7, 2018
@eadwu eadwu deleted the init/glava branch November 17, 2020 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants