tweag / opam-nix

Turn opam-based OCaml projects into Nix derivations
MIT License
111 stars 33 forks source link

Add the ability to override the default build command #5

Closed rizo closed 2 years ago

rizo commented 2 years ago

Is your feature request related to a problem? Please describe. Dune supports different build envs that can be used to pass custom compiler flags during compilation. Currently the installation will use the build attribute found in the opam file by default and there is no way to provide an alternative build command (to use a custom env for example).

Describe the solution you'd like After creating a scope I would like to be able to override the build attribute for my package.

Currently the following does not work and still uses the build command from the opam file:

let
  scope = opam-nix.lib.${pkgs.system}.buildOpamProject {
    inherit pkgs;
  } "my_project" src { ocaml-system = null; };

  overlay = self: super: {
    my_project = super.my_project.overrideAttrs (oa: { build = [ "xxx" ]; });
  };
in
(scope.overrideScope' overlay).my_project

Describe alternatives you've considered Alternatively maybe there is a way to adapt buildDuneProject to allow passing a custom build argument.

balsoft commented 2 years ago

Packages in the scope are just regular nixpkgs stdenv derivations, with mostly standard phase names. So you can do something like this:

let
  scope = opam-nix.lib.${pkgs.system}.buildOpamProject {
    inherit pkgs;
  } "my_project" src { ocaml-system = null; };

  overlay = self: super: {
    my_project = super.my_project.overrideAttrs (oa: { buildPhase = "xxx"; });
  };
in
(scope.overrideScope' overlay).my_project

This is documented in the readme: https://github.com/tweag/opam-nix#package

rizo commented 2 years ago

That makes sense, thanks. I thought the buildPhase was internally more complicated than just calling opam's build.