timbertson / opam2nix

Generate nix expressions from opam packages
MIT License
93 stars 28 forks source link

Set OPAM_SWITCH_PREFIX during build #88

Closed talex5 closed 1 year ago

talex5 commented 1 year ago

Dune requires this when using generated dune files with dune-lang 2.9.

Tested using this flake.nix:

{
  inputs = {
    nixpkgs.url = "nixpkgs";

    opam2nix-src = {
      url = "github:timbertson/opam2nix/v1";
      #url = "github:talex5/opam2nix/opam-switch-prefix";
      flake = false;
    };
  };

  outputs = { self, nixpkgs, opam2nix-src }:
  let
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
    opam2nix = import opam2nix-src { inherit pkgs; };
    ocaml5 = pkgs.ocaml-ng.ocamlPackages_5_0.ocaml;
    selection =
      opam2nix.build {
        ocaml = ocaml5 // { version = "5.0.0"; };
        selection = ./opam-selection.nix;
      };
  in
  {
    packages.${system}.default = selection.eio_main;
  };
}

and these commands:

opam2nix resolve --ocaml-version 5.0.0~beta1 eio_main
nix build . --impure

This fails with:

       >  + dune build -p eio -j 8 --promote-install-files=false @install
       >  + dune install -p eio --create-install-files eio
       > Error: The mandir installation directory is unknown.
       > Hint: It could be specified with --mandir
       > Command failed.

Changing the URL for opam2nix to reference this PR's branch fixes it.

( However, I'm not entirely sure that this value is correct since the build still works even if it's set to a different value. )