Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions doc/languages-frameworks/ocaml.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Here is a simple package example.
ppx_let,
}:

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

Expand All @@ -84,28 +84,30 @@ 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";
description = "OCaml parser combinators built for speed and memory efficiency";
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.
Expand All @@ -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=";
};

Expand All @@ -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
Expand Down
135 changes: 68 additions & 67 deletions pkgs/build-support/ocaml/dune.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,82 +8,83 @@
dune_3,
}:

{
pname,
version,
nativeBuildInputs ? [ ],
enableParallelBuilding ? true,
...
}@args:
lib.extendMkDerivation {
constructDrv = stdenv.mkDerivation;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i haven't figure out with a way to replicate this behavior (stdenv' = args.stdenv or stdenv;) without adding another argument above lib.extendMkDerivation, but it seems that no in-tree code depends on this...

i personally think it'd be fine leaving this as is

excludeDrvArgNames = [
"minimalOCamlVersion"
"duneVersion"
];
Comment on lines +13 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why these have been excluded? it could be useful to know and access this information.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is meta-data that MUST NOT affect the hash.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. What about inheriting them in passthru similar to what the python builder does?

extendDrvArgs =
finalAttrs:
{
pname,
version,
nativeBuildInputs ? [ ],
enableParallelBuilding ? true,
...
}@args:

let
Dune =
let
dune-version = args.duneVersion or "3";
Dune =
let
dune-version = args.duneVersion or "3";
in
{
"1" = dune_1;
"2" = dune_2;
"3" = dune_3;
}
."${dune-version}";
in
{
"1" = dune_1;
"2" = dune_2;
"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
if args ? minimalOCamlVersion && lib.versionOlder ocaml.version args.minimalOCamlVersion then
throw "${pname}-${version} is not available for OCaml ${ocaml.version}"
else
{
name = "ocaml${ocaml.version}-${pname}-${version}";

stdenv'.mkDerivation (
{

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

buildPhase = ''
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 = ''
runHook preInstall
dune install --prefix $out --libdir $OCAMLFIND_DESTDIR ${pname} \
${
if lib.versionAtLeast Dune.version "2.9" then
"--docdir $out/share/doc --mandir $out/share/man"
else
""
}
runHook postInstall
'';
inherit enableParallelBuilding;
dontAddStaticConfigureFlags = true;
configurePlatforms = [ ];

strictDeps = true;
nativeBuildInputs = [
ocaml
Dune
findlib
]
++ nativeBuildInputs;

}
// (builtins.removeAttrs args [
"minimalOCamlVersion"
"duneVersion"
])
// {
buildPhase =
args.buildPhase or ''
runHook preBuild
dune build -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postBuild
'';

name = "ocaml${ocaml.version}-${pname}-${version}";
installPhase =
args.installPhase or ''
runHook preInstall
dune install --prefix $out --libdir $OCAMLFIND_DESTDIR ${pname} \
${
if lib.versionAtLeast Dune.version "2.9" then
"--docdir $out/share/doc --mandir $out/share/man"
else
""
}
runHook postInstall
'';

nativeBuildInputs = [
ocaml
Dune
findlib
]
++ nativeBuildInputs;
checkPhase =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried defaulting doCheck to true but some pkgs failed to build

might need to set it to false explicitly in those pkgs before defaulting this to true here

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;
meta = (args.meta or { }) // {
platforms = args.meta.platforms or ocaml.meta.platforms;
};
};

}
)
}
8 changes: 4 additions & 4 deletions pkgs/development/ocaml-modules/linol/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
yojson,
}:

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

Expand All @@ -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=";
};

Expand All @@ -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
];
};
}
})
Loading