diff options
author | Vladimír Čunát <v@cunat.cz> | 2020-08-04 21:38:08 +0200 |
---|---|---|
committer | Vladimír Čunát <v@cunat.cz> | 2020-08-04 21:38:08 +0200 |
commit | 01c2ba857590ca8d156682e478d297201b715ea2 (patch) | |
tree | 132d524d390bbdf5f08a3b3d9e251ea82177909f /lib | |
parent | ccedb29f4b0b3a02f28be0a06cae480da2be432b (diff) | |
parent | 8bbc202208d0a972e1a1a973f19b4ae0415bce4b (diff) |
Merge branch 'staging-next' into staging
Diffstat (limited to 'lib')
-rw-r--r-- | lib/generators.nix | 6 | ||||
-rw-r--r-- | lib/licenses.nix | 5 | ||||
-rw-r--r-- | lib/strings.nix | 16 |
3 files changed, 25 insertions, 2 deletions
diff --git a/lib/generators.nix b/lib/generators.nix index efe6ea6031d33..abd237eb7d377 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -48,8 +48,10 @@ rec { else if isAttrs v then err "attrsets" v # functions can’t be printed of course else if isFunction v then err "functions" v - # let’s not talk about floats. There is no sensible `toString` for them. - else if isFloat v then err "floats" v + # Floats currently can't be converted to precise strings, + # condition warning on nix version once this isn't a problem anymore + # See https://github.com/NixOS/nix/pull/3480 + else if isFloat v then libStr.floatToString v else err "this value is" (toString v); diff --git a/lib/licenses.nix b/lib/licenses.nix index 2c6da3a865f8b..2f9fc04cb7cb6 100644 --- a/lib/licenses.nix +++ b/lib/licenses.nix @@ -110,6 +110,11 @@ lib.mapAttrs (n: v: v // { shortName = n; }) { fullName = ''BSD 4-clause "Original" or "Old" License''; }; + bsdProtection = spdx { + spdxId = "BSD-Protection"; + fullName = "BSD Protection License"; + }; + bsl11 = { fullName = "Business Source License 1.1"; url = "https://mariadb.com/bsl11"; diff --git a/lib/strings.nix b/lib/strings.nix index 74e3eaa0722de..0baa942355c0e 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -612,6 +612,22 @@ rec { */ fixedWidthNumber = width: n: fixedWidthString width "0" (toString n); + /* Convert a float to a string, but emit a warning when precision is lost + during the conversion + + Example: + floatToString 0.000001 + => "0.000001" + floatToString 0.0000001 + => trace: warning: Imprecise conversion from float to string 0.000000 + "0.000000" + */ + floatToString = float: let + result = toString float; + precise = float == builtins.fromJSON result; + in if precise then result + else lib.warn "Imprecise conversion from float to string ${result}" result; + /* Check whether a value can be coerced to a string */ isCoercibleToString = x: builtins.elem (builtins.typeOf x) [ "path" "string" "null" "int" "float" "bool" ] || |