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

Derivations can output "text-hashed" data #3959

Merged
merged 54 commits into from May 10, 2023

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Aug 25, 2020

Motivation

We're finally getting to RFC 92 features proper!

Derivations are currently serialized to store objects (and also thus given drv paths, even when we just stick with in-memory derivations) using "text hashing" / "text file ingestion method", a type of content addressing. That means, if we want to compute derivations we need to use

  • content-addressed derivations (already have!)
  • with derivations outputs using text ingestion method (don't yet have!)

The latter part is what we are adding.

Context

A few things needed to make this go.

  1. A little cleanup of ContentAddressMethod building on Introduce StoreReferences and ContentAddressWithReferences #3746. The two variants are now TextIngestionMethod and FileIngestionMethod, which together are tantamount to a 3-way enum:

    • flat ingestion
    • Nix archive ingestion ("recursive")
    • text ingestion

    This data type no longer species any hash type, but is just the way of ingestion data. A nice single purpose now.

  2. TextHashMethod -> TextIngestionMethod, since it no longer implies SHA-256 or any other hash type (or hashing at all!), though out of an abundance of caution we disallow trying to use any other hash type with it. (We're separating concerns but not supporting all the options yet!)

  3. FixedOutputHashMethod is deleted. It was a type for a (hash type, flat | recursive) pair, but we simply don't need that anymore. Everything supports text hashing too now.

  4. The new stuff is gated under a new dynamic-derivations feature. I imagine I'll just put all the constituent features that make up dynamic derivations under this, as they are meant to be used together.

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
  • documentation in the internal API docs
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

Priorities

Add 👍 to pull requests you find important.

In particular, this means that derivations can output derivations. But that ramification isn't (yet!) useful as we would want, since there is no way to have a dependent derivation that is itself a dependent derivation.

depends on #3746

@vikanezrimaya
Copy link
Member

I'd like to learn what are the possible use-cases once this feature becomes truly useful and complete (meaning that the drawback you mentioned earlier is solved). This feels very confusing to me as a casual Nix user

@Ericson2314
Copy link
Member Author

Ericson2314 commented Aug 28, 2020

@kisik21 the use-case is instead of using IFD, we can build derivations produced by derivations. For example, we could do nix-instantiate $(cabal2nix ..) > $out in a derivation-producing derivation.

@vikanezrimaya
Copy link
Member

Oh, I see! So the extra step of running node2nix or whatever gets used to package up node packages, or something else, is not needed with derivation-ception that's being made possible here.

Or should we call it Nix-ception? 😂

In particular, this means that derivations can output derivations. But
that ramification isn't (yet!) useful as we would want, since there is
no way to have a dependent derivation that is itself a dependent
derivation.
@Ericson2314 Ericson2314 changed the title WIP: Derivations can output "text-hashed" data --- contains many other PRs Derivations can output "text-hashed" data --- contains #3746 Oct 13, 2020
@Ericson2314
Copy link
Member Author

This should pass, and is rebased to now only contain one other PR.

@Ericson2314 Ericson2314 mentioned this pull request Mar 10, 2021
4 tasks
@Ericson2314 Ericson2314 marked this pull request as ready for review April 19, 2023 16:55
Good to round out the library interface.
In other words, use a plain `ContentAddress` not
`ContentAddressWithReferences` for `DerivationOutput::CAFixed`.

Supporting fixed output derivations with (fixed) references would be a
cool feature, but it is out of scope at this moment.
In this one, we don't just output an existing derivation as is, but
modify it first.
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/rfc-92-status-update/27441/1

Thanks so much!

Co-authored-by: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com>
src/libstore/misc.cc Outdated Show resolved Hide resolved
src/libstore/misc.cc Show resolved Hide resolved
tests/dyn-drv/text-hashed-output.nix Outdated Show resolved Hide resolved
tests/dyn-drv/text-hashed-output.nix Outdated Show resolved Hide resolved
tests/dyn-drv/text-hashed-output.sh Outdated Show resolved Hide resolved
nix path-info $drv --derivation --json | jq
nix path-info $out1 --derivation --json | jq

test $out1 == $drv
Copy link
Member

Choose a reason for hiding this comment

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

I don't suppose we can do nix build $drvProducingDrv^out^out yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

:) not yet, but soon!

@Ericson2314 Ericson2314 force-pushed the ca-drv-exotic branch 3 times, most recently from ead1411 to 2a37fef Compare May 8, 2023 11:10
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Hardly anything significant it seems. 🚀

src/libstore/build/local-derivation-goal.cc Outdated Show resolved Hide resolved
src/libstore/content-address.cc Outdated Show resolved Hide resolved
src/libstore/content-address.cc Outdated Show resolved Hide resolved
src/libstore/content-address.hh Outdated Show resolved Hide resolved
src/libstore/content-address.hh Outdated Show resolved Hide resolved
src/libstore/content-address.hh Outdated Show resolved Hide resolved
src/libstore/content-address.hh Outdated Show resolved Hide resolved
src/libstore/daemon.cc Outdated Show resolved Hide resolved
src/libstore/remote-store.cc Outdated Show resolved Hide resolved
Ericson2314 and others added 6 commits May 9, 2023 12:19
Didn't mean to use the private name that shouldn't be exposed.
It appears we were checking a variable in the process of definining it.
Thanks!

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
The `ContentAddressWithReferences` method is made total, with error
handling now squarely the caller's job. This is better.
@Ericson2314 Ericson2314 merged commit 53a1354 into NixOS:master May 10, 2023
8 checks passed
@Ericson2314 Ericson2314 deleted the ca-drv-exotic branch May 10, 2023 14:42
@edolstra
Copy link
Member

edolstra commented May 12, 2023

This causes a warning with gcc:

src/libstore/content-address.cc: In static member function ‘static nix::ContentAddressMethod nix::ContentAddressMethod::parsePrefix(std::string_view&)’:
src/libstore/content-address.cc:41:16: warning: ‘method’ may be used uninitialized [-Wmaybe-uninitialized]
   41 |         method = TextIngestionMethod {};
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
src/libstore/content-address.cc:37:26: note: ‘method’ declared here
   37 |     ContentAddressMethod method = FileIngestionMethod::Flat;
      |                          ^~~~~~

Any idea what causes that?

@Ericson2314 Ericson2314 mentioned this pull request Jul 5, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Related to an accepted RFC store Issues and pull requests concerning the Nix store with-tests Issues related to testing. PRs with tests have some priority
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

7 participants