Skip to content

Also pass unwanted outputs to post-build-hook#7721

Merged
thufschmitt merged 5 commits intoNixOS:masterfrom
yorickvP:post-build-hook
May 10, 2023
Merged

Also pass unwanted outputs to post-build-hook#7721
thufschmitt merged 5 commits intoNixOS:masterfrom
yorickvP:post-build-hook

Conversation

@yorickvP
Copy link
Contributor

Motivation

#6311 caused only wanted outputs to be passed to the post-build-hook, causing #6960.

Context

Fixes #6960

For a long time, the post-build-hook was passed all built store paths. This changed, causing some breakage.

  • Add a test to see if unwanted outputs are passed to the post-build-hook.
  • Collect wanted+unwanted outputs in a separate set and thread them through DerivationGoal::checkPathValidity, DerivationGoal::registerOutputs, DerivationGoal::assertPathValidity.

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or bug fix: updated release notes

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-43/25185/1

@Ericson2314
Copy link
Member

What does the post-build-hook if the paths are substituted instead of freshly built?

Yes, this fixes a practical problem, but if the semantics of the hook differ based on how the store object was obtained, I feel a bit uncomfortable about that.

@ollie-etl
Copy link

Is this likely the underlying bug for my observation that only a single output from a multi-output derivation is uploaded to s3 cache?
This used to work.

post-hook is

#!/bin/sh
set -eu
set -f # disable globbing
export IFS=' '
exec nix copy --to "s3://<store-uri>?endpoint=https://storage.googleapis.com" $OUT_PATHS

I'm using nix 2.8.1

@yorickvP
Copy link
Contributor Author

@Ericson2314 the post-build-hook was never called for substituted paths, and doing so wouldn't really fit common usage (uploading everything you build to a cache somewhere).

@ollie-etl the difference comes because, before this bug, a build of a.dev would cause the build hook to be invoked with the paths of a.out, a.dev. (even though building a.out is a side-effect).
With the bug, the post-build hook would only get a.dev and a.out would go unnoticed.

@ollie-etl
Copy link

ollie-etl commented Feb 17, 2023

@yorickvP Here i'm building a, and a.out is being uploaded, but not a.dev.

@Ericson2314
Copy link
Member

@yorickvP BTW check out #6312 and in particular the settings wantedOuputs = Outputs::All { }; I used to do (and Nix originally did). I think that might be a simpler way to achieve this PR too?

@yorickvP yorickvP force-pushed the post-build-hook branch 4 times, most recently from f4aaefb to 0096153 Compare February 22, 2023 16:13
@yorickvP
Copy link
Contributor Author

Refactored it quite a bit, moved the wantedOutputs filtering to the end of the pipeline in done().
CA tests fail as @thufschmitt predicted. Will look into it tomorrow.

@yorickvP
Copy link
Contributor Author

I spent a while debugging the test, but copying only the outputs doesn't seem to be sufficient for the CA test in any case (without my patch aswell).

@thufschmitt do you know if that's correct and supposed to be the case?

out=nix-build ./ca-thing.nix
nix copy --to cache $out
nix copy --from cache -f ca-thing.nix
    error: unable to build with a primary store that isn't a local store; either pass a different '--store' or enable remote builds.

@thufschmitt
Copy link
Member

@thufschmitt do you know if that's correct and supposed to be the case?

out=nix-build ./ca-thing.nix
nix copy --to cache $out
nix copy --from cache -f ca-thing.nix
    error: unable to build with a primary store that isn't a local store; either pass a different '--store' or enable remote builds.

Yes, it is. It's explained a bit more in https://www.tweag.io/blog/2021-02-17-derivation-outputs-and-output-paths/, but the gist of it is that with CA derivations there's a split between the output path and the information “this Derivation built this output path”. So if you want to be able to fetch “the output of this derivation” then you must copy exactly that (nix copy --to cache -f ca-thing.nix or nix copy --to cache /nix/store/....-ca-thing.drv) and not just the output path

@yorickvP
Copy link
Contributor Author

Okay, in that case this will have to suffice

@alyssais
Copy link
Member

Any news here?

@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Apr 11, 2023
@yorickvP
Copy link
Contributor Author

@thufschmitt rebased, please review

@ollie-etl
Copy link

@thufschmitt @yorickvP Is this dead?

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long at reaching here.

I'm still a bit sad this can't be a more local change, but it does fix the problem while making the code marginally more sensible. So let's roll!

Copy link
Member

Choose a reason for hiding this comment

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

That's unrelated to this PR, but this file is weird 🤔

@thufschmitt
Copy link
Member

@yorickvP can I let you rebase one last time? The conflicts seem mostly benign

yorickvP added 4 commits May 8, 2023 12:43
fe5509d caused only wanted outputs to be passed to the
post-build-hook, which resulted in paths being built
without ever going into the hook.

This commit adds a (currently failing) test for this.
@yorickvP yorickvP force-pushed the post-build-hook branch from 4620d92 to d1ff33d Compare May 8, 2023 10:59
@yorickvP
Copy link
Contributor Author

yorickvP commented May 8, 2023

Rebased, but the DrvOutputs -> SingleDrvOutputs thing was not entirely trivial. Let's see if the tests pass.

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

It's all passing, and looking good 🚀

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

It's all passing, and looking good 🚀

@thufschmitt thufschmitt merged commit 85ff212 into NixOS:master May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsigned derivations uploaded to S3

6 participants