diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2019-11-24 16:19:32 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2019-11-24 16:24:50 +0000 |
commit | 84a105254d52d8ded6c5365399b61bea14505cd7 (patch) | |
tree | 3932ddfd313b2f3e48fd13f8bf266310a7ce27ba /lib/strings.nix | |
parent | 62d64297932068b5afa25fb66ed396cd38ef293a (diff) |
lib: Add getName to mirror getVersion
Diffstat (limited to 'lib/strings.nix')
-rw-r--r-- | lib/strings.nix | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index ae0d74c6721d..6dbb3d3a3e8b 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -473,6 +473,23 @@ rec { versionAtLeast = v1: v2: !versionOlder v1 v2; /* This function takes an argument that's either a derivation or a + derivation's "name" attribute and extracts the name part from that + argument. + + Example: + getName "youtube-dl-2016.01.01" + => "youtube-dl" + getName pkgs.youtube-dl + => "youtube-dl" + */ + getName = x: + let + parse = drv: (builtins.parseDrvName drv).name; + in if isString x + then parse x + else x.pname or (parse x.name); + + /* This function takes an argument that's either a derivation or a derivation's "name" attribute and extracts the version part from that argument. |