summary refs log tree commit diff
path: root/pkgs/development/tools/ocaml/utop/default.nix
diff options
context:
space:
mode:
authorPatrick Mahoney <pat@polycrystal.org>2017-04-22 14:01:05 -0500
committerPatrick Mahoney <pat@polycrystal.org>2017-04-24 00:12:46 -0500
commit1a7586ce24598c03c2ab823e74e5e2413b450cdf (patch)
treef65e14772b96a3718f7f7e781b27d909d46b0649 /pkgs/development/tools/ocaml/utop/default.nix
parentd27e250627dd2f03e1436410c69b49f6463874ca (diff)
downloadnixpkgs-1a7586ce24598c03c2ab823e74e5e2413b450cdf.tar
nixpkgs-1a7586ce24598c03c2ab823e74e5e2413b450cdf.tar.gz
nixpkgs-1a7586ce24598c03c2ab823e74e5e2413b450cdf.tar.bz2
nixpkgs-1a7586ce24598c03c2ab823e74e5e2413b450cdf.tar.lz
nixpkgs-1a7586ce24598c03c2ab823e74e5e2413b450cdf.tar.xz
nixpkgs-1a7586ce24598c03c2ab823e74e5e2413b450cdf.tar.zst
nixpkgs-1a7586ce24598c03c2ab823e74e5e2413b450cdf.zip
ocamlPackages.utop: fix environment variables
In the wrapper scripts, both OCAMLPATH and CAML_LD_LIBRARY_PATH where
being created with a trailing literal $OCAMLPATH, rather than the
expanded version. Thus if, for example, ocamlPackages.core was present
in OCAMLPATH prior to running utop, the wrapper script would set the
variable to $utop_dependencies:'$OCAMLPATH', and when using utop to
open Core.Std, the following error was reported:

    findlib: [WARNING] cannot read directory $OCAMLPATH: No such file
    or directory

This patch fixes the quoting issue, and further refactors the build to
use standard wrapProgram helper, and uses an "inner derivation" to
re-use the setupHook machinery of buildOCaml and findlib instead of
manually specifying the OCAMLPATH required for utop along with
transitive dependencies.
Diffstat (limited to 'pkgs/development/tools/ocaml/utop/default.nix')
-rw-r--r--pkgs/development/tools/ocaml/utop/default.nix44
1 files changed, 31 insertions, 13 deletions
diff --git a/pkgs/development/tools/ocaml/utop/default.nix b/pkgs/development/tools/ocaml/utop/default.nix
index 31549729cfe..bec72939fa0 100644
--- a/pkgs/development/tools/ocaml/utop/default.nix
+++ b/pkgs/development/tools/ocaml/utop/default.nix
@@ -28,21 +28,39 @@ stdenv.mkDerivation rec {
   dontStrip = true;
 
   postFixup =
-   let p = p: "${p}/lib/ocaml/${ocaml.version}/site-lib"; in
-   ''
-   pushd $out/bin
-   for prog in *
+   let
+     path = "etc/utop/env";
+
+     # derivation of just runtime deps so env vars created by
+     # setup-hooks can be saved for use at runtime
+     runtime = stdenv.mkDerivation rec {
+       name = "utop-runtime-env-${version}";
+
+       buildInputs = [ findlib ] ++ propagatedBuildInputs;
+
+       phases = [ "installPhase" ];
+
+       installPhase = ''
+         mkdir -p "$out"/${path}
+         for e in OCAMLPATH CAML_LD_LIBRARY_PATH; do
+           printf %s "''${!e}" > "$out"/${path}/$e
+         done
+       '';
+     };
+
+     get = key: ''$(cat "${runtime}/${path}/${key}")'';
+   in ''
+   for prog in "$out"/bin/*
    do
-    mv $prog .$prog-wrapped
-    cat > $prog <<EOF
-#!/bin/sh
-export CAML_LD_LIBRARY_PATH=${p ocaml_lwt}/lwt:${p lambdaTerm}/lambda-term:'\$CAML_LD_LIBRARY_PATH'
-export OCAMLPATH=${p ocaml_lwt}:${p ocaml_react}:${p camomile}:${p zed}:${p lambdaTerm}:"$out"/lib/ocaml/${ocaml.version}/site-lib:'\$OCAMLPATH'
-${ocaml}/bin/ocamlrun $out/bin/.$prog-wrapped \$*
-EOF
-    chmod +x $prog
+    # Note: wrapProgram by default calls 'exec -a $0 ...', but this
+    # breaks utop on Linux with OCaml 4.04, and is disabled with
+    # '--argv0 ""' flag. See https://github.com/NixOS/nixpkgs/issues/24496
+    wrapProgram $prog \
+      --argv0 "" \
+      --prefix CAML_LD_LIBRARY_PATH ":" "${get "CAML_LD_LIBRARY_PATH"}" \
+      --prefix OCAMLPATH ":" "${get "OCAMLPATH"}" \
+      --prefix OCAMLPATH ":" $(unset OCAMLPATH; addOCamlPath "$out"; printf %s "$OCAMLPATH")
    done
-   popd
    '';
 
   meta = {