1# The plan (that is, a package set description like an LTS set or a
2# plan.nix (derived from plan.json)) will produce a structure that
3# looks like, which is stored in config.plan.pkg-def:
5# { packages = { "package" = { revision = hackageConfigs.$package.$version.revisions.default;
6# flags = { flag1 = true; flag2 = false; ... }; };
8# compiler = { version = "X.Y.Z"; nix-name ="ghcXYZ";
9# # packages that come bundled with the compiler
10# packages = { "bytestring" = "a.b.c.d"; ... }; };
13{ lib, config, pkgs, pkgconfPkgs, haskellLib, ... }:
19 # dealing with str is a bit annoying especially 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 identically 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
40 map (x: x.value) (filter (x: x ? value && x.value != null) (concatLists (imap1 (n: def:
41 if isList def.value then
44 (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
46 [{ inherit (def) file; value = def'; }]
50 throw "The option value `${showOption loc}` in `${def.file}` is not a list.") defs)));
53 componentOptions = def: {
54 buildable = mkOption {
58 configureFlags = mkOption {
59 type = listOfFilteringNulls str;
60 default = (def.configureFlags or []);
62 setupBuildFlags = mkOption {
63 type = listOfFilteringNulls str;
64 default = (def.setupBuildFlags or []);
66 testFlags = mkOption {
67 type = listOfFilteringNulls str;
68 default = (def.testFlags or []);
70 setupInstallFlags = mkOption {
71 type = listOfFilteringNulls str;
72 default = (def.setupInstallFlags or []);
74 setupHaddockFlags = mkOption {
75 type = listOfFilteringNulls str;
76 default = (def.setupHaddockFlags or []);
78 doExactConfig = mkOption {
80 default = (def.doExactConfig or false);
84 default = (def.doCheck or true);
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.";
89 default = (def.doCrossCheck or false);
91 doHaddock = mkOption {
92 description = "Enable building of the Haddock documentation from the annotated Haskell source code.";
94 default = (def.doHaddock or true);
97 description = "Also build a hoogle index.";
99 default = (def.doHoogle or true);
101 doHyperlinkSource = mkOption {
102 description = "Link documentation to the source code.";
104 default = (def.doHyperlinkSource or true);
106 doQuickjump = mkOption {
107 description = "Generate an index for interactive documentation navigation.";
109 default = (def.doQuickjump or true);
111 doCoverage = mkOption {
112 description = "Enable production of test coverage reports.";
114 default = (def.doCoverage or false);
116 dontPatchELF = mkOption {
117 description = "If set, the patchelf command is not used to remove unnecessary RPATH entries. Only applies to Linux.";
119 default = (def.dontPatchELF or true);
121 dontStrip = mkOption {
122 description = "If set, libraries and executables are not stripped.";
124 default = (def.dontStrip or true);
126 enableDeadCodeElimination = mkOption {
127 description = "If set, enables split sections for link-time dead-code stripping. Only applies to Linux";
129 default = (def.enableDeadCodeElimination or true);
131 enableStatic = mkOption {
132 description = "If set, enables building static libraries and executables.";
134 default = (def.enableStatic or true);
136 enableShared = mkOption {
137 description = "If set, enables building shared libraries.";
139 default = (def.enableShared or true);
141 configureAllComponents = mkOption {
142 description = "If set all the components in the package are configured (useful for cabal-doctest).";
146 shellHook = mkOption {
147 description = "Hook to run when entering a shell";
148 type = unspecified; # Can be either a string or a function
149 default = (def.shellHook or "");
151 enableLibraryProfiling = mkOption {
153 default = (def.enableLibraryProfiling or false);
156 enableSeparateDataOutput = mkOption {
158 default = (def.enableSeparateDataOutput or false);
161 enableExecutableProfiling = mkOption {
163 default = (def.enableExecutableProfiling or false);
166 profilingDetail = mkOption {
167 type = nullOr uniqueStr;
168 default = (def.profilingDetail or "default");
171 keepSource = mkOption {
173 default = (def.keepSource or false);
174 description = "Keep component source in the store in a `source` output";
177 writeHieFiles = mkOption {
179 default = (def.writeHieFiles or false);
180 description = "Write component `.hie` files in the store in a `hie` output";
183 packageOptions = def: componentOptions def // {
184 preUnpack = mkOption {
186 default = (def.preUnpack or null);
188 postUnpack = mkOption {
189 type = nullOr uniqueStr;
190 default = getDefaultOrNull def "postUnpack";
192 preConfigure = mkOption {
193 type = nullOr uniqueStr;
194 default = getDefaultOrNull def "preConfigure";
196 postConfigure = mkOption {
197 type = nullOr uniqueStr;
198 default = getDefaultOrNull def "postConfigure";
200 preBuild = mkOption {
201 type = nullOr uniqueStr;
202 default = getDefaultOrNull def "preBuild";
204 postBuild = mkOption {
205 type = nullOr uniqueStr;
206 default = getDefaultOrNull def "postBuild";
208 preCheck = mkOption {
209 type = nullOr uniqueStr;
210 default = getDefaultOrNull def "preCheck";
212 # Wrapper for test executable run in checkPhase
213 testWrapper = mkOption {
214 type = listOfFilteringNulls str;
215 default = def.testWrapper or [];
216 description = "A command to run for executing tests in checkPhase, which takes the original test command as its arguments.";
219 postCheck = mkOption {
220 type = nullOr uniqueStr;
221 default = getDefaultOrNull def "postCheck";
223 preInstall = mkOption {
224 type = nullOr uniqueStr;
225 default = getDefaultOrNull def "preInstall";
227 postInstall = mkOption {
228 type = nullOr uniqueStr;
229 default = getDefaultOrNull def "postInstall";
231 preHaddock = mkOption {
232 type = nullOr uniqueStr;
233 default = getDefaultOrNull def "preHaddock";
235 postHaddock = mkOption {
236 type = nullOr uniqueStr;
237 default = getDefaultOrNull def "postHaddock";
239 hardeningDisable = mkOption {
240 type = listOfFilteringNulls str;
241 default = (def.hardeningDisable or []);
243 ghcOptions = mkOption {
244 type = listOfFilteringNulls str;
245 default = def.ghcOptions or [];
248 description = "Set to true by `plan-to-nix` for any component that was included in the `plan.json` file.";
249 # This is here so that (rather than in componentOptions) so it can be set project wide for stack projects
251 default = def.planned or false;
257 # Global options. These are passed down to the package level, and from there to the
258 # component level, unless specifically overridden. Depending on the flag flags are
259 # combined or replaced. We seed the package Options with an empty set forcing the
261 options = (packageOptions {}) // {
263 packages = mkOption {
266 inherit pkgs pkgconfPkgs haskellLib;
267 inherit (config) hsPkgs errorHandler;
268 inherit (config.cabal) system compiler;
270 attrsOf (submodule (import ./package.nix {
271 inherit mod_args listOfFilteringNulls;
272 inherit componentOptions packageOptions;
273 parentConfig = config;
281 nix-name = mkOption {
284 packages = mkOption {
289 plan.pkg-def = mkOption {
296 config = let module = config.plan.pkg-def config.hackage.configs; in {
297 inherit (module) compiler;
298 packages = lib.mapAttrs (name: { revision, ... }@revArgs: { system, compiler, flags, pkgs, hsPkgs, errorHandler, pkgconfPkgs, ... }@modArgs:
300 let m = if revision == null
301 then (abort "${name} has no revision!")
302 else revision (modArgs // { hsPkgs = hsPkgs // (mapAttrs (l: _: hsPkgs.${name}.components.sublibs.${l}) (m.components.sublibs or {})); });
304 m // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {}); }
305 ) (lib.filterAttrs (n: v: v == null || v.revision != null ) module.packages);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list