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

Only store hash in DerivationOutput for fixed output derivations #3795

Merged

Conversation

matthewbauer
Copy link
Member

We just need the hash here because we can calculate the store path from its fixed output hash (with some extra parameters that is). This leads to less data duplication.

To calculate the path, we need a name, a storeDir, a hash, and a hash method. We get the storeDir from the store and the drvName from the BasicDerivation. Previously, BasicDerivation didn't have a name, so had to add this in as well.

We always have a name for BasicDerivation, since we have a derivation
store path that has a name.
we don’t need a full storepath for a fixedoutput derivation. So just
putting the ingestion method + the hash is sufficient.
@Ericson2314
Copy link
Member

Ericson2314 commented Jul 8, 2020

@regnat This is the preparatory step from #3776 (comment) . I thought this preparatory change would just be "getting the churn out of the way", switching from the path field to accessor but doing nothing further. Being able to deduplicate BasicDerivation by calculating the store path was just icing on the cake!

std::optional<FixedOutputHash> hash; /* hash used for expected hash computation */
};

struct DerivationOutputFixed
Copy link
Member

Choose a reason for hiding this comment

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

Oh, it just occurred to me I guess we could get rid of this and just use FixedOutputHash directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, but it would be less type safe right? we could do the same with DerivationOutputExtensional and StorePath

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't say "less type safe", just a matter of preference. I don't have a preference, just pointing out the possibility for others that might.

@@ -129,9 +129,11 @@ static DerivationOutput parseDerivationOutput(const Store & store, istringstream
}


static Derivation parseDerivation(const Store & store, const string & s)
static Derivation parseDerivation(const Store & store, const string & s, string name)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we rather read the name from drv.env["name"] to make them more self-contained ? Atm it's technically possible to realize a derivation that doesn't have a name field (or has a name field that's different from the name of the store path), but there's no way to build such a derivation (even manually because it won't be possible to import it into the store)

Copy link
Member

Choose a reason for hiding this comment

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

@regnat I would consider magic things in env a libexpr convention rather than it's nice for libstore to not be aware of.

Matt and I talked about getting the name from the derivation output paths during parsing, which would use libstore-aware conventions. We didn't do that in this PR cause we could get away with it, but if we need to get rid of this new argument we can do that.

Copy link
Member

Choose a reason for hiding this comment

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

I would consider magic things in env a libexpr convention rather than it's nice for libstore to not be aware of.

I agree in principle, but given that the drv format is not extensible that's the best way we have to pass meta information about a derivation. And there's quite a bit of precedent about reading information from the env field (preferLocalBuild, __json, requiredSystemFeatures…), so it seems legit to also do that for the name

src/libstore/derivations.hh Outdated Show resolved Hide resolved
@edolstra

This comment has been minimized.

@matthewbauer matthewbauer changed the title Only store hash in OutputDerivationOutput Only store hash in OutputDerivationFixed Jul 15, 2020
@matthewbauer matthewbauer changed the title Only store hash in OutputDerivationFixed Only store hash in DerivationOutput for fixed output derivations Jul 15, 2020
@Ericson2314

This comment has been minimized.

@edolstra
Copy link
Member

Could you look at the merge conficts? Otherwise LGTM.

One possible improvement: it's a bit ugly to have to pass drvName to DerivationOutput::path(), since you could pass the wrong drvName. Since a derivation knows its own name, maybe we could have a method Derivation::path(store, outputName) that avoids this.

@Ericson2314
Copy link
Member

Could you look at the merge conficts? Otherwise LGTM.

Done

One possible improvement: it's a bit ugly to have to pass drvName to DerivationOutput::path(), since you could pass the wrong drvName. Since a derivation knows its own name, maybe we could have a method Derivation::path(store, outputName) that avoids this.

Yes that we bugging me too. Happy to do that, would you mind if it was a separate PR? If I do it in this I will just get a bunch of conflicts for #3830, so I rather do it on top of #3830.

@edolstra
Copy link
Member

@Ericson2314 Sure!

@edolstra edolstra merged commit a5f7d31 into NixOS:master Jul 27, 2020
@Ericson2314 Ericson2314 deleted the optional-derivation-output-storepath branch July 27, 2020 15:18
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

5 participants