Skip to content

Commit 904cd2d

Browse files
committed
Only activate derivation-meta when __meta is an object
1 parent 78a9be6 commit 904cd2d

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/libstore/derivation-options.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,15 @@ DerivationOptions<SingleDerivedPath> derivationOptionsFromStructuredAttrs(
378378
getStringSetAttr(env, parsed, "requiredSystemFeatures").value_or(defaults.requiredSystemFeatures),
379379
.preferLocalBuild = getBoolAttr(env, parsed, "preferLocalBuild", defaults.preferLocalBuild),
380380
.allowSubstitutes = getBoolAttr(env, parsed, "allowSubstitutes", defaults.allowSubstitutes),
381-
.meta = [&]() -> std::optional<nlohmann::json> {
381+
.meta = [&]() -> std::optional<nlohmann::json::object_t> {
382382
if (!parsed)
383383
return std::nullopt;
384384

385385
auto & structuredAttrs = parsed->structuredAttrs;
386386

387387
// Only extract __meta if derivation-meta feature is used
388388
if (hasDerivationMetaFeature(structuredAttrs)) {
389-
return structuredAttrs.at("__meta");
389+
return getObject(structuredAttrs.at("__meta"));
390390
}
391391
return std::nullopt;
392392
}(),
@@ -628,12 +628,7 @@ DerivationOptions<SingleDerivedPath> adl_serializer<DerivationOptions<SingleDeri
628628
.requiredSystemFeatures = getStringSet(valueAt(json, "requiredSystemFeatures")),
629629
.preferLocalBuild = getBoolean(valueAt(json, "preferLocalBuild")),
630630
.allowSubstitutes = getBoolean(valueAt(json, "allowSubstitutes")),
631-
.meta = [&]() -> std::optional<nlohmann::json> {
632-
if (auto * metaPtr = optionalValueAt(json, "meta"))
633-
if (auto * nonNullMeta = getNullable(*metaPtr))
634-
return *nonNullMeta;
635-
return std::nullopt;
636-
}(),
631+
.meta = valueAt(json, "meta").get<std::optional<nlohmann::json::object_t>>(),
637632
};
638633
}
639634

@@ -668,10 +663,7 @@ void adl_serializer<DerivationOptions<SingleDerivedPath>>::to_json(
668663
json["requiredSystemFeatures"] = o.requiredSystemFeatures;
669664
json["preferLocalBuild"] = o.preferLocalBuild;
670665
json["allowSubstitutes"] = o.allowSubstitutes;
671-
if (o.meta)
672-
json["meta"] = *o.meta;
673-
else
674-
json["meta"] = nullptr;
666+
json["meta"] = o.meta;
675667
}
676668

677669
OutputChecks<SingleDerivedPath> adl_serializer<OutputChecks<SingleDerivedPath>>::from_json(const json & json_)

src/libstore/derivations.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,12 @@ static const DrvHash pathDerivationModulo(Store & store, const StorePath & drvPa
891891

892892
bool hasDerivationMetaFeature(const nlohmann::json::object_t & structuredAttrs)
893893
{
894-
if (!structuredAttrs.contains("__meta"))
894+
auto metaIt = structuredAttrs.find("__meta");
895+
if (metaIt == structuredAttrs.end())
896+
return false;
897+
898+
// Validate that __meta is an object
899+
if (!metaIt->second.is_object())
895900
return false;
896901

897902
if (auto it = structuredAttrs.find("requiredSystemFeatures");

src/libstore/include/nix/store/derivation-options.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ struct DerivationOptions
180180
* Metadata excluded from hash computation. Only populated when both
181181
* `__meta` and `derivation-meta` system feature are present.
182182
* Otherwise `__meta` remains in structured attributes as a regular attribute.
183+
*
184+
* Must be a JSON object (not a string, array, or other JSON type).
183185
*/
184-
std::optional<nlohmann::json> meta;
186+
std::optional<nlohmann::json::object_t> meta;
185187

186188
bool operator==(const DerivationOptions &) const = default;
187189

0 commit comments

Comments
 (0)