summary refs log tree commit diff
path: root/pkgs/lib
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2011-08-24 19:16:43 +0000
committerShea Levy <shea@shealevy.com>2011-08-24 19:16:43 +0000
commit4d70ba6cc960555c9e1f701a88517e99232b2148 (patch)
tree7fc328746167a757526bf4165584e3bfb8a83b4f /pkgs/lib
parent5d62c65d6e085481a36c857e8b86f88d80b1c565 (diff)
parentb58016b007444b25ab5256eb21896cd859038901 (diff)
downloadnixlib-4d70ba6cc960555c9e1f701a88517e99232b2148.tar
nixlib-4d70ba6cc960555c9e1f701a88517e99232b2148.tar.gz
nixlib-4d70ba6cc960555c9e1f701a88517e99232b2148.tar.bz2
nixlib-4d70ba6cc960555c9e1f701a88517e99232b2148.tar.lz
nixlib-4d70ba6cc960555c9e1f701a88517e99232b2148.tar.xz
nixlib-4d70ba6cc960555c9e1f701a88517e99232b2148.tar.zst
nixlib-4d70ba6cc960555c9e1f701a88517e99232b2148.zip
Merge from trunk up through r28790
svn path=/nixpkgs/branches/stdenv-updates/; revision=28792
Diffstat (limited to 'pkgs/lib')
-rw-r--r--pkgs/lib/customisation.nix2
-rw-r--r--pkgs/lib/lists.nix8
-rw-r--r--pkgs/lib/maintainers.nix6
-rw-r--r--pkgs/lib/misc.nix2
-rw-r--r--pkgs/lib/modules.nix18
-rw-r--r--pkgs/lib/properties.nix5
-rw-r--r--pkgs/lib/strings.nix5
-rw-r--r--pkgs/lib/types.nix48
8 files changed, 80 insertions, 14 deletions
diff --git a/pkgs/lib/customisation.nix b/pkgs/lib/customisation.nix
index f97b494ae92d..d2af48146284 100644
--- a/pkgs/lib/customisation.nix
+++ b/pkgs/lib/customisation.nix
@@ -89,7 +89,7 @@ rec {
       };
   */
   callPackageWith = autoArgs: fn: args:
-    let f = import fn; in
+    let f = if builtins.isFunction fn then fn else import fn; in
     makeOverridable f ((builtins.intersectAttrs (builtins.functionArgs f) autoArgs) // args);
 
 }
