Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generators: make toPretty handle floats correctly #48328

Merged
merged 1 commit into from Oct 15, 2018

Conversation

Ekleog
Copy link
Member

@Ekleog Ekleog commented Oct 13, 2018

Motivation for this change

Tested via the lib/tests/misc.nix “test runner”.

Please consider backporting to 18.09 :)

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@Profpatsch
Copy link
Member

I’m not sure it is possible to handle floats “correctly” in nix, because they are implemented very, very, very badly.

2.1111111111111111 == "2.111111"

So I’d rather abort when somebody tries to apply toPretty to them in any way.

@Ekleog
Copy link
Member Author

Ekleog commented Oct 14, 2018

Well, anyway when you toPretty a string with " in it it returns a value that doesn't parse as nix code (because the " isn't escaped), so I'd think it's really done only for user-facing output and it's better to display something than just crash? :) (also, you forgot the toString in your example here)

@Profpatsch
Copy link
Member

Well, anyway when you toPretty a string with " in it it returns a value that doesn't parse as nix code

Ah, right. toPretty should be okay, but the rest of generators shouldn’t provide builtin support for floats until they don’t lose information (what use is a datatype for a configuration language that can’t be correctly transformed into a string after all).

@@ -143,6 +143,7 @@ rec {
}@args: v: with builtins;
let isPath = v: typeOf v == "path";
in if isInt v then toString v
else if isFloat v then toString v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"~${toString v}"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@Profpatsch Profpatsch merged commit 455e0ed into NixOS:master Oct 15, 2018
@Profpatsch
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants