about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2019-11-24 17:25:07 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2019-11-24 17:25:07 +0000
commitd0d5136cce5e0cbe2305c53090bd4bd886114746 (patch)
tree70092947536a3c65e215df9df20e571e34652f7a /lib
parent9b090ccbca3f7dd26d91db06e96e8bf8282c37ca (diff)
parent195c263a812dec532656dcfd5d0360458cdc93fd (diff)
downloadnixlib-d0d5136cce5e0cbe2305c53090bd4bd886114746.tar
nixlib-d0d5136cce5e0cbe2305c53090bd4bd886114746.tar.gz
nixlib-d0d5136cce5e0cbe2305c53090bd4bd886114746.tar.bz2
nixlib-d0d5136cce5e0cbe2305c53090bd4bd886114746.tar.lz
nixlib-d0d5136cce5e0cbe2305c53090bd4bd886114746.tar.xz
nixlib-d0d5136cce5e0cbe2305c53090bd4bd886114746.tar.zst
nixlib-d0d5136cce5e0cbe2305c53090bd4bd886114746.zip
Merge remote-tracking branch 'upstream/master' into wrapper-pname-support
Diffstat (limited to 'lib')
-rw-r--r--lib/attrsets.nix2
-rw-r--r--lib/customisation.nix37
-rw-r--r--lib/default.nix6
-rw-r--r--lib/licenses.nix11
-rw-r--r--lib/modules.nix14
-rw-r--r--lib/systems/default.nix1
-rw-r--r--lib/systems/parse.nix1
-rw-r--r--lib/tests/misc.nix40
-rw-r--r--lib/trivial.nix39
-rw-r--r--lib/versions.nix12
10 files changed, 133 insertions, 30 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix
index d374d229f597..086c3d746fc1 100644
--- a/lib/attrsets.nix
+++ b/lib/attrsets.nix
@@ -354,7 +354,7 @@ rec {
        => { a = ["x" "y"]; b = ["z"] }
   */
   zipAttrsWith = f: sets: zipAttrsWithNames (concatMap attrNames sets) f sets;
-  /* Like `zipAttrsWith' with `(name: values: value)' as the function.
+  /* Like `zipAttrsWith' with `(name: values: values)' as the function.
 
     Example:
       zipAttrs [{a = "x";} {a = "y"; b = "z";}]
diff --git a/lib/customisation.nix b/lib/customisation.nix
index 3be36fcd719b..ac234e3b8c6f 100644
--- a/lib/customisation.nix
+++ b/lib/customisation.nix
@@ -66,22 +66,31 @@ rec {
   */
   makeOverridable = f: origArgs:
     let
-      ff = f origArgs;
+      result = f origArgs;
+
+      # Creates a functor with the same arguments as f
+      copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f);
+      # Changes the original arguments with (potentially a function that returns) a set of new attributes
       overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
+
+      # Re-call the function but with different arguments
+      overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs));
+      # Change the result of the function call by applying g to it
+      overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
     in
