From 1a7586ce24598c03c2ab823e74e5e2413b450cdf Mon Sep 17 00:00:00 2001 From: Patrick Mahoney Date: Sat, 22 Apr 2017 14:01:05 -0500 Subject: [PATCH] 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. --- pkgs/development/tools/ocaml/utop/default.nix | 44 +++++++++++++------ 1 file 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 <