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

When updating to the newest JSON library version (beginning 3.8.0), nix fails to build #4019

Closed
OmnipotentEntity opened this issue Sep 15, 2020 · 3 comments
Labels

Comments

@OmnipotentEntity
Copy link
Contributor

OmnipotentEntity commented Sep 15, 2020

Describe the bug

Nix fails to build with the following error message when using a version of nlohmann's json library that includes the binary type feature.

builder for '/nix/store/cd3a1sxaq9idl129bvgbgrazpfnpp792-nix-3.0pre20200829_f156513.drv' failed with exit code 2; last 10 log lines:
                   from src/libexpr/json-to-value.cc:4:
  /nix/store/a15crh4aa98283pmx0gxzchgi39547qf-nlohmann_json-3.9.1/include/nlohmann/detail/input/binary_reader.hpp:289:113: error: 'nlohmann::json_sax<nlohmann::basic_json<> >' is not an accessible base of 'nlohmann::detail::binary_reader<nlohmann::basic_json<>, nlohmann::detail::iterator_input_adapter<__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> > >, nix::JSONSax>::json_sax_t' {aka 'nix::JSONSax'}
    289 |                 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
    CXX    src/nix/repl.o
    CXX    src/libexpr/nixexpr.o
    CXX    src/nix/registry.o
    CXX    src/nix/profile.o
    CXX    src/nix/ping-store.o
  make: *** [mk/patterns.mk:3: src/libexpr/json-to-value.o] Error 1
  make: *** Waiting for unfinished jobs....

Steps To Reproduce

  1. nix run -I nixpkgs=channel:nixos-unstable nixpkgs.nixpkgs-review -c nixpkgs-review pr 97266

Expected behavior

Builds

nix-env --version output

nix-env (Nix) 2.3.6

Additional context

This was caused by changes to the Sax class in version 3.8.0 to accommodate a new internal type called "binary" which handles binary input/output from binary filetypes (such as CBOR and BSON). You'll need to implement a binary method in the nix::JSONSax class. I do not think you are currently using binary types, so you can just implement a "do nothing" version safely. There are examples of this in the nlohmann JSON tests.

@matthewbauer
Copy link
Member

I just had to add bool binary(binary_t& val) for this to work with 3.8.0. I bet more stuff changed with 3.9.0 though.

obsidiansystems@d2f52cb#diff-d00c80d9496f26e308e2d07d1ee91a0f

@OmnipotentEntity
Copy link
Contributor Author

OmnipotentEntity commented Sep 17, 2020

You'll definitely want a return true in that function. Otherwise, if you somehow call it you'll trigger UB.

Thanks for giving me an easy thing to test against though!

@matthewbauer
Copy link
Member

You'll definitely want a return true in that function. Otherwise, if you somehow call it you'll trigger UB.

Thanks for giving me an easy thing to test against though!

Yeah - although throw might be better - we can't really do much with binary data here.

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

No branches or pull requests

2 participants