Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depext does not support nixOS #5124

Open
RyanGibb opened this issue Apr 21, 2022 · 3 comments
Open

depext does not support nixOS #5124

RyanGibb opened this issue Apr 21, 2022 · 3 comments

Comments

@RyanGibb
Copy link
Contributor

RyanGibb commented Apr 21, 2022

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/shell.nix

@dra27 dra27 changed the title deptext does not support nixOS depext does not support nixOS Apr 28, 2022
@kit-ty-kate
Copy link
Member

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.

@RyanGibb
Copy link
Contributor Author

RyanGibb commented May 6, 2022

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.

@RyanGibb
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants