git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commit1a7586ce24598c03c2ab823e74e5e2413b450cdf authorPatrick Mahoney <pat@polycrystal.org> dateSat 22 Apr 2017, 14:01 (10 years ago) parentd27e250
1 file changed+31−13
pkgs/development/tools/ocaml/utop/default.nix+31−13
pkgs/development/tools/ocaml/utop/default.nix+31−13
@@ -28,21 +28,39 @@ stdenv.mkDerivation rec {
2828 dontStrip = true;
2929
3030 postFixup =
31− let p = p: "${p}/lib/ocaml/${ocaml.version}/site-lib"; in
32− ''
33− pushd $out/bin
34− for prog in *
31+ let
32+ path = "etc/utop/env";
33+
34+ # derivation of just runtime deps so env vars created by
35+ # setup-hooks can be saved for use at runtime
36+ runtime = stdenv.mkDerivation rec {
37+ name = "utop-runtime-env-${version}";
38+
39+ buildInputs = [ findlib ] ++ propagatedBuildInputs;
40+
41+ phases = [ "installPhase" ];
42+
43+ installPhase = ''
44+ mkdir -p "$out"/${path}
45+ for e in OCAMLPATH CAML_LD_LIBRARY_PATH; do
46+ printf %s "''${!e}" > "$out"/${path}/$e
47+ done
48+ '';
49+ };
50+
51+ get = key: ''$(cat "${runtime}/${path}/${key}")'';
52+ in ''
53+ for prog in "$out"/bin/*
3554 do
36− mv $prog .$prog-wrapped
37− cat > $prog <<EOF
38−#!/bin/sh
39−export CAML_LD_LIBRARY_PATH=${p ocaml_lwt}/lwt:${p lambdaTerm}/lambda-term:'\$CAML_LD_LIBRARY_PATH'
40−export OCAMLPATH=${p ocaml_lwt}:${p ocaml_react}:${p camomile}:${p zed}:${p lambdaTerm}:"$out"/lib/ocaml/${ocaml.version}/site-lib:'\$OCAMLPATH'
41−${ocaml}/bin/ocamlrun $out/bin/.$prog-wrapped \$*
42−EOF
43− chmod +x $prog
55+ # Note: wrapProgram by default calls 'exec -a $0 ...', but this
56+ # breaks utop on Linux with OCaml 4.04, and is disabled with
57+ # '--argv0 ""' flag. See https://github.com/NixOS/nixpkgs/issues/24496
58+ wrapProgram $prog \
59+ --argv0 "" \
60+ --prefix CAML_LD_LIBRARY_PATH ":" "${get "CAML_LD_LIBRARY_PATH"}" \
61+ --prefix OCAMLPATH ":" "${get "OCAMLPATH"}" \
62+ --prefix OCAMLPATH ":" $(unset OCAMLPATH; addOCamlPath "$out"; printf %s "$OCAMLPATH")
4463 done
45− popd
4664 '';
4765
4866 meta = {