janet-lang / jpm

Janet Project Manager
MIT License
70 stars 22 forks source link

Tests can't find libjanet on NixOS #88

Open na-sa-do opened 8 months ago

na-sa-do commented 8 months ago

NixOS has an unusual filesystem layout in which packages live under unique paths in /nix/store, and PATH and similar environment variables are manipulated to ensure each program can find the libraries meant for it and no others. For example, on my system ,which janet is /nix/store/n36k55y82g9qlcdxwy7v0gpjwhias7xw-janet-1.33.0/bin/janet. (If janet linked to any dynamic libraries, this would be a shell script that sets up the variables and then execs into the actual janet binary, but it doesn't so that step isn't necessary.)

Although jpm show-paths prints the correct paths, for whatever reason, when running jpm test, it defaults to /usr/local/lib/libjanet.a and fails when that file doesn't exist. Setting JANET_LIBPATH explicitly makes it work.

sogaiu commented 8 months ago

Possibly related https://github.com/janet-lang/jpm/issues/36.

whacked commented 8 months ago

I've encountered a related problem when trying to create an environment to build static binaries, discussion here. With sogaiu's help I created a working flake that bundles jpm which you can find here.

The problem with this flake is that jpm seems to want to install new packages under the same hierarchy as janet, so within the flake env, while you can run jpm, you cannot install any packages, because in the nix store, this hierarchy is read-only at runtime. In theory you could bundle all jpm packages you need at flake build time but this will be a hassle in pure builds because nix will disallow network access.

I took the easy way out now by doing sudo chmod +w against janet's store path (I use nix on Ubuntu so I don't know if this is harder on NixOS). My flake could be missing other configurations because even with JANET_LIBPATH running e.g. jpm install spork, it logs this

generating /nix/store/y2qg5yk96safcv0ig4l384vbikq4qz9i-janet-musl-with-jpm/jpm/.manifests/spork.jdn...
Installed as 'spork'.
copying spork to /nix/store/y2qg5yk96safcv0ig4l384vbikq4qz9i-janet-musl-with-jpm/jpm...
installing bin/janet-format to /bin/janet-format
error: could not open file /bin/janet-format with mode wb

so /nix/store/y2qg5yk96safcv0ig4l384vbikq4qz9i-janet-musl-with-jpm/jpm/.manifests/spork.jdn succeeds due to my chmod hack; but finally it fails because something is empty and it attempts to write to /bin/janet-format