on iko/ghcjs-patch-master help sign in
Fix dealing with str (#263)

our change from string -> str to evade the warnings nix generates, resulted in a bunch of unforseen consequences. We now modify the str type a bit for our own use.

commit623032c1af041b0ca9fa5d35ff1e319e6903eff8 authorMoritz Angermann <moritz.angermann@gmail.com> dateMon 14 Oct 2019, 16:00 (7 years ago) parenta489e01
1 file changed+31−23
modules/plan.nix+31−23
modules/plan.nix+31−23
@@ -15,8 +15,16 @@
1515with lib;
1616with types;
1717
18−
1918let
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+
2028 # This is just like listOf, except that it filters out all null elements.
2129 listOfFilteringNulls = elemType: listOf elemType // {
2230 # Mostly copied from nixpkgs/lib/types.nix
@@ -105,28 +113,28 @@ let
105113 default = (def.preUnpack or null);
106114 };
107115 postUnpack = mkOption {
108− type = nullOr str;
109− default = (def.postUnpack or null);
116+ type = nullOr uniqueStr;
117+ default = getDefaultOrNull def "postUnpack";
110118 };
111119 preConfigure = mkOption {
112− type = nullOr str;
113− default = (def.preConfigure or null);
120+ type = nullOr uniqueStr;
121+ default = getDefaultOrNull def "preConfigure";
114122 };
115123 postConfigure = mkOption {
116− type = nullOr str;
117− default = (def.postConfigure or null);
124+ type = nullOr uniqueStr;
125+ default = getDefaultOrNull def "postConfigure";
118126 };
119127 preBuild = mkOption {
120− type = nullOr str;
121− default = (def.preBuild or null);
128+ type = nullOr uniqueStr;
129+ default = getDefaultOrNull def "preBuild";
122130 };
123131 postBuild = mkOption {
124− type = nullOr str;
125− default = (def.postBuild or null);
132+ type = nullOr uniqueStr;
133+ default = getDefaultOrNull def "postBuild";
126134 };
127135 preCheck = mkOption {
128− type = nullOr str;
129− default = (def.preCheck or null);
136+ type = nullOr uniqueStr;
137+ default = getDefaultOrNull def "preCheck";
130138 };
131139 # Wrapper for test executable run in checkPhase
132140 testWrapper = mkOption {
@@ -136,24 +144,24 @@ let
136144 example = "echo";
137145 };
138146 postCheck = mkOption {
139− type = nullOr str;
140− default = (def.postCheck or null);
147+ type = nullOr uniqueStr;
148+ default = getDefaultOrNull def "postCheck";
141149 };
142150 preInstall = mkOption {
143− type = nullOr str;
144− default = (def.preInstall or null);
151+ type = nullOr uniqueStr;
152+ default = getDefaultOrNull def "preInstall";
145153 };
146154 postInstall = mkOption {
147− type = nullOr str;
148− default = (def.postInstall or null);
155+ type = nullOr uniqueStr;
156+ default = getDefaultOrNull def "postInstall";
149157 };
150158 preHaddock = mkOption {
151− type = nullOr str;
152− default = (def.preHaddock or null);
159+ type = nullOr uniqueStr;
160+ default = getDefaultOrNull def "preHaddock";
153161 };
154162 postHaddock = mkOption {
155− type = nullOr str;
156− default = (def.postHaddock or null);
163+ type = nullOr uniqueStr;
164+ default = getDefaultOrNull def "postHaddock";
157165 };
158166 };
159167