git.iko.soy/typeable/nixpkgs
on master help sign in
lib: fix mixed tab/space indents, trailing whitespace, etc

Nix style seems to have settled on not using spaces between bound variable names and the lambda : so I also tried to make those somewhat more consistent throughout.

commitd9123a2329f0d35af45d25aab5adb4348b8e3d56 authorBenjamin Staffin <benley@gmail.com> dateSat 11 Mar 2017, 17:39 (10 years ago) parent3ea16e9
6 files changed+110−107
lib/composable-derivation.nix+3−3 lib/debug.nix+7−7 lib/deprecated.nix+91−88 lib/modules.nix+4−4 lib/tests.nix+4−4 lib/types.nix+1−1
lib/composable-derivation.nix+3−3
@@ -1,4 +1,4 @@
1−{lib, pkgs} :
1+{lib, pkgs}:
22let inherit (lib) nv nvs; in
33{
44
@@ -19,7 +19,7 @@ let inherit (lib) nv nvs; in
1919 # * vim_configurable
2020 #
2121 # A minimal example illustrating most features would look like this:
22− # let base = composableDerivation { (fixed : let inherit (fixed.fixed) name in {
22+ # let base = composableDerivation { (fixed: let inherit (fixed.fixed) name in {
2323 # src = fetchurl {
2424 # }
2525 # buildInputs = [A];
@@ -79,7 +79,7 @@ let inherit (lib) nv nvs; in
7979 # consider adding addtional elements by derivation.merge { removeAttrs = ["elem"]; };
8080 removeAttrs ? ["cfg" "flags"]
8181
82− }: (lib.defaultOverridableDelayableArgs ( a: mkDerivation a)
82+ }: (lib.defaultOverridableDelayableArgs ( a: mkDerivation a)
8383 {
8484 inherit applyPreTidy removeAttrs;
8585 }).merge;
lib/debug.nix+7−7
@@ -24,10 +24,10 @@ rec {
2424 traceValSeq = v: traceVal (builtins.deepSeq v v);
2525
2626 # this can help debug your code as well - designed to not produce thousands of lines
27− traceShowVal = x : trace (showVal x) x;
27+ traceShowVal = x: trace (showVal x) x;
2828 traceShowValMarked = str: x: trace (str + showVal x) x;
29− attrNamesToStr = a : lib.concatStringsSep "; " (map (x : "${x}=") (attrNames a));
30− showVal = x :
29+ attrNamesToStr = a: lib.concatStringsSep "; " (map (x: "${x}=") (attrNames a));
30+ showVal = x:
3131 if isAttrs x then
3232 if x ? outPath then "x is a derivation, name ${if x ? name then x.name else "<no name>"}, { ${attrNamesToStr x} }"
3333 else "x is attr set { ${attrNamesToStr x} }"
@@ -43,9 +43,9 @@ rec {
4343
4444 # trace the arguments passed to function and its result
4545 # maybe rewrite these functions in a traceCallXml like style. Then one function is enough
46− traceCall = n : f : a : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a));
47− traceCall2 = n : f : a : b : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b));
48− traceCall3 = n : f : a : b : c : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b) (t "arg 3" c));
46+ traceCall = n: f: a: let t = n2: x: traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a));
47+ traceCall2 = n: f: a: b: let t = n2: x: traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b));
48+ traceCall3 = n: f: a: b: c: let t = n2: x: traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b) (t "arg 3" c));
4949
5050 # FIXME: rename this?
5151 traceValIfNot = c: x:
@@ -71,7 +71,7 @@ rec {
7171
7272 # create a test assuming that list elements are true
7373 # usage: { testX = allTrue [ true ]; }
74− testAllTrue = expr : { inherit expr; expected = map (x: true) expr; };
74+ testAllTrue = expr: { inherit expr; expected = map (x: true) expr; };
7575
7676 strict = v:
7777 trace "Warning: strict is deprecated and will be removed in the next release"
lib/deprecated.nix+91−88
@@ -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
lib/modules.nix+4−4
@@ -114,7 +114,7 @@ rec {
114114 /* Massage a module into canonical form, that is, a set consisting
115115 of ‘options’, ‘config’ and ‘imports’ attributes. */
116116 unifyModuleSyntax = file: key: m:
117− let metaSet = if m ? meta
117+ let metaSet = if m ? meta
118118 then { meta = m.meta; }
119119 else {};
120120 in
@@ -595,7 +595,7 @@ rec {
595595 functionality
596596
597597 This show a warning if any a.b.c or d.e.f is set, and set the value of
598− x.y.z to the result of the merge function
598+ x.y.z to the result of the merge function
599599 */
600600 mkMergedOptionModule = from: to: mergeFn:
601601 { config, options, ... }:
@@ -611,12 +611,12 @@ rec {
611611 let val = getAttrFromPath f config;
612612 opt = getAttrFromPath f options;
613613 in
614− optionalString
614+ optionalString
615615 (val != "_mkMergedOptionModule")
616616 "The option `${showOption f}' defined in ${showFiles opt.files} has been changed to `${showOption to}' that has a different type. Please read `${showOption to}' documentation and update your configuration accordingly."
617617 ) from);
618618 } // setAttrByPath to (mkMerge
619− (optional
619+ (optional
620620 (any (f: (getAttrFromPath f config) != "_mkMergedOptionModule") from)
621621 (mergeFn config)));
622622 };
lib/tests.nix+4−4
@@ -80,7 +80,7 @@ runTests {
8080 y = x.merge {};
8181 in (y.merge) { a = 10; };
8282
83− resRem7 = res6.replace (a : removeAttrs a ["a"]);
83+ resRem7 = res6.replace (a: removeAttrs a ["a"]);
8484
8585 resReplace6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = add; }; };
8686 x2 = x.merge { a = 20; }; # now we have 27
@@ -88,10 +88,10 @@ runTests {
8888
8989 # fixed tests (delayed args): (when using them add some comments, please)
9090 resFixed1 =
91− let x = defaultOverridableDelayableArgs id ( x : { a = 7; c = x.fixed.b; });
92− y = x.merge (x : { name = "name-${builtins.toString x.fixed.c}"; });
91+ let x = defaultOverridableDelayableArgs id ( x: { a = 7; c = x.fixed.b; });
92+ y = x.merge (x: { name = "name-${builtins.toString x.fixed.c}"; });
9393 in (y.merge) { b = 10; };
94− strip = attrs : removeAttrs attrs ["merge" "replace"];
94+ strip = attrs: removeAttrs attrs ["merge" "replace"];
9595 in all id
9696 [ ((strip res1) == { })
9797 ((strip res2) == { a = 7; })
lib/types.nix+1−1
@@ -81,7 +81,7 @@ rec {
8181 # name: name of the type
8282 # type: type function.
8383 # wrapped: the type wrapped in case of compound types.
84− # payload: values of the type, two payloads of the same type must be
84+ # payload: values of the type, two payloads of the same type must be
8585 # combinable with the binOp binary operation.
8686 # binOp: binary operation that merge two payloads of the same type.
8787 functor ? defaultFunctor name