+12
-10
doc/languages-frameworks/ocaml.section.md
+12
-10
doc/languages-frameworks/ocaml.section.md
···
75
75
ppx_let,
76
76
}:
77
77
78
-
buildDunePackage rec {
78
+
buildDunePackage (finalAttrs: {
79
79
pname = "angstrom";
80
80
version = "0.15.0";
81
81
···
84
84
src = fetchFromGitHub {
85
85
owner = "inhabitedtype";
86
86
repo = "angstrom";
87
-
tag = version;
87
+
tag = finalAttrs.version;
88
88
hash = "sha256-MK8o+iPGANEhrrTc1Kz9LBilx2bDPQt7Pp5P2libucI=";
89
89
};
90
90
91
-
checkInputs = [
92
-
alcotest
93
-
ppx_let
94
-
];
95
91
buildInputs = [ ocaml-syntax-shims ];
92
+
96
93
propagatedBuildInputs = [
97
94
bigstringaf
98
95
result
99
96
];
97
+
100
98
doCheck = lib.versionAtLeast ocaml.version "4.05";
99
+
checkInputs = [
100
+
alcotest
101
+
ppx_let
102
+
];
101
103
102
104
meta = {
103
105
homepage = "https://github.com/inhabitedtype/angstrom";
···
105
107
license = lib.licenses.bsd3;
106
108
maintainers = with lib.maintainers; [ sternenseemann ];
107
109
};
108
-
}
110
+
})
109
111
```
110
112
111
113
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
119
buildDunePackage,
118
120
}:
119
121
120
-
buildDunePackage rec {
122
+
buildDunePackage (finalAtts: {
121
123
pname = "wtf8";
122
124
version = "1.0.2";
123
125
124
126
minimalOCamlVersion = "4.02";
125
127
126
128
src = fetchurl {
127
-
url = "https://github.com/flowtype/ocaml-wtf8/releases/download/v${version}/wtf8-v${version}.tbz";
129
+
url = "https://github.com/flowtype/ocaml-wtf8/releases/download/v${finalAtts.version}/wtf8-v${finalAtts.version}.tbz";
128
130
hash = "sha256-d5/3KUBAWRj8tntr4RkJ74KWW7wvn/B/m1nx0npnzyc=";
129
131
};
130
132
···
134
136
license = lib.licenses.mit;
135
137
maintainers = [ lib.maintainers.eqyiel ];
136
138
};
137
-
}
139
+
})
138
140
```
139
141
140
142
The build will automatically fail if two distinct versions of the same library
+68
-67
pkgs/build-support/ocaml/dune.nix
+68
-67
pkgs/build-support/ocaml/dune.nix
···
8
8
dune_3,
9
9
}:
10
10
11
-
{
12
-
pname,
13
-
version,
14
-
nativeBuildInputs ? [ ],
15
-
enableParallelBuilding ? true,
16
-
...
17
-
}@args:
11
+
lib.extendMkDerivation {
12
+
constructDrv = stdenv.mkDerivation;
13
+
excludeDrvArgNames = [
14
+
"minimalOCamlVersion"
15
+
"duneVersion"
16
+
];
17
+
extendDrvArgs =
18
+
finalAttrs:
19
+
{
20
+
pname,
21
+
version,
22
+
nativeBuildInputs ? [ ],
23
+
enableParallelBuilding ? true,
24
+
...
25
+
}@args:
18
26
19
-
let
20
-
Dune =
21
27
let
22
-
dune-version = args.duneVersion or "3";
28
+
Dune =
29
+
let
30
+
dune-version = args.duneVersion or "3";
31
+
in
32
+
{
33
+
"1" = dune_1;
34
+
"2" = dune_2;
35
+
"3" = dune_3;
36
+
}
37
+
."${dune-version}";
23
38
in
24
-
{
25
-
"1" = dune_1;
26
-
"2" = dune_2;
27
-
"3" = dune_3;
28
-
}
29
-
."${dune-version}";
30
-
stdenv' = args.stdenv or stdenv;
31
-
in
32
39
33
-
if args ? minimalOCamlVersion && lib.versionOlder ocaml.version args.minimalOCamlVersion then
34
-
throw "${pname}-${version} is not available for OCaml ${ocaml.version}"
35
-
else
40
+
if args ? minimalOCamlVersion && lib.versionOlder ocaml.version args.minimalOCamlVersion then
41
+
throw "${pname}-${version} is not available for OCaml ${ocaml.version}"
42
+
else
43
+
{
44
+
name = "ocaml${ocaml.version}-${pname}-${version}";
36
45
37
-
stdenv'.mkDerivation (
38
-
{
46
+
strictDeps = true;
39
47
40
-
inherit enableParallelBuilding;
41
-
dontAddStaticConfigureFlags = true;
42
-
configurePlatforms = [ ];
48
+
inherit enableParallelBuilding;
49
+
dontAddStaticConfigureFlags = true;
50
+
configurePlatforms = [ ];
43
51
44
-
buildPhase = ''
45
-
runHook preBuild
46
-
dune build -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
47
-
runHook postBuild
48
-
'';
49
-
checkPhase = ''
50
-
runHook preCheck
51
-
dune runtest -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
52
-
runHook postCheck
53
-
'';
54
-
installPhase = ''
55
-
runHook preInstall
56
-
dune install --prefix $out --libdir $OCAMLFIND_DESTDIR ${pname} \
57
-
${
58
-
if lib.versionAtLeast Dune.version "2.9" then
59
-
"--docdir $out/share/doc --mandir $out/share/man"
60
-
else
61
-
""
62
-
}
63
-
runHook postInstall
64
-
'';
52
+
nativeBuildInputs = [
53
+
ocaml
54
+
Dune
55
+
findlib
56
+
]
57
+
++ nativeBuildInputs;
65
58
66
-
strictDeps = true;
59
+
buildPhase =
60
+
args.buildPhase or ''
61
+
runHook preBuild
62
+
dune build -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
63
+
runHook postBuild
64
+
'';
67
65
68
-
}
69
-
// (builtins.removeAttrs args [
70
-
"minimalOCamlVersion"
71
-
"duneVersion"
72
-
])
73
-
// {
66
+
installPhase =
67
+
args.installPhase or ''
68
+
runHook preInstall
69
+
dune install --prefix $out --libdir $OCAMLFIND_DESTDIR ${pname} \
70
+
${
71
+
if lib.versionAtLeast Dune.version "2.9" then
72
+
"--docdir $out/share/doc --mandir $out/share/man"
73
+
else
74
+
""
75
+
}
76
+
runHook postInstall
77
+
'';
74
78
75
-
name = "ocaml${ocaml.version}-${pname}-${version}";
79
+
checkPhase =
80
+
args.checkPhase or ''
81
+
runHook preCheck
82
+
dune runtest -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
83
+
runHook postCheck
84
+
'';
76
85
77
-
nativeBuildInputs = [
78
-
ocaml
79
-
Dune
80
-
findlib
81
-
]
82
-
++ nativeBuildInputs;
83
-
84
-
meta = (args.meta or { }) // {
85
-
platforms = args.meta.platforms or ocaml.meta.platforms;
86
+
meta = (args.meta or { }) // {
87
+
platforms = args.meta.platforms or ocaml.meta.platforms;
88
+
};
86
89
};
87
-
88
-
}
89
-
)
90
+
}