timbertson / opam2nix

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

handling ocamlbuild projects #42

Closed joprice closed 3 years ago

joprice commented 3 years ago

I'm interested in building https://github.com/dbuenzli/brr, but I get the following error:

Fatal error: exception Failure("Invalid character in package name \"/nix/store/y6dkmsma2si9nnmkgarxkis05n0m64x3-source/opam\"")

I think this is because it uses ocamlbuild, and the opam file does not in include the name of the project. Is there a way to handle this with the current rules?

joprice commented 3 years ago

I was able to build this as follows:

{
   noteSrc = fetchFromGitHub {
      owner = "dbuenzli";
      repo = "note";
      rev = "e3ed0b0725e4fcd6ebbf07dd1cd37733b301f239";
      sha256 = "1ggycmjxx672in0zzrffw0cv7i99176z5h53k9qfsh586n2kqdsc";
    };
    note = stdenv.mkDerivation {
      name = "note";
      src = noteSrc;
      inherit (ocamlPackages.topkg) installPhase;
      buildPhase = "${ocamlPackages.topkg.run} build --tests true";
      buildInputs = with ocamlPackages; [
        ocaml
        selection.topkg
        selection.ocamlfind
        selection.ocamlbuild
      ];
    };
    brrSrc = fetchFromGitHub {
      owner = "dbuenzli";
      repo = "brr";
      rev = "89b395269d96a3b6c5d697fcde5737fe37001b9f";
      sha256 = "1x3m6vfcblq5xlmwlir45b67p7npz0ha9lv3f17xrnv4zji49ngn";
    };
    brr = stdenv.mkDerivation {
      name = "brr";
      src = brrSrc;
      inherit (ocamlPackages.topkg) installPhase;
      buildPhase = "${ocamlPackages.topkg.run} build --tests true";
      buildInputs = with ocamlPackages; [
        note
        ocaml
        selection.js_of_ocaml
        selection.js_of_ocaml-toplevel
        selection.topkg
        selection.ocamlfind
        selection.ocamlbuild
      ];
    };
   args = {
      inherit ocaml;
      selection = ./opam-selection.nix;
      src = {
        brr-test = ../.;
      };
      override = {}: {
        brr-test = super: super.overrideAttrs (super: {
          buildInputs = (super.buildInputs or [ ]) ++ [ brr ];
        });
      };
    };
}