at 22.05-pre 929 B view raw
1/* Version string functions. */ 2{ lib }: 3 4rec { 5 6 /* Break a version string into its component parts. 7 8 Example: 9 splitVersion "1.2.3" 10 => ["1" "2" "3"] 11 */ 12 splitVersion = builtins.splitVersion or (lib.splitString "."); 13 14 /* Get the major version string from a string. 15 16 Example: 17 major "1.2.3" 18 => "1" 19 */ 20 major = v: builtins.elemAt (splitVersion v) 0; 21 22 /* Get the minor version string from a string. 23 24 Example: 25 minor "1.2.3" 26 => "2" 27 */ 28 minor = v: builtins.elemAt (splitVersion v) 1; 29 30 /* Get the patch version string from a string. 31 32 Example: 33 patch "1.2.3" 34 => "3" 35 */ 36 patch = v: builtins.elemAt (splitVersion v) 2; 37 38 /* Get string of the first two parts (major and minor) 39 of a version string. 40 41 Example: 42 majorMinor "1.2.3" 43 => "1.2" 44 */ 45 majorMinor = v: 46 builtins.concatStringsSep "." 47 (lib.take 2 (splitVersion v)); 48 49}