diff options
author | Alyssa Ross <hi@alyssa.is> | 2023-12-15 19:32:38 +0100 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-12-15 19:32:38 +0100 |
commit | 6b8e2555ef013b579cda57025b17d662e0f1fe1f (patch) | |
tree | 5a83c673af26c9976acd5a5dfa20e09e06898047 /nixpkgs/lib/strings.nix | |
parent | 66ca7a150b5c051f0728f13134e6265cc46f370c (diff) | |
parent | 02357adddd0889782362d999628de9d309d202dc (diff) | |
download | nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.gz nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.bz2 nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.lz nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.xz nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.zst nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.zip |
Merge branch 'nixos-unstable-small' of https://github.com/NixOS/nixpkgs
Diffstat (limited to 'nixpkgs/lib/strings.nix')
-rw-r--r-- | nixpkgs/lib/strings.nix | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/nixpkgs/lib/strings.nix b/nixpkgs/lib/strings.nix index 695aaaacd348..49654d8abaa7 100644 --- a/nixpkgs/lib/strings.nix +++ b/nixpkgs/lib/strings.nix @@ -715,12 +715,12 @@ rec { getName pkgs.youtube-dl => "youtube-dl" */ - getName = x: - let - parse = drv: (parseDrvName drv).name; - in if isString x - then parse x - else x.pname or (parse x.name); + getName = let + parse = drv: (parseDrvName drv).name; + in x: + 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 @@ -732,12 +732,12 @@ rec { getVersion pkgs.youtube-dl => "2016.01.01" */ - getVersion = x: - let - parse = drv: (parseDrvName drv).version; - in if isString x - then parse x - else x.version or (parse x.name); + getVersion = let + parse = drv: (parseDrvName drv).version; + in x: + if isString x + then parse x + else x.version or (parse x.name); /* Extract name with version from URL. Ask for separator which is supposed to start extension. @@ -771,12 +771,13 @@ rec { cmakeOptionType "string" "ENGINE" "sdl2" => "-DENGINE:STRING=sdl2" */ - cmakeOptionType = type: feature: value: - assert (lib.elem (lib.toUpper type) - [ "BOOL" "FILEPATH" "PATH" "STRING" "INTERNAL" ]); - assert (lib.isString feature); - assert (lib.isString value); - "-D${feature}:${lib.toUpper type}=${value}"; + cmakeOptionType = let + types = [ "BOOL" "FILEPATH" "PATH" "STRING" "INTERNAL" ]; + in type: feature: value: + assert (elem (toUpper type) types); + assert (isString feature); + assert (isString value); + "-D${feature}:${toUpper type}=${value}"; /* Create a -D<condition>={TRUE,FALSE} string that can be passed to typical CMake invocations. @@ -977,9 +978,11 @@ rec { Many types of value are coercible to string this way, including int, float, null, bool, list of similarly coercible values. */ - isConvertibleWithToString = x: + isConvertibleWithToString = let + types = [ "null" "int" "float" "bool" ]; + in x: isStringLike x || - elem (typeOf x) [ "null" "int" "float" "bool" ] || + elem (typeOf x) types || (isList x && lib.all isConvertibleWithToString x); /* Check whether a value can be coerced to a string. |