Racket installation with Nix (Newbie)

Hello,

Complete noob here, learning both nix and starting racket at the same time - might not be a good idea.

I installed Racket using nix, below is my derivation to install it

let
  pkgs = import <nixpkgs> { };
in
pkgs.mkShell {
  buildInputs = [
    pkgs.racket
  ];
}

I ran racket - played around with the repl and things looked good. I ran drracket which resulted in ffi-lib error

ffi-lib: could not load foreign library
  path: libX11.6.dylib

Update my nix derivation

let
  pkgs = import <nixpkgs> { };
in
pkgs.mkShell {
  buildInputs = [
    pkgs.racket
    pkgs.xorg.libX11
    #pkgs.xorg.libX11.dev
  ];
  LD_LIBRARY_PATH="${pkgs.xorg.libX11}/lib";
}

This both installs libX11 and set up the library load path environment variable. At this point I tried drracket again with no luck - same error.

After browsing documentation and blog posts I came to the conclusion that I might need additional changes to the configuration

This is the configuration code/dictionary set up by nix when installing racket

;; generated by unixstyle-install
#hash(
      (doc-dir . "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/share/doc/racket")
      (lib-dir . "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/lib/racket")
      (pkgs-dir . "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/share/racket/pkgs")
      (share-dir . "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/share/racket")
      (include-dir . "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/include/racket")
      (bin-dir . "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/bin")
      (apps-dir . "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/share/applications")
      (man-dir . "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/share/man")
      (absolute-installation? . #t)
      (compiled-file-roots . (same "/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/lib/racket/compiled"))
      (build-stamp . "")
      (doc-search-url . "https://download.racket-lang.org/releases/8.8/doc/local-redirect/index.html")
      (catalogs . ("https://download.racket-lang.org/releases/8.8/catalog/" #f))
)

What (in) or how do I update the configuration for racket to look at environment load path?

I understand this might be a question that is more nix centric. Attempt to ask a question here because my belief that racket configuration can be updated to use the LD_LIBRARY_PATH

Thanks
-Bhaskar

Output from racket

➜  tspl git:(main) ✗ racket                                                                                                                               ~/workspace/tspl
Welcome to Racket v8.8 [cs].
> (require setup/dirs)
> (get-lib-search-dirs)
'(#<path:/Users/bhaskar/.local/share/racket/8.8/lib>
  #<path:/nix/store/pa9q13354fhxfalyvcd5hlxk4h2amv4b-racket-8.8/lib/racket>)
>

It does not see the LD_LIBRARY_PATH env var

➜  tspl git:(main) ✗ echo $LD_LIBRARY_PATH                                                                                                                ~/workspace/tspl
/nix/store/nhpjadxl9yv549hrdm2944k6mmv652vp-libX11-1.8.4/lib

I'm sorry I don't know much about Nix.

There is building guidance at 1 Building Racket from Source

I hope this helps.

Best regards,
Stephen

Thank you. I think it has more to do with how racket looks for dynamic libraries to load. I will take a look a the building from source link.

1 Like

I did get to the point that racket found the library using DYLD_LIBRARY_PATH but got a memory corruption run time error the version I had of X11 wasn't right.

At that point I was wasting time on Nix dependencies. I decide to install the from the racket distribution. For anyone who comes after me the Nix package definition for racket needs a lot more work and probably not the right place to start.

1 Like

Thanks @maddalab for this report. I've made some suggestions for the Nix package maintainers over at Racket FFI can't find external libraries · Issue #209660 · NixOS/nixpkgs · GitHub.

1 Like