on iko/ghcjs-patch-master help sign in
Fix dealing with str (#263)
623032cMoritz Angermann
modules/plan.nix+31−23
@@ -15,8 +15,16 @@
15with lib;
15with lib;
16with types;
16with types;
17
17
18−
19let
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: mergeOneOption locs (lists.unique defs);
26+ uniqueStr = str // { merge = mergeUniqueOption; };
27+
20 # This is just like listOf, except that it filters out all null elements.
28 # This is just like listOf, except that it filters out all null elements.
21 listOfFilteringNulls = elemType: listOf elemType // {
29 listOfFilteringNulls = elemType: listOf elemType // {
22 # Mostly copied from nixpkgs/lib/types.nix
30 # Mostly copied from nixpkgs/lib/types.nix
@@ -105,28 +113,28 @@ let
105 default = (def.preUnpack or null);
113 default = (def.preUnpack or null);
106 };
114 };
107 postUnpack = mkOption {
115 postUnpack = mkOption {
108− type = nullOr str;
116+ type = nullOr uniqueStr;
109− default = (def.postUnpack or null);
117+ default = getDefaultOrNull def "postUnpack";
110 };
118 };
111 preConfigure = mkOption {
119 preConfigure = mkOption {
112− type = nullOr str;
120+ type = nullOr uniqueStr;
113− default = (def.preConfigure or null);
121+ default = getDefaultOrNull def "preConfigure";
114 };
122 };
115 postConfigure = mkOption {
123 postConfigure = mkOption {
116− type = nullOr str;
124+ type = nullOr uniqueStr;
117− default = (def.postConfigure or null);
125+ default = getDefaultOrNull def "postConfigure";
118 };
126 };
119 preBuild = mkOption {
127 preBuild = mkOption {
120− type = nullOr str;
128+ type = nullOr uniqueStr;
121− default = (def.preBuild or null);
129+ default = getDefaultOrNull def "preBuild";
122 };
130 };
123 postBuild = mkOption {
131 postBuild = mkOption {
124− type = nullOr str;
132+ type = nullOr uniqueStr;
125− default = (def.postBuild or null);
133+ default = getDefaultOrNull def "postBuild";
126 };
134 };
127 preCheck = mkOption {
135 preCheck = mkOption {
128− type = nullOr str;
136+ type = nullOr uniqueStr;
129− default = (def.preCheck or null);
137+ default = getDefaultOrNull def "preCheck";
130 };
138 };
131 # Wrapper for test executable run in checkPhase
139 # Wrapper for test executable run in checkPhase
132 testWrapper = mkOption {
140 testWrapper = mkOption {
@@ -136,24 +144,24 @@ let
136 example = "echo";
144 example = "echo";
137 };
145 };
138 postCheck = mkOption {
146 postCheck = mkOption {
139− type = nullOr str;
147+ type = nullOr uniqueStr;
140− default = (def.postCheck or null);
148+ default = getDefaultOrNull def "postCheck";
141 };
149 };
142 preInstall = mkOption {
150 preInstall = mkOption {
143− type = nullOr str;
151+ type = nullOr uniqueStr;
144− default = (def.preInstall or null);
152+ default = getDefaultOrNull def "preInstall";
145 };
153 };
146 postInstall = mkOption {
154 postInstall = mkOption {
147− type = nullOr str;
155+ type = nullOr uniqueStr;
148− default = (def.postInstall or null);
156+ default = getDefaultOrNull def "postInstall";
149 };
157 };
150 preHaddock = mkOption {
158 preHaddock = mkOption {
151− type = nullOr str;
159+ type = nullOr uniqueStr;
152− default = (def.preHaddock or null);
160+ default = getDefaultOrNull def "preHaddock";
153 };
161 };
154 postHaddock = mkOption {
162 postHaddock = mkOption {
155− type = nullOr str;
163+ type = nullOr uniqueStr;
156− default = (def.postHaddock or null);
164+ default = getDefaultOrNull def "postHaddock";
157 };
165 };
158 };
166 };
159
167