diff --git a/pkgs/lib/lists.nix b/pkgs/lib/lists.nix
index d1cdf5b68ab1..e5b47f0d9ce7 100644
--- a/pkgs/lib/lists.nix
+++ b/pkgs/lib/lists.nix
@@ -1,7 +1,7 @@
 # General list operations.
 
 rec {
-  inherit (builtins) head tail isList;
+  inherit (builtins) head tail length isList;
 
 
   # Create a list consisting of a single element.  `singleton x' is
@@ -27,6 +27,10 @@ rec {
     then nul
     else foldl op (op nul (head list)) (tail list);
 
+  # map with index: `imap (i: v: "${v}-${toString i}") ["a" "b"] ==
+  # ["a-1" "b-2"]'
+  imap = f: list:
+    zipListsWith f (range 1 (length list)) list;
 
   # Concatenate a list of lists.
   concatLists = fold (x: y: x ++ y) [];
@@ -136,7 +140,7 @@ rec {
   zipListsWith = f: fst: snd:
     if fst != [] && snd != [] then
       [ (f (head fst) (head snd)) ]
-      ++ zipLists (tail fst) (tail snd)
+      ++ zipListsWith f (tail fst) (tail snd)
     else [];
 
   zipLists = zipListsWith (fst: snd: { inherit fst snd; });
diff --git a/pkgs/lib/maintainers.nix b/pkgs/lib/maintainers.nix
index b6f5b990c4e9..dadc7f813e9d 100644
--- a/pkgs/lib/maintainers.nix
+++ b/pkgs/lib/maintainers.nix
@@ -5,10 +5,12 @@
      alphabetically sorted.  */
 
   all = "Nix Committers <nix-commits@cs.uu.nl>";
-  andres = "Andres Loeh <andres@cs.uu.nl>";
+  andres = "Andres Loeh <ksnixos@andres-loeh.de>";
   astsmtl = "Alexander Tsamutali <astsmtl@yandex.ru>";
   bjg = "Brian Gough <bjg@gnu.org>";
+  chaoflow = "Florian Friesdorf <flo@chaoflow.net>";
   eelco = "Eelco Dolstra <e.dolstra@tudelft.nl>";
+  goibhniu = "Cillian de Róiste <cillian.deroiste@gmail.com>";
   guibert = "David Guibert <david.guibert@gmail.com>";
   kkallio = "Karn Kallio <tierpluspluslists@gmail.com>";
   ludo = "Ludovic Courtès <ludo@gnu.org>";
@@ -16,9 +18,11 @@
   neznalek = "Vladimír Čunát <vcunat@gmail.com>";
   phreedom = "Evgeny Egorochkin <phreedom.stdin@gmail.com>";
   pierron = "Nicolas B. Pierron <nixos@nbp.name>";
+  qknight = "Joachim Schiele <js@lastlog.de>";
   raskin = "Michael Raskin <7c6f434c@mail.ru>";
   roconnor = "Russell O'Connor <roconnor@theorem.ca>";
   sander = "Sander van der Burg <s.vanderburg@tudelft.nl>";
+  shlevy = "Shea Levy <shea@shealevy.com>";
   simons = "Peter Simons <simons@cryp.to>";
   thammers = "Tobias Hammerschmidt <jawr@gmx.de>";
   urkud = "Yury G. Kudryashov <urkud+nix@ya.ru>";
diff --git a/pkgs/lib/misc.nix b/pkgs/lib/misc.nix
index 7f04e7e1e581..df3956f1147a 100644
--- a/pkgs/lib/misc.nix
+++ b/pkgs/lib/misc.nix
@@ -216,7 +216,7 @@ rec {
 
   innerClosePropagation = ready: list: if list == [] then ready else
     if ! isAttrs (head list) then
-      builtins.trace ("not an attrSet: ${lib.showVal (head list)}") 
+      /* builtins.trace ("not an attrSet: ${lib.showVal (head list)}") */
         innerClosePropagation ready (tail list)
     else
       innerClosePropagation 
diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix
index 08c26e72f72e..8ecb04156e78 100644
--- a/pkgs/lib/modules.nix
+++ b/pkgs/lib/modules.nix
@@ -80,19 +80,29 @@ rec {
 
   moduleClosure = initModules: args:
     let
-      moduleImport = m:
+      moduleImport = origin: index: m:
         let m' = applyIfFunction (importIfPath m) args;
         in (unifyModuleSyntax m') // {
           # used by generic closure to avoid duplicated imports.
-          key = if isPath m then m else if m' ? key then m'.key else "<unknown location>";
+          key =
+            if isPath m then m
+            else if m' ? key then m'.key
+            else newModuleName origin index;
         };
 
       getImports = m: attrByPath ["imports"] [] m;
 
+      newModuleName = origin: index:
+        "${origin.key}:<import-${toString index}>";
+
+      topLevel = {
+        key = "<top-level>";
+      };
+
     in
       (lazyGenericClosure {
-        startSet = map moduleImport initModules;
-        operator = m: map moduleImport (getImports m);
+        startSet = imap (moduleImport topLevel) initModules;
+        operator = m: imap (moduleImport m) (getImports m);
       });
 
   selectDeclsAndDefs = modules:
diff --git a/pkgs/lib/properties.nix b/pkgs/lib/properties.nix
index 46854d0e1431..d7df14f716f5 100644
--- a/pkgs/lib/properties.nix
+++ b/pkgs/lib/properties.nix
@@ -223,6 +223,11 @@ rec {
       content = mkNotdef;
     };
 
+  mkAssert = assertion: message: content:
+    mkIf
+      (if assertion then true else throw "\nFailed assertion: ${message}")
+      content;
+
   # Remove all "If" statement defined on a value.
   rmIf = foldProperty (
       foldFilter isIf
diff --git a/pkgs/lib/strings.nix b/pkgs/lib/strings.nix
index 838990793276..73520a949c13 100644
--- a/pkgs/lib/strings.nix
+++ b/pkgs/lib/strings.nix
@@ -16,6 +16,7 @@ rec {
 
   # Map a function over a list and concatenate the resulting strings.
   concatMapStrings = f: list: concatStrings (map f list);
+  concatImapStrings = f: list: concatStrings (lib.imap f list);
   
 
   # Place an element between each element of a list, e.g.,
@@ -45,6 +46,10 @@ rec {
   makeLibraryPath = makeSearchPath "lib";
 
 
+  # Idem for Perl search paths.
+  makePerlPath = makeSearchPath "lib/perl5/site_perl";
+  
+
   # Dependening on the boolean `cond', return either the given string
   # or the empty string.
   optionalString = cond: string: if cond then string else "";
diff --git a/pkgs/lib/types.nix b/pkgs/lib/types.nix
index fd3c071c0bed..9a6bb4b24dd3 100644
--- a/pkgs/lib/types.nix
+++ b/pkgs/lib/types.nix
@@ -6,6 +6,7 @@ let lib = import ./default.nix; in
 with import ./lists.nix;
 with import ./attrsets.nix;
 with import ./options.nix;
+with import ./trivial.nix;
 
 rec {
 
@@ -16,7 +17,7 @@ rec {
     _type = typeName;
   };
 
-  
+
   # name (name of the type)
   # check (boolean function)
   # merge (default merge function)
@@ -43,7 +44,7 @@ rec {
       inherit name check merge iter fold docPath hasOptions delayOnGlobalEval;
     };
 
-    
+
   types = rec {
 
     inferred = mkOptionType {
@@ -75,7 +76,7 @@ rec {
 
     attrs = mkOptionType {
       name = "attribute set";
-      check = lib.traceValIfNot builtins.isAttrs;
+      check = lib.traceValIfNot isAttrs;
       merge = fold lib.mergeAttrs {};
     };
 
@@ -101,8 +102,8 @@ rec {
     };
 
     attrsOf = elemType: mkOptionType {
-      name = "attribute set of ${elemType}s";
-      check = x: lib.traceValIfNot builtins.isAttrs x
+      name = "attribute set of ${elemType.name}s";
+      check = x: lib.traceValIfNot isAttrs x
         && fold (e: v: v && elemType.check e) true (lib.attrValues x);
       merge = lib.zip (name: elemType.merge);
       iter = f: path: set: lib.mapAttrs (name: elemType.iter f (path + "." + name)) set;
@@ -111,6 +112,43 @@ rec {
       inherit (elemType) hasOptions delayOnGlobalEval;
     };
 
+    # List or attribute set of ...
+    loaOf = elemType:
+      let
+        convertIfList = defIdx: def:
+          if isList def then
+            listToAttrs (
+              flip imap def (elemIdx: elem:
+                nameValuePair "unnamed-${toString defIdx}.${toString elemIdx}" elem))
+          else
+            def;
+        listOnly = listOf elemType;
+        attrOnly = attrsOf elemType;
+
+      in mkOptionType {
+        name = "list or attribute set of ${elemType.name}s";
+        check = x:
+          if isList x       then listOnly.check x
+          else if isAttrs x then attrOnly.check x
+          else lib.traceValIfNot (x: false) x;
+        ## The merge function returns an attribute set
+        merge = defs:
+          attrOnly.merge (imap convertIfList defs);
+        iter = f: path: def:
+          if isList def       then listOnly.iter f path def
+          else if isAttrs def then attrOnly.iter f path def
+          else throw "Unexpected value";
+        fold = op: nul: def:
+          if isList def       then listOnly.fold op nul def
+          else if isAttrs def then attrOnly.fold op nul def
+          else throw "Unexpected value";
+
+        docPath = path: elemType.docPath (path + ".<name?>");
+        inherit (elemType) hasOptions delayOnGlobalEval;
+      }
+    ;
+
+
     uniq = elemType: mkOptionType {
       inherit (elemType) name check iter fold docPath hasOptions;
       merge = list: