pinpox / wallpaper-generator

Generate wallpaper images from mathematical functions
MIT License
49 stars 3 forks source link

Missing Dependencies, Generators, etc. #6

Open cyntheticfox opened 3 years ago

cyntheticfox commented 3 years ago

Adding the lgi luaPackage unfortunately does not add the required library, gobject-inspection, or the used tool, cairo. I think you need to add those to the propagatedBuildInputs.

Additionally, since you use install in your installPhase, the child objects don't get added to the derivation.

Lastly, the call to require("generators/" .. args[1]) isn't portable, since that calls from the runtime directory, instead of the current working directory.

This is a really cool project, and I'd like to use it myself, but it's missing a little. I'd recommend adding a devShell to the flake and building it as an app so you can use nix run, but those are extensions on the project.

Edit: Not sure at all about the second and third points anymore, but the first one looks to work with just buildInputs.

pinpox commented 3 years ago

Thanks, for the hints! I'll look into the points and try to make it easier to use. I'm using it myself without problems but that might be due to my specific setup. If you are more experienced with nix than me and want to give it a try, I'd also welcome PR's ;)

pinpox commented 3 years ago

I added the generators to the flake output. nix build now creates a result with the correct files. I haven't been able to fix nix run yet, keep getting this error:

(process:2139067): GLib-GObject-WARNING **: 10:24:57.368: cannot retrieve class for invalid (unclassed) type '<invalid>'

(process:2139067): GLib-GObject-WARNING **: 10:24:57.369: cannot retrieve class for invalid (unclassed) type '<invalid>'
/nix/store/j3v13kmaby3w18sb4g8xdz2qpmarvv66-lua-5.2.4/bin/lua: ...h7r2hidljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi/ffi.lua:84: bad argument #1 to 'cast' (lgi.record expected, got nil)
stack traceback:
        [C]: in function 'cast'
        ...h7r2hidljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi/ffi.lua:84: in function 'load_enum'
        ...3zn7w-lua-5.2.4-env/share/lua/5.2/lgi/override/cairo.lua:45: in main chunk
        [C]: in function 'require'
        ...dljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi/namespace.lua:183: in function <...dljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi/namespace.lua:155>
        (...tail calls...)
        ...wallpaper-generator-1.0/bin/.wallpaper-generator-wrapped:4: in main chunk
        [C]: in ?

@houstdav000 Do you have any ideas what causes this? I't running fine in the CI, but I get this error locally and can't figure out what the problem is.

cyntheticfox commented 3 years ago

That's the exact same error I kept running into and have been trying to figure out. I think it's that the runtime can't find the required C libraries from Cairo and gobject-introspection, considering the failing line is the require statement. Thing is that I'm unsure how to patch Lua require statements to get it to work, and that's what I was playing around with. Just adding the packages to the path or adding the lib folders with a fill indicator to LUA_CPATH didn't fix it, which makes me wonder if the require statements need to be rewritten to specify versions or something like that.

I tried looking at other default.nix or flake.nix files for ideas on how to solve this, but couldn't find a single other example of someone writing and packaging a custom script...

I originally got it to work when writing a devShell and invoking either main.lua or nix run from the package with that environment dynamically loaded by nix-direnv, which needs more inspection to me.

I might have some more time to look at it on Friday

pinpox commented 3 years ago

Would be really nice if you find the time, I'm at a loss here. What puzzles me even more, is that it works just fine in the CI, see here: https://drone.lounge.rocks/pinpox/wallpaper-generator/30

pinpox commented 3 years ago

I'm suspecting it is using other lua libs if they are installed on the system that don't match. I just tried it in an isolated environment and it works fine:

docker run --rm -it nixpkgs/nix-flakes bash -c "nix run "github:pinpox/wallpaper-generator" -- harmonograph"
cyntheticfox commented 2 years ago

I went to go take another look at this and it...seems to work. I do not understand why though

pinpox commented 2 years ago

I went to go take another look at this and it...seems to work. I do not understand why though

I can confirm it seems to work in a sandboxed environment (docker):

docker run --rm -it nixpkgs/nix-flakes bash -c "nix run "github:pinpox/wallpaper-generator" -- harmonograph"

But it still fails when running locally for me.

» nix run "github:pinpox/wallpaper-generator" -- harmonograph

