Can't install ocaml toolchains via opam

The usual way to manage an ocaml installation is via opam. I can install opam on nixos allright but when I try something like

opam switch create 4.10.0 (this is the most recent version of ocaml on nix)

I always get the same error, mutatis mutandis. The process always barfs at the sandbox.sh command seen below.

[ERROR] The compilation of ocaml-variants failed at “/home/quatrezoneilles/.opam/opam-init/hooks/sandbox.sh build make -j11 world”.

#=== ERROR while compiling ocaml-variants.4.10.2+flambda ======================#

context 2.0.7 | linux/x86_64 | | https://opam.ocaml.org#bb1ab5d2

path ~/.opam/4.10.2+flambda/.opam-switch/build/ocaml-variants.4.10.2+flambda

command ~/.opam/opam-init/hooks/sandbox.sh build make -j11 world

exit-code 1

env-file ~/.opam/log/ocaml-variants-5044-c743ac.env

output-file ~/.opam/log/ocaml-variants-5044-c743ac.out

output

I have clang with wrappers installed. I’d be grateful for any tip.

Quatrezoneilles (sorry, can’t get this to format in a non-shouty way)

I haven’t used opam on Nix yet.

Usually Nix users don’t use opam. And use Nix instead for package management, environment isolation and defining OCaml projects.

Is there a specific reason you need Opam?

On the Nix way:
Nixpkgs has OCaml packages, and you reference them in your project, just as you would with any package. And then, the OCaml package will be available to your application. Usually buildDunePackage is used to build the software. See:
https://nixos.org/manual/nixpkgs/unstable/index.html#sec-language-ocaml

If you happen to need a different OCaml compiler version, you can override it, or make a customized derivation for it.
Note: aflSupport, flambdaSupport, spaceTimeSupport are supported by using override.
https://nixos.wiki/wiki/OCaml#Specific_version_of_the_OCaml_compiler

Enabling opam in home-manager works – the configuration there is very straightforward and almost mimics the standard installation procedure (aside from the fact that opam comes from nixpkgs): home-manager/opam.nix at 888eac32bd657bfe0d024c8770130d80d1c02cd3 · nix-community/home-manager · GitHub

1 Like

So why Opam is available in nixpkgs ? Opam produces time waste and frustration here.

There are many things that come packaged in nixpkgs that won’t work without configuration.
If I just put nginx in my system packages that doesn’t just set up nginx.

nixpkgs can not concern itself with configuration so that further configuration needs to be handled by modules be it nixos for system level or home-manager for user level (or by hand)

1 Like