Skip to content

Commit 509a4ca

Browse files
Rework modules (#1999)
* Move custom types to haskellLib.types Move listOfFilteringNulls, getDefaultOrNull and uniqueStr to haskellLib.types * Lint * Use modules in place of passing arguments * This is not used at all * Formatting * Move component options out * Move package options out * Move component out * Fix bug * Minor adjustments Formatting * AH! * Fix project mkFlake after #1993 Rewrite mkFlakeApps, mkFlakeChecks and mkFlakePackages * Lint * Use pre-existing removeRecurseForDerivations * ifdLevel 0 * ifdLevel 1 * ifdLevel 3 --------- Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@gmail.com>
1 parent 755991c commit 509a4ca

File tree

7 files changed

+628
-524
lines changed

7 files changed

+628
-524
lines changed

lib/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,4 +603,6 @@ in {
603603
__toJSON (__attrNames (lib.filterAttrs (_: v: __length v > 1) (
604604
builtins.groupBy (x: if __typeOf x == "set" then x.name or "noname" else "notset") x)))
605605
}";
606+
607+
types = import ./types.nix { inherit lib; };
606608
}

lib/types.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{ lib }:
2+
3+
with lib;
4+
5+
rec {
6+
# This is just like listOf, except that it filters out all null elements.
7+
listOfFilteringNulls = elemType: types.listOf elemType // {
8+
# Mostly copied from nixpkgs/lib/types.nix
9+
merge = loc: defs:
10+
map (x: x.value) (filter (x: x ? value && x.value != null) (concatLists (imap1
11+
(n: def:
12+
if isList def.value then
13+
imap1
14+
(m: def':
15+
(mergeDefinitions
16+
(loc ++ [ "[definition ${toString n}-entry ${toString m}]" ])
17+
elemType
18+
[{ inherit (def) file; value = def'; }]
19+
).optionalValue
20+
)
21+
def.value
22+
else
23+
throw "The option value `${showOption loc}` in `${def.file}` is not a list.")
24+
defs)));
25+
};
26+
27+
# dealing with str is a bit annoying especially with `nullOr str` as that apparently defaults to ""
28+
# instead of null :shrug:. This then messes with our option inheritance logic.
29+
# Hence we have a uniqueStr type that ensures multiple identically defined options are collapsed
30+
# without raising an error. And a way to fetch default options that will retain `null` if the
31+
# option is not defined or "".
32+
getDefaultOrNull = def: key: if def ? ${key} && def.${key} != "" then def.${key} else null;
33+
34+
mergeUniqueOption = locs: defs:
35+
let
36+
mergeOneOption = loc: defs':
37+
# we ignore "" as optionalString, will default to "".
38+
let defs = filter (x: x.value != "") defs'; in
39+
if defs == [ ] then null
40+
else if length defs != 1 then
41+
throw "The unique option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}; with values `${concatStringsSep "', `" (map (x: x.value) defs)}'."
42+
else (head defs).value;
43+
in
44+
mergeOneOption locs (lists.unique defs);
45+
46+
uniqueStr = types.str // { merge = mergeUniqueOption; };
47+
}

modules/component-options.nix

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{ lib, haskellLib, ... }:
2+
{
3+
options = {
4+
buildable = lib.mkOption {
5+
type = lib.types.bool;
6+
default = true;
7+
};
8+
9+
configureFlags = lib.mkOption {
10+
type = haskellLib.types.listOfFilteringNulls lib.types.str;
11+
default = [];
12+
};
13+
14+
setupBuildFlags = lib.mkOption {
15+
type = haskellLib.types.listOfFilteringNulls lib.types.str;
16+
default = [];
17+
};
18+
19+
testFlags = lib.mkOption {
20+
type = haskellLib.types.listOfFilteringNulls lib.types.str;
21+
default = [];
22+
};
23+
24+
setupInstallFlags = lib.mkOption {
25+
type = haskellLib.types.listOfFilteringNulls lib.types.str;
26+
default = [];
27+
};
28+
29+
setupHaddockFlags = lib.mkOption {
30+
type = haskellLib.types.listOfFilteringNulls lib.types.str;
31+
default = [];
32+
};
33+
34+
doExactConfig = lib.mkOption {
35+
type = lib.types.bool;
36+
default = false;
37+
};
38+
39+
doCheck = lib.mkOption {
40+
type = lib.types.bool;
41+
default = true;
42+
};
43+
44+
doCrossCheck = lib.mkOption {
45+
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.";
46+
type = lib.types.bool;
47+
default = false;
48+
};
49+
50+
doHaddock = lib.mkOption {
51+
description = "Enable building of the Haddock documentation from the annotated Haskell source code.";
52+
type = lib.types.bool;
53+
default = true;
54+
};
55+
56+
doHoogle = lib.mkOption {
57+
description = "Also build a hoogle index.";
58+
type = lib.types.bool;
59+
default = true;
60+
};
61+
62+
doHyperlinkSource = lib.mkOption {
63+
description = "Link documentation to the source code.";
64+
type = lib.types.bool;
65+
default = true;
66+
};
67+
68+
doQuickjump = lib.mkOption {
69+
description = "Generate an index for interactive documentation navigation.";
70+
type = lib.types.bool;
71+
default = true;
72+
};
73+
74+
doCoverage = lib.mkOption {
75+
description = "Enable production of test coverage reports.";
76+
type = lib.types.bool;
77+
default = false;
78+
};
79+
80+
dontPatchELF = lib.mkOption {
81+
description = "If set, the patchelf command is not used to remove unnecessary RPATH entries. Only applies to Linux.";
82+
type = lib.types.bool;
83+
default = true;
84+
};
85+
86+
dontStrip = lib.mkOption {
87+
description = "If set, libraries and executables are not stripped.";
88+
type = lib.types.bool;
89+
default = true;
90+
};
91+
92+
enableDeadCodeElimination = lib.mkOption {
93+
description = "If set, enables split sections for link-time dead-code stripping. Only applies to Linux";
94+
type = lib.types.bool;
95+
default = true;
96+
};
97+
98+
enableStatic = lib.mkOption {
99+
description = "If set, enables building static libraries and executables.";
100+
type = lib.types.bool;
101+
default = true;
102+
};
103+
104+
enableShared = lib.mkOption {
105+
description = "If set, enables building shared libraries.";
106+
type = lib.types.bool;
107+
default = true;
108+
};
109+
110+
configureAllComponents = lib.mkOption {
111+
description = "If set all the components in the package are configured (useful for cabal-doctest).";
112+
type = lib.types.bool;
113+
default = false;
114+
};
115+
116+
shellHook = lib.mkOption {
117+
description = "Hook to run when entering a shell";
118+
type = lib.types.unspecified; # Can be either a string or a function
119+
default = "";
120+
};
121+
122+
enableLibraryProfiling = lib.mkOption {
123+
type = lib.types.bool;
124+
default = false;
125+
};
126+
127+
enableSeparateDataOutput = lib.mkOption {
128+
type = lib.types.bool;
129+
default = true;
130+
};
131+
132+
enableProfiling = lib.mkOption {
133+
type = lib.types.bool;
134+
default = false;
135+
};
136+
137+
profilingDetail = lib.mkOption {
138+
type = lib.types.nullOr haskellLib.types.uniqueStr;
139+
default = "default";
140+
};
141+
142+
keepConfigFiles = lib.mkOption {
143+
type = lib.types.bool;
144+
default = false;
145+
description = "Keep component configFiles in the store in a `configFiles` output";
146+
};
147+
148+
keepGhc = lib.mkOption {
149+
type = lib.types.bool;
150+
default = false;
151+
description = "Keep component wrapped ghc in the store in a `ghc` output";
152+
};
153+
154+
keepSource = lib.mkOption {
155+
type = lib.types.bool;
156+
default = false;
157+
description = "Keep component source in the store in a `source` output";
158+
};
159+
160+
writeHieFiles = lib.mkOption {
161+
type = lib.types.bool;
162+
default = false;
163+
description = "Write component `.hie` files in the store in a `hie` output";
164+
};
165+
};
166+
}

modules/component.nix

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{ lib, haskellLib, ... }:
2+
3+
let
4+
inherit (lib) types;
5+
inherit (haskellLib.types) listOfFilteringNulls;
6+
7+
in
8+
{
9+
imports = [
10+
./component-options.nix
11+
./package-options.nix
12+
];
13+
14+
options = {
15+
plugins = lib.mkOption {
16+
type = types.listOf (types.submodule {
17+
options = {
18+
library = lib.mkOption {
19+
type = types.unspecified;
20+
};
21+
22+
moduleName = lib.mkOption {
23+
type = types.str;
24+
};
25+
26+
args = lib.mkOption {
27+
type = types.listOf types.str;
28+
default = [ ];
29+
};
30+
};
31+
});
32+
33+
default = [ ];
34+
};
35+
36+
depends = lib.mkOption {
37+
type = listOfFilteringNulls types.unspecified;
38+
default = [ ];
39+
};
40+
41+
libs = lib.mkOption {
42+
type = listOfFilteringNulls (types.either (types.nullOr types.package) (listOfFilteringNulls types.package));
43+
default = [ ];
44+
};
45+
46+
frameworks = lib.mkOption {
47+
type = listOfFilteringNulls types.package;
48+
default = [ ];
49+
};
50+
51+
pkgconfig = lib.mkOption {
52+
type = types.listOf (listOfFilteringNulls types.package);
53+
default = [ ];
54+
};
55+
56+
build-tools = lib.mkOption {
57+
type = listOfFilteringNulls types.unspecified;
58+
default = [ ];
59+
};
60+
61+
modules = lib.mkOption {
62+
type = listOfFilteringNulls types.unspecified;
63+
default = [ ];
64+
};
65+
66+
asmSources = lib.mkOption {
67+
type = listOfFilteringNulls types.unspecified;
68+
default = [ ];
69+
};
70+
71+
cmmSources = lib.mkOption {
72+
type = listOfFilteringNulls types.unspecified;
73+
default = [ ];
74+
};
75+
76+
cSources = lib.mkOption {
77+
type = listOfFilteringNulls types.unspecified;
78+
default = [ ];
79+
};
80+
81+
cxxSources = lib.mkOption {
82+
type = listOfFilteringNulls types.unspecified;
83+
default = [ ];
84+
};
85+
86+
jsSources = lib.mkOption {
87+
type = listOfFilteringNulls types.unspecified;
88+
default = [ ];
89+
};
90+
91+
hsSourceDirs = lib.mkOption {
92+
type = listOfFilteringNulls types.unspecified;
93+
default = [ "." ];
94+
};
95+
96+
includeDirs = lib.mkOption {
97+
type = listOfFilteringNulls types.unspecified;
98+
default = [ ];
99+
};
100+
101+
includes = lib.mkOption {
102+
type = listOfFilteringNulls types.unspecified;
103+
default = [ ];
104+
};
105+
106+
mainPath = lib.mkOption {
107+
type = listOfFilteringNulls types.unspecified;
108+
default = [ ];
109+
};
110+
111+
extraSrcFiles = lib.mkOption {
112+
type = listOfFilteringNulls types.unspecified;
113+
default = [ ];
114+
};
115+
116+
platforms = lib.mkOption {
117+
type = types.nullOr (listOfFilteringNulls types.unspecified);
118+
default = null;
119+
};
120+
};
121+
}

0 commit comments

Comments
 (0)