** (process:307050): WARNING **: 09:29:52.857: Failed to load shared library '/nix/store/1pj0qrswyq0iyfa4xzqwppnfxszvh868-glib-2.70.0/lib/libgobject-2.0.so.0' referenced by the typelib: /nix/store/1pj0qrswyq0iyfa4xzqwppnfxszvh868-glib-2.70.0/lib/libgobject-2.0.so.0: undefined symbol: g_pattern_spec_copy
/nix/store/j3v13kmaby3w18sb4g8xdz2qpmarvv66-lua-5.2.4/bin/lua: ...r2hidljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi/class.lua:284: could not locate (null)(g_type_register_static): /nix/store/1pj0qrswyq0iyfa4xzqwppnfxszvh868-glib-2.70.0/lib/libgobject-2.0.so.0: undefined symbol: g_pattern_spec_copy
stack traceback:
        [C]: in function 'new'
        ...r2hidljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi/class.lua:284: in main chunk
        [C]: in function 'require'
        ...dljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi/namespace.lua:18: in main chunk
        [C]: in function 'require'
        ...7r2hidljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi/init.lua:47: in main chunk
        [C]: in function 'require'
        ...c6cqh7r2hidljs53zn7w-lua-5.2.4-env/share/lua/5.2/lgi.lua:19: in main chunk
        [C]: in function 'require'
        ...wallpaper-generator-1.0/bin/.wallpaper-generator-wrapped:2: in main chunk
        [C]: in ?
cyntheticfox commented 2 years ago

I don't know what to tell you. I'm on NixOS and everything

> nix run github:pinpox/wallpaper-generator -- harmonograph
Running generator: harmonograph
cyntheticfox commented 2 years ago

Wait, I see now, it's not using gobject-introspection, it's using glib! That must be the dependency instead

cyntheticfox commented 2 years ago

Try replacing gobject-introspection in /flake.nix with glib and lmk if that works

pinpox commented 2 years ago

Modified flake.nix like this:

diff --git a/flake.nix b/flake.nix
index 6224912..ba7c5fc 100644
--- a/flake.nix
+++ b/flake.nix
@@ -28,7 +28,8 @@
           pkgs.luaPackages.luafilesystem
           pkgs.luaPackages.argparse
           pkgs.cairo
-          pkgs.gobject-introspection
+          # pkgs.gobject-introspection
+          pkgs.glib
         ];

       in rec {

But still get the error:

✦ ×  nix run '.' -- harmonograph
warning: Git tree '/home/pinpox/code/github.com/pinpox/wallpaper-generator' is dirty

(process:325220): GLib-GObject-WARNING **: 10:45:28.860: cannot retrieve class for invalid (unclassed) type '<invalid>'

(process:325220): GLib-GObject-WARNING **: 10:45:28.863: cannot retrieve class for invalid (unclassed) type '<invalid>'
/nix/store/h7hxlq55l6v4gmxy1sx8wkllqdas0dw6-lua-5.2.4/bin/lua: ...psk3gbi0h5156p5h-lua-5.2.4-env/share/lua/5.2/lgi/ffi.lua:84: bad argument #1 to 'cast' (lgi.record expected, got nil)
stack traceback:
        [C]: in function 'cast'
        ...psk3gbi0h5156p5h-lua-5.2.4-env/share/lua/5.2/lgi/ffi.lua:84: in function 'load_enum'
        ...56p5h-lua-5.2.4-env/share/lua/5.2/lgi/override/cairo.lua:45: in main chunk
        [C]: in function 'require'
        ...i0h5156p5h-lua-5.2.4-env/share/lua/5.2/lgi/namespace.lua:183: in function <...i0h5156p5h-lua-5.2.4-env/share/lua/5.2/lgi/namespace.lua:155>
        (...tail calls...)
        ...wallpaper-generator-1.0/bin/.wallpaper-generator-wrapped:4: in main chunk
        [C]: in ?
cyntheticfox commented 2 years ago

Hmm, looking through an strace, I can see library loads from glib, libffi, cairo, and gobject-introspection. So if all of those get loaded as libraries, let me check nixpkgs a little to see what dependencies they define for cairo and gobject-introspection.

Edit: nope, gobject-introspection defines libffi and glib as propagatedBuildInputs, and hasn't changed that this year, so that should be fine...

Edit2: Looking at nix-store --query --tree ./result it shouldn't even need you to define gobject-introspection or cairo, since those are in the dependency tree... Heck, the env defined by lua-with-pkgs, you shouldn't even need to define libs or LUA_CPATH...