From 5ae3fb2c3804a74251c359d603e00bd947aaea15 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sat, 7 Mar 2020 02:44:56 +0100 Subject: lib/strings: Add floatToString --- lib/strings.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') 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" ] || -- cgit 1.4.1 From 9df69cba054c3b5d3a3b67778e0d2947eba3f297 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 13 Dec 2019 00:24:30 +0100 Subject: lib/generators: Extend mkValueStringDefault with float support --- lib/generators.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') 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); -- cgit 1.4.1 From f26cbd0caa96d491532a11da5477c67e5f7fceef Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Mon, 3 Aug 2020 21:20:05 +0100 Subject: licenses: add bsdProtection see https://spdx.org/licenses/BSD-Protection.html --- lib/licenses.nix | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') 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"; -- cgit 1.4.1