diff options
Diffstat (limited to 'pkgs/development/tools/ocaml/utop/default.nix')
-rw-r--r-- | pkgs/development/tools/ocaml/utop/default.nix | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/pkgs/development/tools/ocaml/utop/default.nix b/pkgs/development/tools/ocaml/utop/default.nix index 31549729cfe7..8ab1371af9cb 100644 --- a/pkgs/development/tools/ocaml/utop/default.nix +++ b/pkgs/development/tools/ocaml/utop/default.nix @@ -1,5 +1,5 @@ -{ stdenv, fetchurl, ocaml, findlib, ocamlbuild, camlp4, ocaml_react -, lambdaTerm, ocaml_lwt, makeWrapper, camomile, zed, cppo, ppx_tools +{ stdenv, fetchurl, bash, ocaml, findlib, ocamlbuild, camlp4, ocaml_react +, lambdaTerm, ocaml_lwt, camomile, zed, cppo, ppx_tools }: stdenv.mkDerivation rec { @@ -11,7 +11,7 @@ stdenv.mkDerivation rec { sha256 = "16z02vp9n97iax4fqpbi7v86r75vbabxvnd1rirh8w2miixs1g4x"; }; - buildInputs = [ ocaml findlib ocamlbuild makeWrapper cppo camlp4 ppx_tools ]; + buildInputs = [ ocaml findlib ocamlbuild cppo camlp4 ppx_tools ]; propagatedBuildInputs = [ lambdaTerm ocaml_lwt ]; @@ -28,21 +28,41 @@ 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 = { |