@@ -16,23 +16,23 @@ rec {
1616
1717 defaultMergeArg = x : y: if builtins.isAttrs y then
1818 y
19− else
19+ else
2020 (y x);
2121 defaultMerge = x: y: x // (defaultMergeArg x y);
22− foldArgs = merger: f: init: x:
23− let arg=(merger init (defaultMergeArg init x));
24− # now add the function with composed args already applied to the final attrs
25− base = (setAttrMerge "passthru" {} (f arg)
26− ( z : z // rec {
27− function = foldArgs merger f arg;
28− args = (lib.attrByPath ["passthru" "args"] {} z) // x;
22+ foldArgs = merger: f: init: x:
23+ let arg = (merger init (defaultMergeArg init x));
24+ # now add the function with composed args already applied to the final attrs
25+ base = (setAttrMerge "passthru" {} (f arg)
26+ ( z: z // rec {
27+ function = foldArgs merger f arg;
28+ args = (lib.attrByPath ["passthru" "args"] {} z) // x;
2929 } ));
30− withStdOverrides = base // {
31− override = base.passthru.function;
32− } ;
30+ withStdOverrides = base // {
31+ override = base.passthru.function;
32+ };
3333 in
34− withStdOverrides;
35−
34+ withStdOverrides;
35+
3636
3737 # predecessors: proposed replacement for applyAndFun (which has a bug cause it merges twice)
3838 # the naming "overridableDelayableArgs" tries to express that you can
@@ -49,35 +49,35 @@ rec {
4949 #
5050 # examples: see test cases "res" below;
5151 overridableDelayableArgs =
52− f : # the function applied to the arguments
53− initial : # you pass attrs, the functions below are passing a function taking the fix argument
52+ f: # the function applied to the arguments
53+ initial: # you pass attrs, the functions below are passing a function taking the fix argument
5454 let
5555 takeFixed = if isFunction initial then initial else (fixed : initial); # transform initial to an expression always taking the fixed argument
56− tidy = args :
56+ tidy = args:
5757 let # apply all functions given in "applyPreTidy" in sequence
58− applyPreTidyFun = fold ( n : a : x : n ( a x ) ) lib.id (maybeAttr "applyPreTidy" [] args);
58+ applyPreTidyFun = fold ( n: a: x: n ( a x ) ) lib.id (maybeAttr "applyPreTidy" [] args);
5959 in removeAttrs (applyPreTidyFun args) ( ["applyPreTidy"] ++ (maybeAttr "removeAttrs" [] args) ); # tidy up args before applying them
60− fun = n : x :
61− let newArgs = fixed :
62− let args = takeFixed fixed;
63− mergeFun = args.${n};
64− in if isAttrs x then (mergeFun args x)
65− else assert isFunction x;
66− mergeFun args (x ( args // { inherit fixed; }));
67− in overridableDelayableArgs f newArgs;
60+ fun = n: x:
61+ let newArgs = fixed:
62+ let args = takeFixed fixed;
63+ mergeFun = args.${n};
64+ in if isAttrs x then (mergeFun args x)
65+ else assert isFunction x;
66+ mergeFun args (x ( args // { inherit fixed; }));
67+ in overridableDelayableArgs f newArgs;
6868 in
6969 (f (tidy (lib.fix takeFixed))) // {
7070 merge = fun "mergeFun";
7171 replace = fun "keepFun";
7272 };
73− defaultOverridableDelayableArgs = f :
73+ defaultOverridableDelayableArgs = f:
7474 let defaults = {
7575 mergeFun = mergeAttrByFunc; # default merge function. merge strategie (concatenate lists, strings) is given by mergeAttrBy
76− keepFun = a : b : { inherit (a) removeAttrs mergeFun keepFun mergeAttrBy; } // b; # even when using replace preserve these values
76+ keepFun = a: b: { inherit (a) removeAttrs mergeFun keepFun mergeAttrBy; } // b; # even when using replace preserve these values
7777 applyPreTidy = []; # list of functions applied to args before args are tidied up (usage case : prepareDerivationArgs)
7878 mergeAttrBy = mergeAttrBy // {
79− applyPreTidy = a : b : a ++ b;
80− removeAttrs = a : b: a ++ b;
79+ applyPreTidy = a: b: a ++ b;
80+ removeAttrs = a: b: a ++ b;
8181 };
8282 removeAttrs = ["mergeFun" "keepFun" "mergeAttrBy" "removeAttrs" "fixed" ]; # before applying the arguments to the function make sure these names are gone
8383 };
@@ -86,7 +86,7 @@ rec {
8686
8787
8888 # rec { # an example of how composedArgsAndFun can be used
89− # a = composedArgsAndFun (x : x) { a = ["2"]; meta = { d = "bar";}; };
89+ # a = composedArgsAndFun (x: x) { a = ["2"]; meta = { d = "bar";}; };
9090 # # meta.d will be lost ! It's your task to preserve it (eg using a merge function)
9191 # b = a.passthru.function { a = [ "3" ]; meta = { d2 = "bar2";}; };
9292 # # instead of passing/ overriding values you can use a merge function:
@@ -119,7 +119,7 @@ rec {
119119 else if val == true || val == false then false
120120 else null;
121121
122−
122+
123123 # Return true only if there is an attribute and it is true.
124124 checkFlag = attrSet: name:
125125 if name == "true" then true else
@@ -134,29 +134,29 @@ rec {
134134 ( attrByPath [name] (if checkFlag attrSet name then true else
135135 if argList == [] then null else
136136 let x = builtins.head argList; in
137− if (head x) == name then
137+ if (head x) == name then
138138 (head (tail x))
139− else (getValue attrSet
139+ else (getValue attrSet
140140 (tail argList) name)) attrSet );
141141
142−
142+
143143 # Input : attrSet, [[name default] ...], [ [flagname reqs..] ... ]
144144 # Output : are reqs satisfied? It's asserted.
145− checkReqs = attrSet : argList : condList :
145+ checkReqs = attrSet: argList: condList:
146146 (
147− fold lib.and true
148− (map (x: let name = (head x) ; in
149−
150− ((checkFlag attrSet name) ->
147+ fold lib.and true
148+ (map (x: let name = (head x); in
149+
150+ ((checkFlag attrSet name) ->
151151 (fold lib.and true
152152 (map (y: let val=(getValue attrSet argList y); in
153− (val!=null) && (val!=false))
154− (tail x))))) condList)) ;
155−
153+ (val!=null) && (val!=false))
154+ (tail x))))) condList));
155+
156156
157157 # This function has O(n^2) performance.
158− uniqList = {inputList, acc ? []} :
159− let go = xs : acc :
158+ uniqList = { inputList, acc ? [] }:
159+ let go = xs: acc:
160160 if xs == []
161161 then []
162162 else let x = head xs;
@@ -164,26 +164,26 @@ rec {
164164 in y ++ go (tail xs) (y ++ acc);
165165 in go inputList acc;
166166
167− uniqListExt = {inputList, outputList ? [],
168− getter ? (x : x), compare ? (x: y: x==y)}:
167+ uniqListExt = { inputList,
168+ outputList ? [],
169+ getter ? (x: x),
170+ compare ? (x: y: x==y) }:
169171 if inputList == [] then outputList else
170− let x=head inputList;
171− isX = y: (compare (getter y) (getter x));
172− newOutputList = outputList ++
173− (if any isX outputList then [] else [x]);
174− in uniqListExt {outputList=newOutputList;
175− inputList = (tail inputList);
176− inherit getter compare;
177− };
178−
172+ let x = head inputList;
173+ isX = y: (compare (getter y) (getter x));
174+ newOutputList = outputList ++
175+ (if any isX outputList then [] else [x]);
176+ in uniqListExt { outputList = newOutputList;
177+ inputList = (tail inputList);
178+ inherit getter compare;
179+ };
179180
180−
181181 condConcat = name: list: checker:
182182 if list == [] then name else
183− if checker (head list) then
184− condConcat
185− (name + (head (tail list)))
186− (tail (tail list))
183+ if checker (head list) then
184+ condConcat
185+ (name + (head (tail list)))
186+ (tail (tail list))
187187 checker
188188 else condConcat
189189 name (tail (tail list)) checker;
@@ -202,12 +202,12 @@ rec {
202202 in
203203 work startSet [] [];
204204
205− innerModifySumArgs = f: x: a: b: if b == null then (f a b) // x else
205+ innerModifySumArgs = f: x: a: b: if b == null then (f a b) // x else
206206 innerModifySumArgs f x (a // b);
207207 modifySumArgs = f: x: innerModifySumArgs f x {};
208208
209209
210− innerClosePropagation = acc : xs :
210+ innerClosePropagation = acc: xs:
211211 if xs == []
212212 then acc
213213 else let y = head xs;
@@ -227,31 +227,31 @@ rec {
227227 closePropagation = list: (uniqList {inputList = (innerClosePropagation [] list);});
228228
229229 # calls a function (f attr value ) for each record item. returns a list
230− mapAttrsFlatten = f : r : map (attr: f attr r.${attr}) (attrNames r);
230+ mapAttrsFlatten = f: r: map (attr: f attr r.${attr}) (attrNames r);
231231
232232 # attribute set containing one attribute
233− nvs = name : value : listToAttrs [ (nameValuePair name value) ];
233+ nvs = name: value: listToAttrs [ (nameValuePair name value) ];
234234 # adds / replaces an attribute of an attribute set
235− setAttr = set : name : v : set // (nvs name v);
235+ setAttr = set: name: v: set // (nvs name v);
236236
237237 # setAttrMerge (similar to mergeAttrsWithFunc but only merges the values of a particular name)
238− # setAttrMerge "a" [] { a = [2];} (x : x ++ [3]) -> { a = [2 3]; }
239− # setAttrMerge "a" [] { } (x : x ++ [3]) -> { a = [ 3]; }
240− setAttrMerge = name : default : attrs : f :
238+ # setAttrMerge "a" [] { a = [2];} (x: x ++ [3]) -> { a = [2 3]; }
239+ # setAttrMerge "a" [] { } (x: x ++ [3]) -> { a = [ 3]; }
240+ setAttrMerge = name: default: attrs: f:
241241 setAttr attrs name (f (maybeAttr name default attrs));
242242
243− # Using f = a : b = b the result is similar to //
243+ # Using f = a: b = b the result is similar to //
244244 # merge attributes with custom function handling the case that the attribute
245245 # exists in both sets
246− mergeAttrsWithFunc = f : set1 : set2 :
247− fold (n: set : if set ? ${n}
246+ mergeAttrsWithFunc = f: set1: set2:
247+ fold (n: set: if set ? ${n}
248248 then setAttr set n (f set.${n} set2.${n})
249249 else set )
250250 (set2 // set1) (attrNames set2);
251251
252252 # merging two attribute set concatenating the values of same attribute names
253253 # eg { a = 7; } { a = [ 2 3 ]; } becomes { a = [ 7 2 3 ]; }
254− mergeAttrsConcatenateValues = mergeAttrsWithFunc ( a : b : (toList a) ++ (toList b) );
254+ mergeAttrsConcatenateValues = mergeAttrsWithFunc ( a: b: (toList a) ++ (toList b) );
255255
256256 # merges attributes using //, if a name exisits in both attributes
257257 # an error will be triggered unless its listed in mergeLists
@@ -262,10 +262,10 @@ rec {
262262 # ! deprecated, use mergeAttrByFunc instead
263263 mergeAttrsNoOverride = { mergeLists ? ["buildInputs" "propagatedBuildInputs"],
264264 overrideSnd ? [ "buildPhase" ]
265− } : attrs1 : attrs2 :
266− fold (n: set :
265+ }: attrs1: attrs2:
266+ fold (n: set:
267267 setAttr set n ( if set ? ${n}
268− then # merge
268+ then # merge
269269 if elem n mergeLists # attribute contains list, merge them by concatenating
270270 then attrs2.${n} ++ attrs1.${n}
271271 else if elem n overrideSnd
@@ -286,14 +286,14 @@ rec {
286286 # { mergeAttrsBy = [...]; buildInputs = [ a b c d ]; }
287287 # is used by prepareDerivationArgs, defaultOverridableDelayableArgs and can be used when composing using
288288 # foldArgs, composedArgsAndFun or applyAndFun. Example: composableDerivation in all-packages.nix
289− mergeAttrByFunc = x : y :
289+ mergeAttrByFunc = x: y:
290290 let
291− mergeAttrBy2 = { mergeAttrBy=lib.mergeAttrs; }
291+ mergeAttrBy2 = { mergeAttrBy = lib.mergeAttrs; }
292292 // (maybeAttr "mergeAttrBy" {} x)
293293 // (maybeAttr "mergeAttrBy" {} y); in
294294 fold lib.mergeAttrs {} [
295295 x y
296− (mapAttrs ( a : v : # merge special names using given functions
296+ (mapAttrs ( a: v: # merge special names using given functions
297297 if x ? ${a}
298298 then if y ? ${a}
299299 then v x.${a} y.${a} # both have attr, use merge func
@@ -313,9 +313,9 @@ rec {
313313 #
314314 # This function is best explained by an example:
315315 #
316− # {version ? "2.x"} :
316+ # {version ? "2.x"}:
317317 #
318− # mkDerivation (mergeAttrsByVersion "package-name" version
318+ # mkDerivation (mergeAttrsByVersion "package-name" version
319319 # { # version specific settings
320320 # "git" = { src = ..; preConfigre = "autogen.sh"; buildInputs = [automake autoconf libtool]; };
321321 # "2.x" = { src = ..; };
@@ -346,21 +346,24 @@ rec {
346346 # See misc.nix -> versionedDerivation
347347 # discussion: nixpkgs: pull/310
348348 mergeAttrsByVersion = name: version: attrsByVersion: base:
349− mergeAttrsByFuncDefaultsClean [ { name = "${name}-${version}"; } base (maybeAttr version (throw "bad version ${version} for ${name}") attrsByVersion)];
349+ mergeAttrsByFuncDefaultsClean [ { name = "${name}-${version}"; }
350+ base
351+ (maybeAttr version (throw "bad version ${version} for ${name}") attrsByVersion)
352+ ];
350353
351354 # sane defaults (same name as attr name so that inherit can be used)
352355 mergeAttrBy = # { buildInputs = concatList; [...]; passthru = mergeAttr; [..]; }
353− listToAttrs (map (n : nameValuePair n lib.concat)
356+ listToAttrs (map (n: nameValuePair n lib.concat)
354357 [ "nativeBuildInputs" "buildInputs" "propagatedBuildInputs" "configureFlags" "prePhases" "postAll" "patches" ])
355− // listToAttrs (map (n : nameValuePair n lib.mergeAttrs) [ "passthru" "meta" "cfg" "flags" ])
356− // listToAttrs (map (n : nameValuePair n (a: b: "${a}\n${b}") ) [ "preConfigure" "postInstall" ])
358+ // listToAttrs (map (n: nameValuePair n lib.mergeAttrs) [ "passthru" "meta" "cfg" "flags" ])
359+ // listToAttrs (map (n: nameValuePair n (a: b: "${a}\n${b}") ) [ "preConfigure" "postInstall" ])
357360 ;
358361
359362 # prepareDerivationArgs tries to make writing configurable derivations easier
360363 # example:
361364 # prepareDerivationArgs {
362365 # mergeAttrBy = {
363− # myScript = x : y : x ++ "\n" ++ y;
366+ # myScript = x: y: x ++ "\n" ++ y;
364367 # };
365368 # cfg = {
366369 # readlineSupport = true;
@@ -392,10 +395,10 @@ rec {
392395 # TODO use args.mergeFun here as well?
393396 prepareDerivationArgs = args:
394397 let args2 = { cfg = {}; flags = {}; } // args;
395− flagName = name : "${name}Support";
396− cfgWithDefaults = (listToAttrs (map (n : nameValuePair (flagName n) false) (attrNames args2.flags)))
398+ flagName = name: "${name}Support";
399+ cfgWithDefaults = (listToAttrs (map (n: nameValuePair (flagName n) false) (attrNames args2.flags)))
397400 // args2.cfg;
398− opts = attrValues (mapAttrs (a : v :
401+ opts = attrValues (mapAttrs (a: v:
399402 let v2 = if v ? set || v ? unset then v else { set = v; };
400403 n = if cfgWithDefaults.${flagName a} then "set" else "unset";
401404 attr = maybeAttr n {} v2; in