on f413621 help sign in
277 lines 10 kB history raw
1# The plan (that is, a package set description like an LTS set or a
2# plan.nix (derived from plan.json)) will producde a structure that
3# looks like, which is stored in config.plan.pkg-def:
4#
5# { packages = { "package" = { revision = hackageConfigs.$package.$version.revisions.default;
6# flags = { flag1 = true; flag2 = false; ... }; };
7# ... };
8# compiler = { version = "X.Y.Z"; nix-name ="ghcXYZ";
9# # packages that come bundled with the compiler
10# packages = { "bytestring" = "a.b.c.d"; ... }; };
11# }
13{ lib, config, pkgs, pkgconfPkgs, haskellLib, ... }:
15with lib;
16with types;
18let
19 # dealing with str is a bit annoying espectially with `nullOr str` as that apparently defaults to ""
20 # instead of null :shrug:. This then messes with our option inheritance logic.
21 # Hence we have a uniqueStr type that ensures multiple identially defined options are collapsed
22 # without raising an error. And a way to fetch default options that will retain `null` if the
23 # option is not defined or "".
24 getDefaultOrNull = def: key: if def ? ${key} && def.${key} != "" then def.${key} else null;
25 mergeUniqueOption = locs: defs: let
26 mergeOneOption = loc: defs':
27 # we ignore "" as optionalString, will default to "".
28 let defs = filter (x: x.value != "") defs'; in
29 if defs == [] then null
30 else if length defs != 1 then
31 throw "The unique option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}; with values `${concatStringsSep "', `" (map (x: x.value) defs)}'."
32 else (head defs).value;
33 in mergeOneOption locs (lists.unique defs);
34 uniqueStr = str // { merge = mergeUniqueOption; };
36 # This is just like listOf, except that it filters out all null elements.
37 listOfFilteringNulls = elemType: listOf elemType // {
38 # Mostly copied from nixpkgs/lib/types.nix
39 merge = loc: defs:
40 map (x: x.value) (filter (x: x ? value && x.value != null) (concatLists (imap1 (n: def:
41 if isList def.value then
42 imap1 (m: def':
43 (mergeDefinitions
44 (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
45 elemType
46 [{ inherit (def) file; value = def'; }]
47 ).optionalValue
48 ) def.value
49 else
50 throw "The option value `${showOption loc}` in `${def.file}` is not a list.") defs)));
51 };
53 componentOptions = def: {
54 buildable = mkOption {
55 type = bool;
56 default = true;
57 };
58 configureFlags = mkOption {
59 type = listOfFilteringNulls str;
60 default = (def.configureFlags or []);
61 };
62 setupBuildFlags = mkOption {
63 type = listOfFilteringNulls str;
64 default = (def.setupBuildFlags or []);
65 };
66 testFlags = mkOption {
67 type = listOfFilteringNulls str;
68 default = (def.testFlags or []);
69 };
70 setupInstallFlags = mkOption {
71 type = listOfFilteringNulls str;
72 default = (def.setupInstallFlags or []);
73 };
74 setupHaddockFlags = mkOption {
75 type = listOfFilteringNulls str;
76 default = (def.setupHaddockFlags or []);
77 };
78 doExactConfig = mkOption {
79 type = bool;
80 default = (def.doExactConfig or false);
81 };
82 doCheck = mkOption {
83 type = bool;
84 default = (def.doCheck or true);
85 };
86 doCrossCheck = mkOption {
87 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.";
88 type = bool;
89 default = (def.doCrossCheck or false);
90 };
91 doHaddock = mkOption {
92 description = "Enable building of the Haddock documentation from the annotated Haskell source code.";
93 type = bool;
94 default = (def.doHaddock or true);
95 };
96 doHoogle = mkOption {
97 description = "Also build a hoogle index.";
98 type = bool;
99 default = (def.doHoogle or true);
100 };
101 doHyperlinkSource = mkOption {
102 description = "Link documentation to the source code.";
103 type = bool;
104 default = (def.doHyperlinkSource or true);
105 };
106 doQuickjump = mkOption {
107 description = "Generate an index for interactive documentation navigation.";
108 type = bool;
109 default = (def.doQuickjump or true);
110 };
111 dontPatchELF = mkOption {
112 description = "If set, the patchelf command is not used to remove unnecessary RPATH entries. Only applies to Linux.";
113 type = bool;
114 default = (def.dontPatchELF or true);
115 };
116 dontStrip = mkOption {
117 description = "If set, libraries and executables are not stripped.";
118 type = bool;
119 default = (def.dontStrip or true);
120 };
121 enableDeadCodeElimination = mkOption {
122 description = "If set, enables split sections for link-time dead-code stripping. Only applies to Linux";
123 type = bool;
124 default = (def.enableDeadCodeElimination or true);
125 };
126 enableStatic = mkOption {
127 description = "If set, enables building static libraries and executables.";
128 type = bool;
129 default = (def.enableStatic or true);
130 };
131 enableShared = mkOption {
132 description = "If set, enables building shared libraries.";
133 type = bool;
134 default = (def.enableShared or true);
135 };
136 shellHook = mkOption {
137 description = "Hook to run when entering a shell";
138 type = unspecified; # Can be either a string or a function
139 default = (def.shellHook or "");
140 };
141 enableLibraryProfiling = mkOption {
142 type = bool;
143 default = (def.enableLibraryProfiling or false);
144 };
146 enableSeparateDataOutput = mkOption {
147 type = bool;
148 default = (def.enableSeparateDataOutput or false);
149 };
151 enableExecutableProfiling = mkOption {
152 type = bool;
153 default = (def.enableExecutableProfiling or false);
154 };
156 profilingDetail = mkOption {
157 type = nullOr uniqueStr;
158 default = (def.profilingDetail or "default");
159 };
161 keepSource = mkOption {
162 type = bool;
163 default = (def.keepSource or false);
164 description = "Keep component source in the store in a `source` output";
165 };
166 };
167 packageOptions = def: componentOptions def // {
168 preUnpack = mkOption {
169 type = nullOr lines;
170 default = (def.preUnpack or null);
171 };
172 postUnpack = mkOption {
173 type = nullOr uniqueStr;
174 default = getDefaultOrNull def "postUnpack";
175 };
176 preConfigure = mkOption {
177 type = nullOr uniqueStr;
178 default = getDefaultOrNull def "preConfigure";
179 };
180 postConfigure = mkOption {
181 type = nullOr uniqueStr;
182 default = getDefaultOrNull def "postConfigure";
183 };
184 preBuild = mkOption {
185 type = nullOr uniqueStr;
186 default = getDefaultOrNull def "preBuild";
187 };
188 postBuild = mkOption {
189 type = nullOr uniqueStr;
190 default = getDefaultOrNull def "postBuild";
191 };
192 preCheck = mkOption {
193 type = nullOr uniqueStr;
194 default = getDefaultOrNull def "preCheck";
195 };
196 # Wrapper for test executable run in checkPhase
197 testWrapper = mkOption {
198 type = listOfFilteringNulls str;
199 default = def.testWrapper or [];
200 description = "A command to run for executing tests in checkPhase, which takes the original test command as its arguments.";
201 example = "echo";
202 };
203 postCheck = mkOption {
204 type = nullOr uniqueStr;
205 default = getDefaultOrNull def "postCheck";
206 };
207 preInstall = mkOption {
208 type = nullOr uniqueStr;
209 default = getDefaultOrNull def "preInstall";
210 };
211 postInstall = mkOption {
212 type = nullOr uniqueStr;
213 default = getDefaultOrNull def "postInstall";
214 };
215 preHaddock = mkOption {
216 type = nullOr uniqueStr;
217 default = getDefaultOrNull def "preHaddock";
218 };
219 postHaddock = mkOption {
220 type = nullOr uniqueStr;
221 default = getDefaultOrNull def "postHaddock";
222 };
223 };
226in {
227 # Global options. These are passed down to the package level, and from there to the
228 # component level, unless specifically overridden. Depending on the flag flags are
229 # combined or replaced. We seed the package Options with an empty set forcing the
230 # default values.
231 options = (packageOptions {}) // {
233 packages = mkOption {
234 type =
235 let mod_args = {
236 inherit pkgs pkgconfPkgs haskellLib;
237 inherit (config) hsPkgs errorHandler;
238 inherit (config.cabal) system compiler;
239 }; in
240 attrsOf (submodule (import ./package.nix {
241 inherit mod_args listOfFilteringNulls;
242 inherit componentOptions packageOptions;
243 parentConfig = config;
244 }));
245 };
247 compiler = {
248 version = mkOption {
249 type = str;
250 };
251 nix-name = mkOption {
252 type = str;
253 };
254 packages = mkOption {
255 type = attrsOf str;
256 };
257 };
259 plan.pkg-def = mkOption {
260 type = unspecified;
261 visible = false;
262 internal = true;
263 };
264 };
266 config = let module = config.plan.pkg-def config.hackage.configs; in {
267 inherit (module) compiler;
268 packages = lib.mapAttrs (name: { revision, ... }@revArgs: { system, compiler, flags, pkgs, hsPkgs, errorHandler, pkgconfPkgs, ... }@modArgs:
270 let m = if revision == null
271 then (abort "${name} has no revision!")
272 else revision (modArgs // { hsPkgs = hsPkgs // (mapAttrs (l: _: hsPkgs.${name}.components.sublibs.${l}) (m.components.sublibs or {})); });
273 in
274 m // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {}); }
275 ) (lib.filterAttrs (n: v: v == null || v.revision != null ) module.packages);
276 };