diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 3978cc63611..0adff8c46e3 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -1392,8 +1392,7 @@ Derivation Derivation::fromJSON( std::function::ChildNode(const nlohmann::json &)> doInput; doInput = [&](const auto & json) { DerivedPathMap::ChildNode node; - node.value = static_cast( - ensureType(valueAt(json, "outputs"), value_t::array)); + node.value = getStringSet(valueAt(json, "outputs")); for (auto & [outputId, childNode] : getObject(valueAt(json, "dynamicOutputs"))) { xpSettings.require(Xp::DynamicDerivations); node.childMap[outputId] = doInput(childNode); @@ -1411,8 +1410,8 @@ Derivation Derivation::fromJSON( res.platform = getString(valueAt(json, "system")); res.builder = getString(valueAt(json, "builder")); - res.args = ensureType(valueAt(json, "args"), value_t::array); - res.env = ensureType(valueAt(json, "env"), value_t::object); + res.args = getStringList(valueAt(json, "args")); + res.env = getStringMap(valueAt(json, "env")); return res; } diff --git a/src/libutil/json-utils.cc b/src/libutil/json-utils.cc index 9df2543d21f..e2260199a2e 100644 --- a/src/libutil/json-utils.cc +++ b/src/libutil/json-utils.cc @@ -90,4 +90,36 @@ const nlohmann::json::boolean_t & getBoolean(const nlohmann::json & value) return value.get_ref(); } + +StringSet getStringSet(const nlohmann::json & value) +{ + StringSet stringSet = {}; + auto asArray = getArray(value); + for(auto & elem: asArray){ + stringSet.insert(getString(elem)); + } + return stringSet; +} + +Strings getStringList(const nlohmann::json & value) +{ + Strings stringList = {}; + auto asArray = getArray(value); + for(auto & elem: asArray){ + stringList.push_back(getString(elem)); + } + return stringList; +} + + +StringMap getStringMap(const nlohmann::json & value) +{ + StringMap stringMap = {}; + auto asObject = getObject(value); + for(auto & [key, elem]: asObject){ + stringMap.insert(key, getString(elem)); + } + return stringMap; +} + } diff --git a/src/libutil/json-utils.hh b/src/libutil/json-utils.hh index 6b75516f907..91d7faff0d8 100644 --- a/src/libutil/json-utils.hh +++ b/src/libutil/json-utils.hh @@ -3,6 +3,7 @@ #include #include +#include "types.hh" namespace nix { @@ -41,6 +42,9 @@ const nlohmann::json::array_t & getArray(const nlohmann::json & value); const nlohmann::json::string_t & getString(const nlohmann::json & value); const nlohmann::json::number_integer_t & getInteger(const nlohmann::json & value); const nlohmann::json::boolean_t & getBoolean(const nlohmann::json & value); +StringSet getStringSet(const nlohmann::json & value); +Strings getStringList(const nlohmann::json & value); +StringMap getStringMap(const nlohmann::json & value); /** * For `adl_serializer>` below, we need to track what