Unverified Commit 69d2b0d7 authored by Vincent Laporte's avatar Vincent Laporte Committed by GitHub
Browse files

ocamlPackages.buildDunePackage: support fixed point args with `lib.extendMkDerivation` (#446007)

parents e90c49cc cb98bc06
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ Here is a simple package example.
  ppx_let,
}:

buildDunePackage rec {
buildDunePackage (finalAttrs: {
  pname = "angstrom";
  version = "0.15.0";

@@ -84,20 +84,22 @@ buildDunePackage rec {
  src = fetchFromGitHub {
    owner = "inhabitedtype";
    repo = "angstrom";
    tag = version;
    tag = finalAttrs.version;
    hash = "sha256-MK8o+iPGANEhrrTc1Kz9LBilx2bDPQt7Pp5P2libucI=";
  };

  checkInputs = [
    alcotest
    ppx_let
  ];
  buildInputs = [ ocaml-syntax-shims ];

  propagatedBuildInputs = [
    bigstringaf
    result
  ];

  doCheck = lib.versionAtLeast ocaml.version "4.05";
  checkInputs = [
    alcotest
    ppx_let
  ];

  meta = {
    homepage = "https://github.com/inhabitedtype/angstrom";
@@ -105,7 +107,7 @@ buildDunePackage rec {
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [ sternenseemann ];
  };
}
})
```

Here is a second example, this time using a source archive generated with `dune-release`. It is a good idea to use this archive when it is available as it will usually contain substituted variables such as a `%%VERSION%%` field. This library does not depend on any other OCaml library and no tests are run after building it.
@@ -117,14 +119,14 @@ Here is a second example, this time using a source archive generated with `dune-
  buildDunePackage,
}:

buildDunePackage rec {
buildDunePackage (finalAtts: {
  pname = "wtf8";
  version = "1.0.2";

  minimalOCamlVersion = "4.02";

  src = fetchurl {
    url = "https://github.com/flowtype/ocaml-wtf8/releases/download/v${version}/wtf8-v${version}.tbz";
    url = "https://github.com/flowtype/ocaml-wtf8/releases/download/v${finalAtts.version}/wtf8-v${finalAtts.version}.tbz";
    hash = "sha256-d5/3KUBAWRj8tntr4RkJ74KWW7wvn/B/m1nx0npnzyc=";
  };

@@ -134,7 +136,7 @@ buildDunePackage rec {
    license = lib.licenses.mit;
    maintainers = [ lib.maintainers.eqyiel ];
  };
}
})
```

The build will automatically fail if two distinct versions of the same library
+68 −67
Original line number Diff line number Diff line
@@ -8,6 +8,14 @@
  dune_3,
}:

lib.extendMkDerivation {
  constructDrv = stdenv.mkDerivation;
  excludeDrvArgNames = [
    "minimalOCamlVersion"
    "duneVersion"
  ];
  extendDrvArgs =
    finalAttrs:
    {
      pname,
      version,
@@ -27,31 +35,36 @@ let
          "3" = dune_3;
        }
        ."${dune-version}";
  stdenv' = args.stdenv or stdenv;
    in

    if args ? minimalOCamlVersion && lib.versionOlder ocaml.version args.minimalOCamlVersion then
      throw "${pname}-${version} is not available for OCaml ${ocaml.version}"
    else

  stdenv'.mkDerivation (
      {
        name = "ocaml${ocaml.version}-${pname}-${version}";

        strictDeps = true;

        inherit enableParallelBuilding;
        dontAddStaticConfigureFlags = true;
        configurePlatforms = [ ];

      buildPhase = ''
        nativeBuildInputs = [
          ocaml
          Dune
          findlib
        ]
        ++ nativeBuildInputs;

        buildPhase =
          args.buildPhase or ''
            runHook preBuild
            dune build -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
            runHook postBuild
          '';
      checkPhase = ''
        runHook preCheck
        dune runtest -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
        runHook postCheck
      '';
      installPhase = ''

        installPhase =
          args.installPhase or ''
            runHook preInstall
            dune install --prefix $out --libdir $OCAMLFIND_DESTDIR ${pname} \
             ${
@@ -63,27 +76,15 @@ else
            runHook postInstall
          '';

      strictDeps = true;

    }
    // (builtins.removeAttrs args [
      "minimalOCamlVersion"
      "duneVersion"
    ])
    // {

      name = "ocaml${ocaml.version}-${pname}-${version}";

      nativeBuildInputs = [
        ocaml
        Dune
        findlib
      ]
      ++ nativeBuildInputs;
        checkPhase =
          args.checkPhase or ''
            runHook preCheck
            dune runtest -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
            runHook postCheck
          '';

        meta = (args.meta or { }) // {
          platforms = args.meta.platforms or ocaml.meta.platforms;
        };

      };
}
  )
+4 −4
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
  yojson,
}:

buildDunePackage rec {
buildDunePackage (finalAttrs: {
  pname = "linol";
  version = "0.10";

@@ -18,7 +18,7 @@ buildDunePackage rec {
  src = fetchFromGitHub {
    owner = "c-cube";
    repo = "linol";
    tag = "v${version}";
    tag = "v${finalAttrs.version}";
    hash = "sha256-G/5nTJd+MxPgNObKW2Hmmwn4HejQ81c3f4oVXjpNSZg=";
  };

@@ -33,11 +33,11 @@ buildDunePackage rec {
  meta = {
    description = "LSP server library";
    homepage = "https://github.com/c-cube/linol";
    changelog = "https://raw.githubusercontent.com/c-cube/linol/refs/tags/v${version}/CHANGES.md";
    changelog = "https://raw.githubusercontent.com/c-cube/linol/refs/tags/v${finalAttrs.version}/CHANGES.md";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [
      stepbrobd
      ulrikstrid
    ];
  };
}
})