diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/deprecated.nix | 8 | ||||
-rw-r--r-- | lib/lists.nix | 14 | ||||
-rw-r--r-- | lib/maintainers.nix | 3 | ||||
-rw-r--r-- | lib/modules.nix | 2 | ||||
-rw-r--r-- | lib/strings.nix | 4 | ||||
-rw-r--r-- | lib/types.nix | 8 |
6 files changed, 28 insertions, 11 deletions
diff --git a/lib/deprecated.nix b/lib/deprecated.nix index 983e8d26892..d4e78c39250 100644 --- a/lib/deprecated.nix +++ b/lib/deprecated.nix @@ -423,4 +423,12 @@ rec { else if isInt x then "int" else "string"; + /* deprecated: + + For historical reasons, imap has an index starting at 1. + + But for consistency with the rest of the library we want an index + starting at zero. + */ + imap = imap1; } diff --git a/lib/lists.nix b/lib/lists.nix index fd746f4f97b..a04b1b27893 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -77,15 +77,21 @@ rec { */ foldl' = builtins.foldl' or foldl; - /* Map with index + /* Map with index starting from 0 - FIXME(zimbatm): why does this start to count at 1? + Example: + imap0 (i: v: "${v}-${toString i}") ["a" "b"] + => [ "a-0" "b-1" ] + */ + imap0 = f: list: genList (n: f n (elemAt list n)) (length list); + + /* Map with index starting from 1 Example: - imap (i: v: "${v}-${toString i}") ["a" "b"] + imap1 (i: v: "${v}-${toString i}") ["a" "b"] => [ "a-1" "b-2" ] */ - imap = f: list: genList (n: f (n + 1) (elemAt list n)) (length list); + imap1 = f: list: genList (n: f (n + 1) (elemAt list n)) (length list); /* Map and concatenate the result. diff --git a/lib/maintainers.nix b/lib/maintainers.nix index 422c86469f8..c43096deb29 100644 --- a/lib/maintainers.nix +++ b/lib/maintainers.nix @@ -16,6 +16,7 @@ acowley = "Anthony Cowley <acowley@gmail.com>"; adelbertc = "Adelbert Chang <adelbertc@gmail.com>"; adev = "Adrien Devresse <adev@adev.name>"; + adisbladis = "Adam Hose <adis@blad.is>"; Adjective-Object = "Maxwell Huang-Hobbs <mhuan13@gmail.com>"; adnelson = "Allen Nelson <ithinkican@gmail.com>"; adolfogc = "Adolfo E. García Castro <adolfo.garcia.cr@gmail.com>"; @@ -267,6 +268,7 @@ jpierre03 = "Jean-Pierre PRUNARET <nix@prunetwork.fr>"; jpotier = "Martin Potier <jpo.contributes.to.nixos@marvid.fr>"; jraygauthier = "Raymond Gauthier <jraygauthier@gmail.com>"; + jtojnar = "Jan Tojnar <jtojnar@gmail.com>"; juliendehos = "Julien Dehos <dehos@lisic.univ-littoral.fr>"; jwiegley = "John Wiegley <johnw@newartisans.com>"; jwilberding = "Jordan Wilberding <jwilberding@afiniate.com>"; @@ -606,6 +608,7 @@ z77z = "Marco Maggesi <maggesi@math.unifi.it>"; zagy = "Christian Zagrodnick <cz@flyingcircus.io>"; zalakain = "Unai Zalakain <contact@unaizalakain.info>"; + zarelit = "David Costa <david@zarel.net>"; zauberpony = "Elmar Athmer <elmar@athmer.org>"; zef = "Zef Hemel <zef@zef.me>"; zimbatm = "zimbatm <zimbatm@zimbatm.com>"; diff --git a/lib/modules.nix b/lib/modules.nix index 91e2eae0595..3da689a6bdb 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -98,7 +98,7 @@ rec { /* Close a set of modules under the ‘imports’ relation. */ closeModules = modules: args: let - toClosureList = file: parentKey: imap (n: x: + toClosureList = file: parentKey: imap1 (n: x: if isAttrs x || isFunction x then let key = "${parentKey}:anon-${toString n}"; in unifyModuleSyntax file key (unpackSubmodule (applyIfFunction key) x args) diff --git a/lib/strings.nix b/lib/strings.nix index 1cc633c729d..a03694d1b1d 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -33,7 +33,7 @@ rec { concatImapStrings (pos: x: "${toString pos}-${x}") ["foo" "bar"] => "1-foo2-bar" */ - concatImapStrings = f: list: concatStrings (lib.imap f list); + concatImapStrings = f: list: concatStrings (lib.imap1 f list); /* Place an element between each element of a list @@ -70,7 +70,7 @@ rec { concatImapStringsSep "-" (pos: x: toString (x / pos)) [ 6 6 6 ] => "6-3-2" */ - concatImapStringsSep = sep: f: list: concatStringsSep sep (lib.imap f list); + concatImapStringsSep = sep: f: list: concatStringsSep sep (lib.imap1 f list); /* Construct a Unix-style search path consisting of each `subDir" directory of the given list of packages. diff --git a/lib/types.nix b/lib/types.nix index 50aa6d77085..a7dcd3f1e1c 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -179,9 +179,9 @@ rec { description = "list of ${elemType.description}s"; check = isList; merge = loc: defs: - map (x: x.value) (filter (x: x ? value) (concatLists (imap (n: def: + map (x: x.value) (filter (x: x ? value) (concatLists (imap1 (n: def: if isList def.value then - imap (m: def': + imap1 (m: def': (mergeDefinitions (loc ++ ["[definition ${toString n}-entry ${toString m}]"]) elemType @@ -220,7 +220,7 @@ rec { if isList def.value then { inherit (def) file; value = listToAttrs ( - imap (elemIdx: elem: + imap1 (elemIdx: elem: { name = elem.name or "unnamed-${toString defIdx}.${toString elemIdx}"; value = elem; }) def.value); @@ -233,7 +233,7 @@ rec { name = "loaOf"; description = "list or attribute set of ${elemType.description}s"; check = x: isList x || isAttrs x; - merge = loc: defs: attrOnly.merge loc (imap convertIfList defs); + merge = loc: defs: attrOnly.merge loc (imap1 convertIfList defs); getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name?>"]); getSubModules = elemType.getSubModules; substSubModules = m: loaOf (elemType.substSubModules m); |