Skip to content

Commit d591f17

Browse files
authored
Merge pull request #14189 from NixOS/fix-exportReferencesGraph
exportReferencesGraph: Handle heterogeneous arrays
2 parents bb1945a + 94f410b commit d591f17

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/libstore/derivation-options.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ DerivationOptions DerivationOptions::fromStructuredAttrs(
9999
return fromStructuredAttrs(env, parsed ? &*parsed : nullptr);
100100
}
101101

102+
static void flatten(const nlohmann::json & value, StringSet & res)
103+
{
104+
if (value.is_array())
105+
for (auto & v : value)
106+
flatten(v, res);
107+
else if (value.is_string())
108+
res.insert(value);
109+
else
110+
throw Error("'exportReferencesGraph' value is not an array or a string");
111+
}
112+
102113
DerivationOptions
103114
DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAttrs * parsed, bool shouldWarn)
104115
{
@@ -219,12 +230,9 @@ DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAt
219230
if (!e || !e->is_object())
220231
return ret;
221232
for (auto & [key, value] : getObject(*e)) {
222-
if (value.is_array())
223-
ret.insert_or_assign(key, value);
224-
else if (value.is_string())
225-
ret.insert_or_assign(key, StringSet{value});
226-
else
227-
throw Error("'exportReferencesGraph' value is not an array or a string");
233+
StringSet ss;
234+
flatten(value, ss);
235+
ret.insert_or_assign(key, std::move(ss));
228236
}
229237
} else {
230238
auto s = getOr(env, "exportReferencesGraph", "");

tests/functional/structured-attrs.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,8 @@ mkDerivation {
8282
"foo$" = "BAD";
8383

8484
exportReferencesGraph.refs = [ dep ];
85+
exportReferencesGraph.refs2 = [
86+
dep
87+
[ dep ]
88+
]; # regression test for heterogeneous arrays
8589
}

tests/functional/structured-attrs.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
source common.sh
44

5-
# 27ce722638 required some incompatible changes to the nix file, so skip this
6-
# tests for the older versions
7-
requireDaemonNewerThan "2.4pre20210712"
5+
# https://github.com/NixOS/nix/pull/14189
6+
requireDaemonNewerThan "2.33"
87

98
clearStoreIfPossible
109

0 commit comments

Comments
 (0)