fractalide/racket2nix

Problem: Launcher creation isn't pure

clacke opened this issue · 2 comments

As seen in the comments to #186 , the launchers (meaning, e.g. /nix/store/[ . . . ]-racket2nix/bin/racket2nix) behave differently depending on the file system where the derivation was run. racket peeks in /bin and /usr/bin for certain tools. So in a sandbox or a NixOS, we get the absolute bindir="/nix/[ . . . ]" and on machines with a /usr/bin and coreutils, we get the dynamic script following symlinks to the launcher's directory and looking for a racket in that directory.

Solution: Either patch racket, or find the parameters that make raco pkg install always create the absolute reference.

In (make-relative-path-header) we see (equal? (car dest-explode) (car bindir-explode))), so if we could place our racket wrapper and our launcher in different derivations, that would solve the issue. I'm not sure if that's possible using raco only, because ISTR that it looks for racket in the destination directory, effectively making bindir equivalent to dest. But I may have missed something.

Ok, so in setup/setup-core.rkt we have:

                 (define aux
                   (append
                    `((exe-name . ,mzln)
                      (relative? . ,(and (cc-main? cc)
                                         (not tethered?)
                                         (not (get-absolute-installation?))))
                      (install-mode . ,(if tethered?
                                           (if user? 'addon-tethered 'config-tethered)
                                           (if (cc-main? cc) 'main 'user)))
                      ,@(build-aux-from-path
                         (build-path (cc-path cc)
                                     (path-replace-extension (or mzll mzln) #""))))))

This is the aux that is fed into make-racket-launcher, which has the:

(if as-relative?
              (make-relative-path-header dest bindir use-librktdir?)
              (make-absolute-path-header bindir))

... where as-relative? looks up relative? in the aux.

I think this means we can set the previously completely-mysterious config.rktd property absolute-installation? to #t and that solves everything.

I thought we already did. I hope not.

      (define config-rktd
        `#hash(
          (share-dir . ,(format "~a/share/racket" out))
          (lib-search-dirs . ,lib-dirs)
          (lib-dir . ,(format "~a/lib/racket" out))
          (bin-dir . ,(format "~a/bin" out))
          (absolute-installation . #t)
          (installation-name . ".")

          (links-search-files . ,(share/racket "links.rktd"))
          (pkgs-search-dirs . ,(share/racket "pkgs"))
          (collects-search-dirs . ,(share/racket "collects"))
          (doc-search-dirs . ,(share/racket "doc"))
        ))

What a difference a single question mark makes.