about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix2
-rw-r--r--lib/tests/misc.nix15
-rw-r--r--lib/versions.nix12
3 files changed, 24 insertions, 5 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 18d2dfae1e183..f293a1defb11c 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -134,5 +134,7 @@ let
       mergeAttrsByFuncDefaultsClean mergeAttrBy
       fakeSha256 fakeSha512
       nixType imap;
+    inherit (versions)
+      splitVersion;
   });
 in lib
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index d8f412d3fc49a..e5d76d4e57b75 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -102,6 +102,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/versions.nix b/lib/versions.nix
index 2c05445b3dd07..0e9d81ac78b1e 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.