about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/attrsets.nix2
-rw-r--r--lib/derivations.nix2
-rw-r--r--lib/modules.nix2
-rw-r--r--lib/strings.nix40
-rw-r--r--lib/systems/architectures.nix2
-rw-r--r--lib/systems/default.nix4
-rw-r--r--lib/systems/flake-systems.nix2
-rw-r--r--lib/tests/misc.nix4
-rwxr-xr-xlib/tests/modules.sh2
9 files changed, 27 insertions, 33 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix
index 511d619a1dc2f..4b663db2ce4a3 100644
--- a/lib/attrsets.nix
+++ b/lib/attrsets.nix
@@ -757,7 +757,7 @@ rec {
        matchAttrs :: AttrSet -> AttrSet -> Bool
   */
   matchAttrs =
-    # Attribute set strucutre to match
+    # Attribute set structure to match
     pattern:
     # Attribute set to find patterns in
     attrs:
diff --git a/lib/derivations.nix b/lib/derivations.nix
index 9a88087f2e34a..dce98b46ddb98 100644
--- a/lib/derivations.nix
+++ b/lib/derivations.nix
@@ -17,7 +17,7 @@ in
     situations below.
 
     For illustration and/or testing, we define derivation such that its
-    evaluation is very noticable.
+    evaluation is very noticeable.
 
         let derivation = throw "This won't be evaluated.";
 
diff --git a/lib/modules.nix b/lib/modules.nix
index 8cc8d67d600b1..caabfee5710e8 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -479,7 +479,7 @@ rec {
       ) (lib.functionArgs f);
 
       # Note: we append in the opposite order such that we can add an error
-      # context on the explicited arguments of "args" too. This update
+      # context on the explicit arguments of "args" too. This update
       # operator is used to make the "args@{ ... }: with args.lib;" notation
       # works.
     in f (args // extraArgs)
diff --git a/lib/strings.nix b/lib/strings.nix
index 9a4f29380d0de..8a19bc56ed5cb 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -185,7 +185,7 @@ rec {
   */
   makeBinPath = makeSearchPathOutput "bin" "bin";
 
-  /* Normalize path, removing extranous /s
+  /* Normalize path, removing extraneous /s
 
      Type: normalizePath :: string -> string
 
@@ -328,9 +328,9 @@ rec {
        escape ["(" ")"] "(foo)"
        => "\\(foo\\)"
   */
-  escape = list: replaceChars list (map (c: "\\${c}") list);
+  escape = list: replaceStrings list (map (c: "\\${c}") list);
 
-  /* Escape occurence of the element of `list` in `string` by
+  /* Escape occurrence of the element of `list` in `string` by
      converting to its ASCII value and prefixing it with \\x.
      Only works for printable ascii characters.
 
@@ -341,7 +341,7 @@ rec {
        => "foo\\x20bar"
 
   */
-  escapeC = list: replaceChars list (map (c: "\\x${ toLower (lib.toHexString (charToInt c))}") list);
+  escapeC = list: replaceStrings list (map (c: "\\x${ toLower (lib.toHexString (charToInt c))}") list);
 
   /* Quote string to be used safely within the Bourne shell.
 
@@ -471,19 +471,8 @@ rec {
     ["\"" "'" "<" ">" "&"]
     ["&quot;" "&apos;" "&lt;" "&gt;" "&amp;"];
 
-  # Obsolete - use replaceStrings instead.
-  replaceChars = builtins.replaceStrings or (
-    del: new: s:
-    let
-      substList = lib.zipLists del new;
-      subst = c:
-        let found = lib.findFirst (sub: sub.fst == c) null substList; in
-        if found == null then
-          c
-        else
-          found.snd;
-    in
-      stringAsChars subst s);
+  # warning added 12-12-2022
+  replaceChars = lib.warn "replaceChars is a deprecated alias of replaceStrings, replace usages of it with replaceStrings." builtins.replaceStrings;
 
   # Case conversion utilities.
   lowerChars = stringToCharacters "abcdefghijklmnopqrstuvwxyz";
@@ -497,7 +486,7 @@ rec {
        toLower "HOME"
        => "home"
   */
-  toLower = replaceChars upperChars lowerChars;
+  toLower = replaceStrings upperChars lowerChars;
 
   /* Converts an ASCII string to upper-case.
 
@@ -507,7 +496,7 @@ rec {
        toUpper "home"
        => "HOME"
   */
-  toUpper = replaceChars lowerChars upperChars;
+  toUpper = replaceStrings lowerChars upperChars;
 
   /* Appends string context from another string.  This is an implementation
      detail of Nix and should be used carefully.
@@ -860,9 +849,9 @@ rec {
   */
   toInt = str:
     let
-      # RegEx: Match any leading whitespace, then any digits, and finally match any trailing
-      # whitespace.
-      strippedInput = match "[[:space:]]*([[:digit:]]+)[[:space:]]*" str;
+      # RegEx: Match any leading whitespace, possibly a '-', one or more digits,
+      # and finally match any trailing whitespace.
+      strippedInput = match "[[:space:]]*(-?[[:digit:]]+)[[:space:]]*" str;
 
       # RegEx: Match a leading '0' then one or more digits.
       isLeadingZero = match "0[[:digit:]]+" (head strippedInput) == [];
@@ -911,9 +900,10 @@ rec {
   */
   toIntBase10 = str:
     let
-      # RegEx: Match any leading whitespace, then match any zero padding, capture any remaining
-      # digits after that, and finally match any trailing whitespace.
-      strippedInput = match "[[:space:]]*0*([[:digit:]]+)[[:space:]]*" str;
+      # RegEx: Match any leading whitespace, then match any zero padding,
+      # capture possibly a '-' followed by one or more digits,
+      # and finally match any trailing whitespace.
+      strippedInput = match "[[:space:]]*0*(-?[[:digit:]]+)[[:space:]]*" str;
 
       # RegEx: Match at least one '0'.
       isZero = match "0+" (head strippedInput) == [];
diff --git a/lib/systems/architectures.nix b/lib/systems/architectures.nix
index ddc320d24e0a0..94127fa90b351 100644
--- a/lib/systems/architectures.nix
+++ b/lib/systems/architectures.nix
@@ -67,7 +67,7 @@ rec {
     #
     # Note:
     #
-    # - The succesors of `skylake` (`cannonlake`, `icelake`, etc) use `avx512`
+    # - The successors of `skylake` (`cannonlake`, `icelake`, etc) use `avx512`
     #   which no current AMD Zen michroarch support.
     # - `znver1` uses `ABM`, `CLZERO`, `CX16`, `MWAITX`, and `SSE4A` which no
     #   current Intel microarch support.
diff --git a/lib/systems/default.nix b/lib/systems/default.nix
index ca5186ca47680..4c1e9d9f25364 100644
--- a/lib/systems/default.nix
+++ b/lib/systems/default.nix
@@ -20,7 +20,7 @@ rec {
   # necessary.
   #
   # `parsed` is inferred from args, both because there are two options with one
-  # clearly prefered, and to prevent cycles. A simpler fixed point where the RHS
+  # clearly preferred, and to prevent cycles. A simpler fixed point where the RHS
   # always just used `final.*` would fail on both counts.
   elaborate = args': let
     args = if lib.isString args' then { system = args'; }
@@ -62,7 +62,7 @@ rec {
       linker =
         /**/ if final.useLLVM or false      then "lld"
         else if final.isDarwin              then "cctools"
-        # "bfd" and "gold" both come from GNU binutils. The existance of Gold
+        # "bfd" and "gold" both come from GNU binutils. The existence of Gold
         # is why we use the more obscure "bfd" and not "binutils" for this
         # choice.
         else                                     "bfd";
diff --git a/lib/systems/flake-systems.nix b/lib/systems/flake-systems.nix
index 74124c32e8369..b1988c6a4fbb0 100644
--- a/lib/systems/flake-systems.nix
+++ b/lib/systems/flake-systems.nix
@@ -1,6 +1,6 @@
 # See [RFC 46] for mandated platform support and ../../pkgs/stdenv for
 # implemented platform support. This list is mainly descriptive, i.e. all
-# system doubles for platforms where nixpkgs can do native compiliation
+# system doubles for platforms where nixpkgs can do native compilation
 # reasonably well are included.
 #
 # [RFC 46]: https://github.com/NixOS/rfcs/blob/master/rfcs/0046-platform-support-tiers.md
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 648c05ab35720..c719fcf5d4fae 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -339,6 +339,8 @@ runTests {
     (0 == toInt " 0")
     (0 == toInt "0 ")
     (0 == toInt " 0 ")
+    (-1 == toInt "-1")
+    (-1 == toInt " -1 ")
   ];
 
   testToIntFails = testAllTrue [
@@ -383,6 +385,8 @@ runTests {
     (0 == toIntBase10 " 000000")
     (0 == toIntBase10 "000000 ")
     (0 == toIntBase10 " 000000 ")
+    (-1 == toIntBase10 "-1")
+    (-1 == toIntBase10 " -1 ")
   ];
 
   testToIntBase10Fails = testAllTrue [
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 75b316c972120..cde4da6439372 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -246,7 +246,7 @@ checkConfigError 'A definition for option .* is not of type .*' \
 ## Freeform modules
 # Assigning without a declared option should work
 checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix
-# No freeform assigments shouldn't make it error
+# No freeform assignments shouldn't make it error
 checkConfigOutput '^{ }$' config ./freeform-attrsOf.nix
 # but only if the type matches
 checkConfigError 'A definition for option .* is not of type .*' config.value ./freeform-attrsOf.nix ./define-value-list.nix