1{
2 lib,
3 stdenv,
4 fetchurl,
5 ocaml,
6 findlib,
7 lambda-term,
8 cppo,
9 makeWrapper,
10 buildDunePackage,
11 xdg,
12 zed,
13 logs,
14}:
15
16buildDunePackage rec {
17 pname = "utop";
18
19 version = "2.15.0";
20 propagatedBuildInputs = [
21 findlib
22 lambda-term
23 xdg
24 zed
25 logs
26 ];
27
28 minimalOCamlVersion = "4.11";
29
30 src = fetchurl {
31 url = "https://github.com/ocaml-community/utop/releases/download/${version}/utop-${version}.tar.gz";
32 hash = "sha256-dlneoKf3pbFuMAJO5oFEUXn4wPh2MOXNrlVCgNrNb6w=";
33 };
34
35 nativeBuildInputs = [
36 makeWrapper
37 cppo
38 ];
39
40 postFixup =
41 let
42 path = "etc/utop/env";
43
44 # derivation of just runtime deps so env vars created by
45 # setup-hooks can be saved for use at runtime
46 runtime = stdenv.mkDerivation {
47 pname = "utop-runtime-env";
48 inherit version;
49
50 buildInputs = [ findlib ] ++ propagatedBuildInputs;
51
52 dontUnpack = true;
53
54 installPhase = ''
55 mkdir -p "$out"/${path}
56 for e in OCAMLPATH CAML_LD_LIBRARY_PATH; do
57 [[ -v "$e" ]] || continue
58 printf %s "''${!e}" > "$out"/${path}/$e
59 done
60 '';
61 };
62
63 get = key: ''$(cat "${runtime}/${path}/${key}")'';
64 in
65 ''
66 for prog in "$out"/bin/*
67 do
68
69 # Note: wrapProgram by default calls 'exec -a $0 ...', but this
70 # breaks utop on Linux with OCaml 4.04, and is disabled with
71 # '--argv0 ""' flag. See https://github.com/NixOS/nixpkgs/issues/24496
72 wrapProgram "$prog" \
73 --argv0 "" \
74 --prefix CAML_LD_LIBRARY_PATH ":" "${get "CAML_LD_LIBRARY_PATH"}" \
75 --prefix OCAMLPATH ":" "${get "OCAMLPATH"}" \
76 --prefix OCAMLPATH ":" $(unset OCAMLPATH; addOCamlPath "$out"; printf %s "$OCAMLPATH") \
77 --add-flags "-I ${findlib}/lib/ocaml/${lib.getVersion ocaml}/site-lib"
78 done
79 '';
80
81 meta = {
82 description = "Universal toplevel for OCaml";
83 longDescription = ''
84 utop is an improved toplevel for OCaml. It can run in a terminal or in Emacs. It supports line edition, history, real-time and context sensitive completion, colors, and more.
85
86 It integrates with the tuareg mode in Emacs.
87 '';
88 homepage = "https://github.com/ocaml-community/utop";
89 changelog = "https://github.com/ocaml-community/utop/blob/${version}/CHANGES.md";
90 license = lib.licenses.bsd3;
91 platforms = ocaml.meta.platforms or [ ];
92 maintainers = [
93 lib.maintainers.gal_bolle
94 ];
95 };
96}