opam
opam copied to clipboard
depext does not support nixOS
When installing packages with opam:
[NOTE] External dependency handling not supported for OS family 'nixos'.
You can disable this check using 'opam option --global depext=false'
And system dependencies need to be manually installed.
It would be nice if opam could support nix by interacting with nix-env
or creating a local default.nix
I don’t know much about Nix but as I understand it, it wouldn’t be really useful as the path to C libraries would change all the time and opam/ocaml could store some of them.
We could change the note to encourage nixos users to use https://github.com/timbertson/opam2nix instead.
But maybe my assumptions are very wrong, as I said I don’t know Nix much. cc @timbertson @rgrinberg in case you have some inputs as Nix users.
Thanks for taking the time to respond @kit-ty-kate.
The paths to the libraries would change, but using nix-shell
in the directory with default.nix
/shell.nix
sets global flags that point to these locations.
To illustrate this with an example, ocaml-dns requires the gmp
package. Installing it globally results in it (as expected) not being found as it's in /nix/store/<hash>-gmp_<version>
.
Creating the file shell.nix
with contents:
with import <nixpkgs> {};
mkShell {
nativeBuildInputs = [
ocaml
opam
dune_2
pkg-config
gcc
bintools-unwrapped
gmp
];
}
And calling nix-shell
in the working directory sets appropriate flags like
% echo $NIX_CFLAGS_COMPILE
-frandom-seed=3ldx0bvp71 -isystem /nix/store/zlijai5jhl4z4j573h5f0y8x3apvskn2-ocaml-4.12.0/include -isystem /nix/store/5p5k86w1bvmyl2hf5l5q43c9z5ak1qrm-libev-4.33/include -isystem /nix/store/b987cpz6k72fkp05ycbhvk635y46m3cc-binutils-2.35.2/include -isystem /nix/store/9lhyw0riy5ilwmzqximjngcjrabcbfj4-gmp-6.2.1-dev/include -isystem /nix/store/zlijai5jhl4z4j573h5f0y8x3apvskn2-ocaml-4.12.0/include -isystem /nix/store/5p5k86w1bvmyl2hf5l5q43c9z5ak1qrm-libev-4.33/include -isystem /nix/store/b987cpz6k72fkp05ycbhvk635y46m3cc-binutils-2.35.2/include -isystem /nix/store/9lhyw0riy5ilwmzqximjngcjrabcbfj4-gmp-6.2.1-dev/include
So that gmp
is included when using the gcc wrapper.
This use of nix-shell
can be automated and use the existing shell with direnv.
Using opam2nix or opam-nix is good for building, but sometimes not all than convenient for developing.
Currently shell.nix
has to be manually created, but this seems like it could be trivially automated if packages are already including nixos deptexts.
It's perhaps worth noting this is the OCaml equivalent of https://nixos.org/manual/nixpkgs/stable/#how-to-consume-python-modules-using-pip-in-a-virtual-environment-like-i-am-used-to-on-other-operating-systems.
What I'm proposing is supporting this workflow from opam by automatically injecting systems dependancies into shell.nix
.