-      if builtins.isAttrs ff then (ff // {
-        override = newArgs: makeOverridable f (overrideWith newArgs);
-        overrideDerivation = fdrv:
-          makeOverridable (args: overrideDerivation (f args) fdrv) origArgs;
-        ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv:
-          makeOverridable (args: (f args).overrideAttrs fdrv) origArgs;
-      })
-      else if lib.isFunction ff then {
-        override = newArgs: makeOverridable f (overrideWith newArgs);
-        __functor = self: ff;
-        overrideDerivation = throw "overrideDerivation not yet supported for functors";
-      }
-      else ff;
+      if builtins.isAttrs result then
+        result // {
+          override = overrideArgs;
+          overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv);
+          ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv:
+            overrideResult (x: x.overrideAttrs fdrv);
+        }
+      else if lib.isFunction result then
+        # Transform the result into a functor while propagating its arguments
+        lib.setFunctionArgs result (lib.functionArgs result) // {
+          override = overrideArgs;
+        }
+      else result;
 
 
   /* Call the package function in the file `fn' with the required
diff --git a/lib/default.nix b/lib/default.nix
index 0e840dd6c9e6..8af531525860 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -57,8 +57,8 @@ let
       hasAttr head isAttrs isBool isInt isList isString length
       lessThan listToAttrs pathExists readFile replaceStrings seq
       stringLength sub substring tail;
-    inherit (trivial) id const concat or and bitAnd bitOr bitXor bitNot
-      boolToString mergeAttrs flip mapNullable inNixShell min max
+    inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor
+      bitNot boolToString mergeAttrs flip mapNullable inNixShell min max
       importJSON warn info showWarnings nixpkgsVersion version mod compare
       splitByAndCompare functionArgs setFunctionArgs isFunction;
     inherit (fixedPoints) fix fix' converge extends composeExtensions
@@ -135,5 +135,7 @@ let
       mergeAttrsByFuncDefaultsClean mergeAttrBy
       fakeSha256 fakeSha512
       nixType imap;
+    inherit (versions)
+      splitVersion;
   });
 in lib
diff --git a/lib/licenses.nix b/lib/licenses.nix
index 83e1ec7748d5..986b7fa1fdd9 100644
--- a/lib/licenses.nix
+++ b/lib/licenses.nix
@@ -218,9 +218,9 @@ lib.mapAttrs (n: v: v // { shortName = n; }) {
     fullName = "Common Public License 1.0";
   };
 
-  curl = {
-    fullName = "MIT/X11 derivate";
-    url = "https://curl.haxx.se/docs/copyright.html";
+  curl = spdx {
+    spdxId = "curl";
+    fullName = "curl License";
   };
 
   doc = spdx {
@@ -613,6 +613,11 @@ lib.mapAttrs (n: v: v // { shortName = n; }) {
     url = https://enterprise.dejacode.com/licenses/public/purdue-bsd;
   };
 
+  qhull = spdx {
+    spdxId = "Qhull";
+    fullName = "Qhull License";
+  };
+
   qpl = spdx {
     spdxId = "QPL-1.0";
     fullName = "Q Public License 1.0";
diff --git a/lib/modules.nix b/lib/modules.nix
index c3c903c1dfa8..44db77b5d1c6 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -326,6 +326,8 @@ rec {
 
       # The value with a check that it is defined
       valueDefined = if res.isDefined then res.mergedValue else
+        # (nixos-option detects this specific error message and gives it special
+        # handling.  If changed here, please change it there too.)
         throw "The option `${showOption loc}' is used but not defined.";
 
       # Apply the 'apply' function to the merged value. This allows options to
@@ -591,12 +593,16 @@ rec {
     { options, ... }:
     { options = setAttrByPath optionName (mkOption {
         visible = false;
+        apply = x: throw "The option `${showOption optionName}' can no longer be used since it's been removed. ${replacementInstructions}";
       });
-      config.warnings =
-        let opt = getAttrFromPath optionName options; in
-        optional opt.isDefined ''
+      config.assertions =
+        let opt = getAttrFromPath optionName options; in [{
+          assertion = !opt.isDefined;
+          message = ''
             The option definition `${showOption optionName}' in ${showFiles opt.files} no longer has any effect; please remove it.
-            ${replacementInstructions}'';
+            ${replacementInstructions}
+          '';
+        }];
     };
 
   /* Return a module that causes a warning to be shown if the
diff --git a/lib/systems/default.nix b/lib/systems/default.nix
index 0c0cdf1f11b1..0d51be4b23bc 100644
--- a/lib/systems/default.nix
+++ b/lib/systems/default.nix
@@ -79,6 +79,7 @@ rec {
         else if final.isAarch64 then "arm64"
         else if final.isx86_32 then "x86"
         else if final.isx86_64 then "ia64"
+        else if final.isMips then "mips"
         else final.parsed.cpu.name;
 
       qemuArch =
diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix
index 5a3805cf997a..362357446025 100644
--- a/lib/systems/parse.nix
+++ b/lib/systems/parse.nix
@@ -330,6 +330,7 @@ rec {
         }
       ];
     };
+    gnuabi64     = { abi = "64"; };
 
     musleabi     = { float = "soft"; };
     musleabihf   = { float = "hard"; };
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index d8f412d3fc49..b064faa1e1ba 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -18,6 +18,31 @@ runTests {
     expected = 2;
   };
 
+  testPipe = {
+    expr = pipe 2 [
+      (x: x + 2) # 2 + 2 = 4
+      (x: x * 2) # 4 * 2 = 8
+    ];
+    expected = 8;
+  };
+
+  testPipeEmpty = {
+    expr = pipe 2 [];
+    expected = 2;
+  };
+
+  testPipeStrings = {
+    expr = pipe [ 3 4 ] [
+      (map toString)
+      (map (s: s + "\n"))
+      concatStrings
+    ];
+    expected = ''
+      3
+      4
+    '';
+  };
+
   /*
   testOr = {
     expr = or true false;
@@ -102,6 +127,21 @@ runTests {
     expected = [ "2001" "db8" "0" "0042" "" "8a2e" "370" "" ];
   };
 
+  testSplitVersionSingle = {
+    expr = versions.splitVersion "1";
+    expected = [ "1" ];
+  };
+
+  testSplitVersionDouble = {
+    expr = versions.splitVersion "1.2";
+    expected = [ "1" "2" ];
+  };
+
+  testSplitVersionTriple = {
+    expr = versions.splitVersion "1.2.3";
+    expected = [ "1" "2" "3" ];
+  };
+
   testIsStorePath =  {
     expr =
       let goodPath =
diff --git a/lib/trivial.nix b/lib/trivial.nix
index f2710a6f0338..3a25e31fb052 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -29,6 +29,43 @@ rec {
     # Value to ignore
     y: x;
 
+  /* Pipes a value through a list of functions, left to right.
+
+     Type: pipe :: a -> [<functions>] -> <return type of last function>
+     Example:
+       pipe 2 [
+         (x: x + 2)  # 2 + 2 = 4
+         (x: x * 2)  # 4 * 2 = 8
+       ]
+       => 8
+
+       # ideal to do text transformations
+       pipe [ "a/b" "a/c" ] [
+
+         # create the cp command
+         (map (file: ''cp "${src}/${file}" $out\n''))
+
+         # concatenate all commands into one string
+         lib.concatStrings
+
+         # make that string into a nix derivation
+         (pkgs.runCommand "copy-to-out" {})
+
+       ]
+       => <drv which copies all files to $out>
+
+     The output type of each function has to be the input type
+     of the next function, and the last function returns the
+     final value.
+  */
+  pipe = val: functions:
+    let reverseApply = x: f: f x;
+    in builtins.foldl' reverseApply val functions;
+  /* note please don’t add a function like `compose = flip pipe`.
+     This would confuse users, because the order of the functions
+     in the list is not clear. With pipe, it’s obvious that it
+     goes first-to-last. With `compose`, not so much.
+  */
 
   ## Named versions corresponding to some builtin operators.
 
@@ -134,7 +171,7 @@ rec {
      On each release the first letter is bumped and a new animal is chosen
      starting with that new letter.
   */
-  codeName = "Loris";
+  codeName = "Markhor";
 
   /* Returns the current nixpkgs version suffix as string. */
   versionSuffix =
diff --git a/lib/versions.nix b/lib/versions.nix
index 2c05445b3dd0..0e9d81ac78b1 100644
--- a/lib/versions.nix
+++ b/lib/versions.nix
@@ -1,13 +1,15 @@
 /* Version string functions. */
 { lib }:
 
-let
+rec {
 
-  splitVersion = builtins.splitVersion or (lib.splitString ".");
-
-in
+  /* Break a version string into its component parts.
 
-{
+     Example:
+       splitVersion "1.2.3"
+       => ["1" "2" "3"]
+  */
+  splitVersion = builtins.splitVersion or (lib.splitString ".");
 
   /* Get the major version string from a string.