From 9c04c629e5e39c7ec55bbaf3590bf3b553faa2c2 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 6 Nov 2025 16:51:19 -0500 Subject: [PATCH] `UnkeyedValidPathInfo::fromJSON` Remove support for older version It turns out this code path is only used for unit tests (to ensure our JSON formats are possible to parse by other code, elsewhere). No user-facing functionality consumes this format. Therefore, let's drop the old version parsing support. --- doc/manual/rl-next/json-format-changes.md | 2 +- src/libstore/derivation-options.cc | 9 ------- src/libstore/path-info.cc | 30 ++++++++-------------- src/libutil/include/nix/util/json-utils.hh | 9 +++++++ 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/doc/manual/rl-next/json-format-changes.md b/doc/manual/rl-next/json-format-changes.md index c5518ee1b..ef442c27e 100644 --- a/doc/manual/rl-next/json-format-changes.md +++ b/doc/manual/rl-next/json-format-changes.md @@ -22,7 +22,7 @@ The store path info JSON format has been updated from version 1 to version 2: - New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}` - Still `null` values for input-addressed store objects -Version 1 format is still accepted when reading for backward compatibility. +Nix currently only produces, and doesn't consume this format. **Affected command**: `nix path-info --json` diff --git a/src/libstore/derivation-options.cc b/src/libstore/derivation-options.cc index 75313841c..265f28e80 100644 --- a/src/libstore/derivation-options.cc +++ b/src/libstore/derivation-options.cc @@ -423,15 +423,6 @@ void adl_serializer::to_json(json & json, const DerivationOpt json["allowSubstitutes"] = o.allowSubstitutes; } -template -static inline std::optional ptrToOwned(const json * ptr) -{ - if (ptr) - return std::optional{*ptr}; - else - return std::nullopt; -} - DerivationOptions::OutputChecks adl_serializer::from_json(const json & json_) { auto & json = getObject(json_); diff --git a/src/libstore/path-info.cc b/src/libstore/path-info.cc index c535d08f4..7d8bf4911 100644 --- a/src/libstore/path-info.cc +++ b/src/libstore/path-info.cc @@ -192,13 +192,10 @@ UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store auto & json = getObject(_json); - // Check version (optional for backward compatibility) - nlohmann::json::number_unsigned_t version = 1; - if (json.contains("version")) { - version = getUnsigned(valueAt(json, "version")); - if (version != 1 && version != 2) { - throw Error("Unsupported path info JSON format version %d, expected 1 through 2", version); - } + { + auto version = getUnsigned(valueAt(json, "version")); + if (version != 2) + throw Error("Unsupported path info JSON format version %d, only version 2 is currently supported", version); } res.narHash = Hash::parseAny(getString(valueAt(json, "narHash")), std::nullopt); @@ -213,19 +210,12 @@ UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store throw; } - // New format as this as nullable but mandatory field; handling - // missing is for back-compat. - if (auto * rawCa0 = optionalValueAt(json, "ca")) - if (auto * rawCa = getNullable(*rawCa0)) - switch (version) { - case 1: - // old string format also used in SQLite DB and .narinfo - res.ca = ContentAddress::parse(getString(*rawCa)); - break; - case 2 ... std::numeric_limits::max(): - res.ca = *rawCa; - break; - } + try { + res.ca = ptrToOwned(getNullable(valueAt(json, "ca"))); + } catch (Error & e) { + e.addTrace({}, "while reading key 'ca'"); + throw; + } if (auto * rawDeriver0 = optionalValueAt(json, "deriver")) if (auto * rawDeriver = getNullable(*rawDeriver0)) diff --git a/src/libutil/include/nix/util/json-utils.hh b/src/libutil/include/nix/util/json-utils.hh index 7a3fe4f36..ec513ca25 100644 --- a/src/libutil/include/nix/util/json-utils.hh +++ b/src/libutil/include/nix/util/json-utils.hh @@ -114,4 +114,13 @@ struct adl_serializer> } }; +template +static inline std::optional ptrToOwned(const json * ptr) +{ + if (ptr) + return std::optional{*ptr}; + else + return std::nullopt; +} + } // namespace nlohmann