on iko/ghcjs-patch-master help sign in
reinstallable lib:ghc and option inheritance (#88)
0de60e8Moritz Angermann
@@ -13,7 +13,10 @@ let
13 # up much later on hackage; but are not installable
13 # up much later on hackage; but are not installable
14 # anyway. Therefore we just strip them out of the
14 # anyway. Therefore we just strip them out of the
15 # pkg-def's packages.
15 # pkg-def's packages.
16+ #
17+ # Note: these will need to be provided by alternative
18+ # means outside of hackage.
16− boot-pkgs = [ "rts" "ghc" "ghci" "ghc-boot" "ghc-boot-th"
19+ boot-pkgs = [ "rts" "ghc" "ghc-boot-th" "ghc-boot" "ghci"
17 "ghc-heap" # since ghc 8.6.
20 "ghc-heap" # since ghc 8.6.
18 ];
21 ];
19 strip-pkg-def = pkgs: pkg-def: hackage: with pkgs.lib;
22 strip-pkg-def = pkgs: pkg-def: hackage: with pkgs.lib;
modules/component-driver.nix+20−2
@@ -23,9 +23,27 @@ in
23 type = lib.types.listOf lib.types.str;
23 type = lib.types.listOf lib.types.str;
24 };
24 };
25
25
26+ # Dependencies
27+ #
28+ # .--------. .------------------.
29+ # | pretty | < ------- | template-haskell |
30+ # '--------' '------------------'
31+ # v |
32+ # .---------. .-------. |
33+ # | deepseq | - > | array | |
34+ # '---------' '-------' v
35+ # v v .-------------.
36+ # .----------. .----------. .------. .- | ghc-boot-th |
37+ # | ghc-heap | | ghc-prim | | base |< -' '-------------'
38+ # '----------' '----------' '------' .----------------.
39+ # | v | | | integer-simple |
40+ # | .-----. | '-- > |-------or-------|
41+ # '---- > | rts | < -----' | integer-gmp |
42+ # '-----' '----------------'
43+
26 config.nonReinstallablePkgs =
44 config.nonReinstallablePkgs =
27− [ "rts" "ghc" "ghc-prim" "integer-gmp" "integer-simple" "base"
45+ [ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
28− "array" "deepseq" "pretty" "ghc-boot-th" "template-haskell" "ghc-heap" ];
46+ "deepseq" "array" "ghc-boot-th" "pretty" "template-haskell" ];
29
47
30 options.hsPkgs = lib.mkOption {
48 options.hsPkgs = lib.mkOption {
31 type = lib.types.unspecified;
49 type = lib.types.unspecified;
modules/package.nix+6−149
@@ -13,39 +13,22 @@
13# tests = { "..." = { depends = ... }; ... };
13# tests = { "..." = { depends = ... }; ... };
14# };
14# };
15
15
16+{ parentConfig, mod_args, listOfFilteringNulls, componentOptions, packageOptions }:
16{ lib, config, pkgs, haskellLib, ... }:
17{ lib, config, pkgs, haskellLib, ... }:
17
18
18with lib;
19with lib;
19with types;
20with types;
20
21
21−let
22− # This is just like listOf, except that it filters out all null elements.
23− listOfFilteringNulls = elemType: listOf elemType // {
24− # Mostly copied from nixpkgs/lib/types.nix
25− merge = loc: defs:
26− map (x: x.value) (filter (x: x ? value && x.value != null) (concatLists (imap1 (n: def:
27− if isList def.value then
28− imap1 (m: def':
29− (mergeDefinitions
30− (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
31− elemType
32− [{ inherit (def) file; value = def'; }]
33− ).optionalValue
34− ) def.value
35− else
36− throw "The option value `${showOption loc}` in `${def.file}` is not a list.") defs)));
37− };
38−in {
22+{
39 # This is how the Nix expressions generated by *-to-nix receive
23 # This is how the Nix expressions generated by *-to-nix receive
40 # their flags argument.
24 # their flags argument.
41− config._module.args.flags = config.flags;
25+ config._module.args = mod_args // { flags = config.flags; };
42
26
43− options = {
27+ options = (packageOptions parentConfig) // {
44 # TODO: Add descriptions to everything.
28 # TODO: Add descriptions to everything.
45 flags = mkOption {
29 flags = mkOption {
46 type = attrsOf bool;
30 type = attrsOf bool;
47 };
31 };
48−
49 package = {
32 package = {
50 specVersion = mkOption {
33 specVersion = mkOption {
51 type = str;
34 type = str;
@@ -98,7 +81,8 @@ in {
98
81
99 components = let
82 components = let
100 componentType = submodule {
83 componentType = submodule {
101− options = {
84+ # add the shared componentOptions
85+ options = (componentOptions config) // {
102 depends = mkOption {
86 depends = mkOption {
103 type = listOfFilteringNulls unspecified;
87 type = listOfFilteringNulls unspecified;
104 default = [];
88 default = [];
@@ -119,43 +103,6 @@ in {
119 type = listOfFilteringNulls unspecified;
103 type = listOfFilteringNulls unspecified;
120 default = [];
104 default = [];
121 };
105 };
122− configureFlags = mkOption {
123− type = listOfFilteringNulls str;
124− default = config.configureFlags;
125− };
126− setupBuildFlags = mkOption {
127− type = listOfFilteringNulls str;
128− default = config.setupBuildFlags;
129− };
130− setupTestFlags = mkOption {
131− type = listOfFilteringNulls str;
132− default = config.setupTestFlags;
133− };
134− setupInstallFlags = mkOption {
135− type = listOfFilteringNulls str;
136− default = config.setupInstallFlags;
137− };
138− setupHaddockFlags = mkOption {
139− type = listOfFilteringNulls str;
140− default = config.setupHaddockFlags;
141− };
142− doExactConfig = mkOption {
143− type = bool;
144− default = config.doExactConfig;
145− };
146− doCheck = mkOption {
147− type = bool;
148− default = config.doCheck;
149− };
150− doCrossCheck = mkOption {
151− type = bool;
152− default = config.doCrossCheck;
153− };
154− doHaddock = mkOption {
155− description = "Enable building of the Haddock documentation from the annotated Haskell source code.";
156− type = bool;
157− default = config.doHaddock;
158− };
159 };
106 };
160 };
107 };
161 in {
108 in {
@@ -224,96 +171,6 @@ in {
224 type = listOf (either unspecified path);
171 type = listOf (either unspecified path);
225 default = [];
172 default = [];
226 };
173 };
227− configureFlags = mkOption {
228− type = listOfFilteringNulls str;
229− default = [];
230− };
231− setupBuildFlags = mkOption {
232− type = listOfFilteringNulls str;
233− default = [];
234− };
235− setupTestFlags = mkOption {
236− type = listOfFilteringNulls str;
237− default = [];
238− };
239− setupInstallFlags = mkOption {
240− type = listOfFilteringNulls str;
241− default = [];
242− };
243− setupHaddockFlags = mkOption {
244− type = listOfFilteringNulls str;
245− default = [];
246− };
247− preUnpack = mkOption {
248− type = nullOr lines;
249− default = null;
250− };
251− postUnpack = mkOption {
252− type = nullOr string;
253− default = null;
254− };
255− preConfigure = mkOption {
256− type = nullOr string;
257− default = null;
258− };
259− postConfigure = mkOption {
260− type = nullOr string;
261− default = null;
262− };
263− preBuild = mkOption {
264− type = nullOr string;
265− default = null;
266− };
267− postBuild = mkOption {
268− type = nullOr string;
269− default = null;
270− };
271− preCheck = mkOption {
272− type = nullOr string;
273− default = null;
274− };
275− postCheck = mkOption {
276− type = nullOr string;
277− default = null;
278− };
279− preInstall = mkOption {
280− type = nullOr string;
281− default = null;
282− };
283− postInstall = mkOption {
284− type = nullOr string;
285− default = null;
286− };
287− preHaddock = mkOption {
288− type = nullOr string;
289− default = null;
290− };
291− postHaddock = mkOption {
292− type = nullOr string;
293− default = null;
294− };
295− shellHook = mkOption {
296− type = nullOr string;
297− default = null;
298− };
299− doExactConfig = mkOption {
300− type = bool;
301− default = false;
302− };
303− doCheck = mkOption {
304− type = bool;
305− default = false;
306− };
307− doCrossCheck = mkOption {
308− description = "Run doCheck also in cross compilation settings. This can be tricky as the test logic must know how to run the tests on the target.";
309− type = bool;
310− default = false;
311− };
312− doHaddock = mkOption {
313− description = "Enable building of the Haddock documentation from the annotated Haskell source code.";
314− type = bool;
315− default = true;
316− };
317 };
174 };
318
175
319 # This has one quirk. Manually setting options on the all component
176 # This has one quirk. Manually setting options on the all component
modules/plan.nix+129−7
@@ -15,17 +15,139 @@
15with lib;
15with lib;
16with types;
16with types;
17
17
18−{
18+
19+let
20+ # This is just like listOf, except that it filters out all null elements.
21+ listOfFilteringNulls = elemType: listOf elemType // {
22+ # Mostly copied from nixpkgs/lib/types.nix
23+ merge = loc: defs:
24+ map (x: x.value) (filter (x: x ? value && x.value != null) (concatLists (imap1 (n: def:
25+ if isList def.value then
26+ imap1 (m: def':
27+ (mergeDefinitions
28+ (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
29+ elemType
30+ [{ inherit (def) file; value = def'; }]
31+ ).optionalValue
32+ ) def.value
33+ else
34+ throw "The option value `${showOption loc}` in `${def.file}` is not a list.") defs)));
35+ };
36+
37+ componentOptions = def: {
38+ configureFlags = mkOption {
39+ type = listOfFilteringNulls str;
40+ default = (def.configureFlags or []);
41+ };
42+ setupBuildFlags = mkOption {
43+ type = listOfFilteringNulls str;
44+ default = (def.setupBuildFlags or []);
45+ };
46+ setupTestFlags = mkOption {
47+ type = listOfFilteringNulls str;
48+ default = (def.setupTestFlags or []);
49+ };
50+ setupInstallFlags = mkOption {
51+ type = listOfFilteringNulls str;
52+ default = (def.setupInstallFlags or []);
53+ };
54+ setupHaddockFlags = mkOption {
55+ type = listOfFilteringNulls str;
56+ default = (def.setupHaddockFlags or []);
57+ };
58+ doExactConfig = mkOption {
59+ type = bool;
60+ default = (def.doExactConfig or false);
61+ };
62+ doCheck = mkOption {
63+ type = bool;
64+ default = (def.doCheck or false);
65+ };
66+ doCrossCheck = mkOption {
67+ description = "Run doCheck also in cross compilation settings. This can be tricky as the test logic must know how to run the tests on the target.";
68+ type = bool;
69+ default = (def.doCrossCheck or false);
70+ };
71+ doHaddock = mkOption {
72+ description = "Enable building of the Haddock documentation from the annotated Haskell source code.";
73+ type = bool;
74+ default = (def.doHaddock or true);
75+ };
76+ };
77+ packageOptions = def: componentOptions def // {
78+ preUnpack = mkOption {
79+ type = nullOr lines;
80+ default = (def.preUnpack or null);
81+ };
82+ postUnpack = mkOption {
83+ type = nullOr string;
84+ default = (def.postUnpack or null);
85+ };
86+ preConfigure = mkOption {
87+ type = nullOr string;
88+ default = (def.preConfigure or null);
89+ };
90+ postConfigure = mkOption {
91+ type = nullOr string;
92+ default = (def.postConfigure or null);
93+ };
94+ preBuild = mkOption {
95+ type = nullOr string;
96+ default = (def.preBuild or null);
97+ };
98+ postBuild = mkOption {
99+ type = nullOr string;
100+ default = (def.postBuild or null);
101+ };
102+ preCheck = mkOption {
103+ type = nullOr string;
104+ default = (def.preCheck or null);
105+ };
106+ postCheck = mkOption {
107+ type = nullOr string;
108+ default = (def.postCheck or null);
109+ };
110+ preInstall = mkOption {
111+ type = nullOr string;
112+ default = (def.preInstall or null);
113+ };
114+ postInstall = mkOption {
115+ type = nullOr string;
116+ default = (def.postInstall or null);
117+ };
118+ preHaddock = mkOption {
119+ type = nullOr string;
120+ default = (def.preHaddock or null);
121+ };
122+ postHaddock = mkOption {
123+ type = nullOr string;
124+ default = (def.postHaddock or null);
125+ };
126+ shellHook = mkOption {
127+ type = nullOr string;
128+ default = (def.shellHook or null);
129+ };
130+ };
131+
132+
133+in {
134+ # Global options. These are passed down to the package level, and from there to the
135+ # component level, unless specifically overridden. Depending on the flag flags are
136+ # combined or replaced. We seed the package Options with an empty set forcing the
137+ # default values.
19− options = {
138+ options = (packageOptions {}) // {
20 packages = mkOption {
139 packages = mkOption {
21− type = attrsOf (submodule {
140+ type =
22− imports = [./package.nix];
141+ let mod_args = {
23− _module.args = {
24 inherit pkgs pkgconfPkgs haskellLib;
142 inherit pkgs pkgconfPkgs haskellLib;
25 inherit (config) hsPkgs;
143 inherit (config) hsPkgs;
26 inherit (config.cabal) system compiler;
144 inherit (config.cabal) system compiler;
27− };
145+ }; in
146+ attrsOf (submodule (import ./package.nix {
147+ inherit mod_args listOfFilteringNulls;
148+ inherit componentOptions packageOptions;
149+ parentConfig = config;
28− });
150+ }));
29 };
151 };
30
152
31 compiler = {
153 compiler = {