ocaml-community / utop

Universal toplevel for OCaml
Other
846 stars 113 forks source link

utop.el nix-shell integration #280

Open Pitometsu opened 5 years ago

Pitometsu commented 5 years ago

I trying to use utop from nix-shell environment in Emacs.

I run it like nix-shell--pure --quiet --run 'opam config exec -- dune utop . -- -emacs' $PROJECT_ROOT/shell.nix and it work in plain shell. But when I start M-x utop, I get Process utop exited with code 1. Have no idea how to debug it.

My configuration:

.dir-locals.el:

;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

((nil . ((eval . (progn
                   (setq utop-command
                         (let ((project-root
                                (or (when (require 'projectile)
                                      (projectile-project-root))
                                    (file-name-directory
                                     (let ((d (dir-locals-find-file
                                               ".")))
                                       (if (stringp d) d (car d))))
                                    (pwd))))
                           (format "nix-shell $NIX_ARGS --pure --quiet --run 'opam config exec -- dune utop . -- -emacs' %sshell.nix"
                                   project-root))))))))

shell.nix:

with import <nixpkgs> {};

let
  sandbox-exec = stdenv.mkDerivation {
    name = "sandbox-exec";
    src = /usr/bin/sandbox-exec;
    unpackPhase = "true";
    buildPhase = "true";
    installPhase = "mkdir -p $out/bin && ln -s $src $out/bin/sandbox-exec";
  };
in

stdenv.mkDerivation {
  name = "develop";
  src = if lib.inNixShell then null else ./.;

  shellHook = ''
    eval `opam env -y`
  '';

  buildInputs = with ocaml-ng.ocamlPackages_4_05; [
    opam
    ocaml
    dune
    ocamlformat
    utop
    odoc
    merlin
    ocp-indent
    gmp
    coreutils
    cacert
    gnupg
    fswatch
    m4
    pkg-config
    perl
    less
    which
    tree
    ripgrep
    gitMinimal
    ncurses
  ] ++ stdenv.lib.optional stdenv.isDarwin sandbox-exec;
}
rgrinberg commented 5 years ago

What happens when you run utop "normally" via emacs. E.g.

M-x shell-command and use echo 'print_endline "foobar"' | utop -stdin? Does utop run or does it give you an error code?