summary refs log tree commit diff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2016-01-05 20:08:22 +0100
committerPeter Simons <simons@cryp.to>2016-01-05 20:09:39 +0100
commit7ca8e139189ff3935dbe6ef12ff014cf8e028e04 (patch)
treee4249f4417b298b0760c0b6146f641026fbe6fd0 /lib/strings.nix
parent9af50919926f5ee654593a67c3446f0bf2f1a015 (diff)
downloadnixlib-7ca8e139189ff3935dbe6ef12ff014cf8e028e04.tar
nixlib-7ca8e139189ff3935dbe6ef12ff014cf8e028e04.tar.gz
nixlib-7ca8e139189ff3935dbe6ef12ff014cf8e028e04.tar.bz2
nixlib-7ca8e139189ff3935dbe6ef12ff014cf8e028e04.tar.lz
nixlib-7ca8e139189ff3935dbe6ef12ff014cf8e028e04.tar.xz
nixlib-7ca8e139189ff3935dbe6ef12ff014cf8e028e04.tar.zst
nixlib-7ca8e139189ff3935dbe6ef12ff014cf8e028e04.zip
lib.getVersion: extend the function to cope with strings as well as derivations
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 098da975c601..fc6c2152b9fc 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -189,9 +189,13 @@ rec {
   versionAtLeast = v1: v2: !versionOlder v1 v2;
 
 
-  # Get the version of the specified derivation, as specified in its
-  # ‘name’ attribute.
-  getVersion = drv: (builtins.parseDrvName drv.name).version;
+  # This function takes an argument that's either a derivation or a
+  # derivation's "name" attribute and extracts the version part from that
+  # argument. For example:
+  #
+  #    lib.getVersion "youtube-dl-2016.01.01" ==> "2016.01.01"
+  #    lib.getVersion pkgs.youtube-dl         ==> "2016.01.01"
+  getVersion = x: (builtins.parseDrvName (x.name or x)).version;
 
 
   # Extract name with version from URL. Ask for separator which is