NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.3k stars 13.54k forks source link

Ocaml dune and dune subpackages coherence #164287

Open AllanBlanchard opened 2 years ago

AllanBlanchard commented 2 years ago
Checklist
Project name

Currently, it seems to me that there is no way to build a package that requires both Dune 3 and dune-site.

Notify maintainers

maintainers: @vbgl @marsam

Note for maintainers

Please tag this issue in your PR.

AllanBlanchard commented 2 years ago

Ok it probably a bit hackish, but the following files/configurations allowed me to get a Dune 3 environment. I am not really familiar with Nix so it might be awful, but hey, it works for me.

dune-packages.zip

with the following overlay

let
  sources = import ./sources.nix {}; # links to some packages sources
  ocamlOverlay = oself: osuper: {
    # Nix + Dune 3
    dune-build-3 =
      osuper.buildDunePackage.override {
        dune_2 = oself.dune_3;
      };
    dune-ordering-3 =
      oself.callPackage ./dune-ordering.nix {
        dune_2 = oself.dune_3;
        buildDunePackage = oself.dune-build-3;
      };
    dune-dyn-3 =
      oself.callPackage ./dune-dyn.nix {
        dune_2 = oself.dune_3;
        buildDunePackage = oself.dune-build-3;
        dune-ordering = oself.dune-ordering-3;
      };
    dune-stdune-3 =
      oself.callPackage ./dune-stdune.nix {
        dune_2 = oself.dune_3;
        buildDunePackage = oself.dune-build-3;
        dune-ordering = oself.dune-ordering-3;
        dune-dyn = oself.dune-dyn-3;
      };
    dune-private-libs-3 =
      oself.callPackage ./dune-private-libs.nix {
        dune_2 = oself.dune_3;
        buildDunePackage = oself.dune-build-3;
        dune-ordering = oself.dune-ordering-3;
        dune-stdune = oself.dune-stdune-3;
        dune-dyn = oself.dune-dyn-3;
      };
    dune-site-3 =
      osuper.dune-site.override {
        dune_2 = oself.dune_3;
        buildDunePackage = oself.dune-build-3;
        dune-private-libs = oself.dune-private-libs-3;
      };
  };
  overlay = self: super: {
    niv = (import sources.niv {}).niv;
    ocaml-ng = super.lib.mapAttrs (
      name: value:
        if builtins.hasAttr "overrideScope'" value
        then value.overrideScope' ocamlOverlay
        else value
    ) super.ocaml-ng;
    inherit (super.callPackage sources."gitignore.nix" {}) gitignoreSource;
  };
  pkgs = import sources.nixpkgs {
    config.allowUnfree = true;
    overlays = [ overlay ];
  };
in
pkgs