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

queryDerivationOutputMap no longer assumes all outputs have a mapping #3859

Merged
merged 14 commits into from Aug 20, 2020

Conversation

Ericson2314
Copy link
Member

This assumption is broken by CA derivations. Making a PR now to do the
breaking daemon change as soon as possible (if it is already too late,
we can bump protocol instead).

CC @regnat

This assumption is broken by CA derivations. Making a PR now to do the
breaking daemon change as soon as possible (if it is already too late,
we can bump protocol intead).
{
if (!goal.isAllowed(path))
throw InvalidPath("cannot query output map for unknown path '%s' in recursive Nix", printStorePath(path));
return next->queryDerivationOutputMap(path);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter until we actually implement CA derivations, but we should censor returned output paths too.

Comment on lines 73 to 123
/* To guide overloading */
template<typename T>
struct Proxy {};

template<typename T>
std::map<std::string, T> read(const Store & store, Source & from, Proxy<std::map<std::string, T>> _)
{
std::map<string, T> resMap;
auto size = (size_t)readInt(from);
while (size--) {
auto thisKey = readString(from);
resMap.insert_or_assign(std::move(thisKey), read(store, from, Proxy<T> {}));
}
return resMap;
}

template<typename T>
void write(const Store & store, Sink & out, const std::map<string, T> & resMap)
{
out << resMap.size();
for (auto & i : resMap) {
out << i.first;
write(store, out, i.second);
}
}

template<typename T>
std::optional<T> read(const Store & store, Source & from, Proxy<std::optional<T>> _)
{
auto tag = readNum<uint8_t>(from);
switch (tag) {
case 0:
return std::nullopt;
case 1:
return read(store, from, Proxy<T> {});
default:
throw Error("got an invalid tag bit for std::optional: %#04x", tag);
}
}

template<typename T>
void write(const Store & store, Sink & out, const std::optional<T> & optVal)
{
out << (optVal ? 1 : 0);
if (optVal)
write(store, out, *optVal);
}

StorePath read(const Store & store, Source & from, Proxy<StorePath> _);

void write(const Store & store, Sink & out, const StorePath & storePath);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the generic machinery is a bit overkill for just one problem, I would like to keep this stuff to make the daemon protocol less annoying to work with in the future.

@Ericson2314 Ericson2314 force-pushed the drv-outputs-map-allow-missing branch from 2f2ae99 to fbeb869 Compare August 4, 2020 21:51
@Ericson2314
Copy link
Member Author

OK, this is now backwards compatible, and thus is ready to be merged.

template<>
std::optional<StorePath> read(const Store & store, Source & from, Phantom<std::optional<StorePath>> _)
{
auto s = readString(from);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto s = readString(from);
auto s = readString(from);

tab -> spaces

{ unsupported("queryDerivationOutputMap"); }

/* Query the mapping outputName=>outputPath for the given derivation.
Assume every output has a mapping and throw an exception otherwise. */
OutputPathMap queryDerivationOutputMapAssumeTotal(const StorePath & path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OutputPathMap queryDerivationOutputMapAssumeTotal(const StorePath & path);
OutputPathMap queryDerivationOutputMap(const StorePath & path);

/* Query the mapping outputName => outputPath for the given derivation. All
outputs are mentioned so ones mising the mapping are mapped to
`std::nullopt`. */
virtual std::map<std::string, std::optional<StorePath>> queryDerivationOutputMap(const StorePath & path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
virtual std::map<std::string, std::optional<StorePath>> queryDerivationOutputMap(const StorePath & path)
virtual std::map<std::string, std::optional<StorePath>> queryPartialDerivationOutputMap(const StorePath & path)

 - `queryDerivationOutputMapAssumeTotal` -> `queryPartialDerivationOutputMap`
 - `queryDerivationOutputMapAssumeTotal` -> `queryDerivationOutputMap`
@edolstra edolstra merged commit 4d77513 into NixOS:master Aug 20, 2020
@Ericson2314 Ericson2314 deleted the drv-outputs-map-allow-missing branch August 20, 2020 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants