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

[RFC 0092] Computed derivations #92

Merged
merged 59 commits into from
Jan 12, 2022
Merged

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Apr 26, 2021

This is the spiritual successor of #40.

Rendered merged

Tracking issue

Ericson2314 and others added 26 commits February 1, 2019 01:08
Also:

 - Allow fixed output builds (in that temp store)

 - Clean up drawbacks and alternatives.
Thanks @siddharthist!

Co-Authored-By: Ericson2314 <git@JohnEricson.me>
Thanks @Mic92

Co-Authored-By: Ericson2314 <git@JohnEricson.me>
Thanks @globin

Co-Authored-By: Ericson2314 <git@JohnEricson.me>
Thanks @siddharthist!

Co-Authored-By: Ericson2314 <git@JohnEricson.me>
Break off some previously inline observations into their own subsection.
Thanks @Mic92!

Co-Authored-By: Ericson2314 <git@JohnEricson.me>
The later examples with `nix-instantiate` automatically get all the outputs of the final rewritten drv, so there's no output iteration needed. `"$o"` was mistakenly copied over from the earlier examples.

Thanks to @ocharles for asking me the question that led me to this. Hopefully this change answers that?
Co-Authored-By: Domen Kožar <domen@enlambda.com>
No `let`, so don't need `in`.
This was in the "wrapper" derivation example.
We already cache builds just fine, thanks!

Thanks @globin for catching
Copy link
Contributor

@asymmetric asymmetric left a comment

Choose a reason for hiding this comment

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

Left a couple of comments to make this more accessible.

rfcs/0000-plan-dynanism.md Outdated Show resolved Hide resolved
Comment on lines 109 to 113
e ⇓ e'
e' is derivation
------
builtins.assumeDerivation e ⇓ e'
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a section explaining this syntax? I assume it's familiar for PLT folks, but it's very cryptic to me :)

Copy link
Member

Choose a reason for hiding this comment

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

Those are inference rules expressed in operational semantics.

You can read that as if e evaluates to e' and e' is a derivation, then builtins.assumeDerivation e evaluates to e'.

I agree with asymmetric, we're not a PLT-focused symposium, prose is fine here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a more accessible presentation would be better. This is pseudo-formal, because (AFAIK) the and is derivation judgements aren't actually defined anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Unfortunately not everyone has that background.

Copy link
Contributor

Choose a reason for hiding this comment

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

A "translation" would suffice. Those compaxt bits of formalisms are great, once one has learned to parse them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well.....I'll put it this way:

  1. I think CA derivations' various notions of store coherence (by far the subtlest part), GUIX-style "grafting", mixing native- and cross-compiled packages, and probably other things I can't anticipate are going to repeatedly keep us thinking about these sorts of inductive relations. Some sort of sequent-ish syntax, or prolog's horn clause syntax, or many other such things are far and away the clearest and most concise way to convey this information once the reader is familiar --- it's supposed to be nice and "pictoral" not inscrutable ivory tower. I think it be best if we start moving in that direction.

  2. Even if I right some prose now, It's going to a pain to update. VS with this sort of syntax it can be easier to just stare at and have all the important bits come out, so it's easier to revise.

So I am fine writing some sort of prose explanation, but I rather do it once the RFC is further along.


P.S. whether you love our hate this stuff, https://www.youtube.com/watch?v=dCuZkaaou0Q is a fun talk.

Copy link
Member

Choose a reason for hiding this comment

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

You could include a link to a short introduction to natural deduction.

Copy link
Member

Choose a reason for hiding this comment

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

Since this is gone we can remove this.

rfcs/0000-plan-dynanism.md Outdated Show resolved Hide resolved
| <single-installable> ! *
```

Now that we have `path` vs `path!*`, we also don't need `---derivation` as a disambiguator, and so that should be removed along with all the complexity that goes with it.
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be clarified. I took me three readings to figure out that /nix/store/…foo.drv!* is to build all outputs (which is the current default behavior unless --derivation is specified, I assume?) and /nix/store/…foo.drv would just build the derivation.

Copy link
Member Author

@Ericson2314 Ericson2314 Apr 27, 2021

Choose a reason for hiding this comment

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

Oh sheesh, yes I never said what the semantics were. Did that in addition to the examples @asymmetric asked for.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does it make sense now? (before I mark this resolved.)

Copy link
Member

Choose a reason for hiding this comment

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

The example clarifies things yeah! I am unsure though if the mention of --derivation is detremental at this point since it is a nixUnstable only thing and I could not find any documentation of the flag that even remotely explained to me what it does.

I guess we have a bit of a problem that this RFC somewhat overlaps with problems related to the Installables abstraction and the unstable CLI?

rfcs/0000-plan-dynanism.md Outdated Show resolved Hide resolved
@Ericson2314 Ericson2314 marked this pull request as draft April 26, 2021 14:23
@L-as
Copy link
Member

L-as commented Jan 10, 2022

I think the FCP has passed?

@edolstra edolstra merged commit 9a2f5ac into NixOS:master Jan 12, 2022
@edolstra
Copy link
Member

Yes indeed, so I've merged the RFC. Thanks all!

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/nixpkgss-current-development-workflow-is-not-sustainable/18741/73

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/recent-nix-change-worthy-of-greater-attention/18972/1

@Ericson2314
Copy link
Member Author

6xxscl

@L-as
Copy link
Member

L-as commented Oct 23, 2022

We should post the pseudoshepherd meeting notes somewhere

@das-g
Copy link
Member

das-g commented Oct 23, 2022

We should post the pseudoshepherd meeting notes somewhere

I know our RFC process has the concept of shepherd teams, but what's a "pseudoshepherd meeting"?

@L-as
Copy link
Member

L-as commented Oct 23, 2022

@das-g We talked about this RFC at NixCon.

@tomberek
Copy link
Contributor

Notes from NixCon opportunistic meeting in the courtyard:

Summary

  • derivations that produce derivations
  • IFD is normally used for bulk import of language-specifics
  • ninja/make export for fine-grained caching
  • performance characteristics
  • equivalent ergonomics possible to full recursive-nix

History

  • 2019 initial implementation
  • Niel Mitchell, Applicative build systems are Monadic under the hood link
  • on the fly lazy handling of the build graph instead of static build plan
  • changes to the heart of Nix
  • need more code review
  • keep the momentum instead of exacerbating merge conflicts
  • get John off of "single point of failure"
  • add builtPath case of derivedPath
  • treat the output of a derivation as a derivation

Summary of internals

  • nix evaluation creates a derivation and it builds into another derivation.
  • Uses the top-level goal to guide forward progress.
  • Self-modifying graph, substitute new graphs in to the old.
  • nix expression, with import nixpkgs hello, inside derivation, evaluate, build
  • useful to avoid IFD
  • parallelize evaluation
  • Crates, extract names to do auto-completion
  • repl supports IFD while live
  • "^" for user feedback, interally the daemon protocol uses "!"
  • RFC92 does not impact repl
  • dervations produced do not have Nix values associated with them, store-layer concept
  • override of dependency. with aeson we know static dependencies, with dynamic derivations
  • might be possible to override, but might fail at build time

next step brainstorm

  • create use cases (required for stabilization, not for experimental)

  • make lang2nix examples

  • needs library to make it ergonomic, or an extra primitive

  • primary advantage is it is a limited IFD

  • ninja2nix

  • GNUMake 2 nix

  • nixpkgs is limited because it cannot import nix code from elsewhere

  • does this solve incremental builds

    • build Linux, it calculates the build graph
    • the evaluation inside the derivation can be cached
    • purs-nix
  • IFD can be made correct, very hard to make it fast

  • 92 is easy to make performant

  • distcc, ccache

  • "optimize IFD to do eval in parallel"

  • Hercules-CI agent does some eval

  • caching Nix evaluation, builtins.cache

  • nix build .#x can make the derivation for you...

  • this might also implement cached Nix evaluation (see Nix PR for caching primop)

  • well suited for big builds

  • recursive Nix is easier to adapt, speak the daemon protocol inside the sandbox

  • The test case is the existing yarn2nix, old version of snack,

  • cross system is an idiom question, how to express this?

  • what conventions, when to use, when not to

  • clearly describe when

  • makePackage function, eval-time attributes added

there are simple advantages, but unclear if we can get the benefits for large projects

makes the sizes of necessary locks much smaller, making previously unpalatable appoaches better

Steps

  1. review and merge PR
  2. Nixpkgs? or branch with Hydra to test this
  3. staging hydra
  4. Project/example to prove it helps and measure

dependencies

  1. determine if we need dynamic number of outputs? or recursive nix?
  2. review existing PR to debug cycles of multi-output derivation (not a blocker, but helpful)
  3. determine what we can do without the recursive-nix constraint

recursive-nix followup

"can we limit recursive-nix to only build from dynamic-derivation and use only nix-instantiate?"

question: dynamic derivation

  • only limit to nix-instantiate
  • "userspace" nix-instantiate
  • "kernel" add store paths

@roberth
Copy link
Member

roberth commented Mar 30, 2023

Computed derivations could provide a means to access old packages in case of a major change to the language.

I'm not suggesting we should change the language in backwards incompatible ways, but if we were to do it, this feature would let us preserve Nix's unique selling point of being able to use very old software alongside very up to date software.

It will not generalize to any expression though; mostly just to derivations, so things like NixOS modules would still have to be ported, but this is much less effort than porting the entire toolchain and dependencies that produced the legacy package. (And you should probably review an old module anyway, if you even dare to run it as part of your OS)

Interestingly, this could be one way in which we'd have a need for nested computed derivations: if the legacy package before the language change was itself a computed derivation, because it uses a derivation-supported build system. Though for now it's a bit hard to imagine such a fancy package to be old.

More likely we'll first see a derivation-supported build system to rely on a computed derivation (to build the build system), though that seems to be a different kind of nesting, as such a build system is parented by Nixpkgs and could be injected into the final dynamic derivation by means of a store path, rather than having to do a double outputOf. We might not even call that nesting.

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/nixcon-governance-workshop/32705/9

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/community-calendar/18589/102

KAction pushed a commit to KAction/rfcs that referenced this pull request Apr 13, 2024
* Initial draft "ret-cont" recursive Nix

* Fix typos and finish trailing sentance

* Switch to advocating temp store rather than daemon socket

Also:

 - Allow fixed output builds (in that temp store)

 - Clean up drawbacks and alternatives.

* ret-cont-recursive-nix: Fix typo

Thanks @siddharthist!

Co-Authored-By: Ericson2314 <git@JohnEricson.me>

* ret-cont-recursive-nix: Fix typo

Thanks @Mic92

Co-Authored-By: Ericson2314 <git@JohnEricson.me>

* ret-cont-recursive-nix: Fix typo

Thanks @globin

Co-Authored-By: Ericson2314 <git@JohnEricson.me>

* ret-cont-recursive-nix: Fix typo

Thanks @siddharthist!

Co-Authored-By: Ericson2314 <git@JohnEricson.me>

* ret-cont-recursive-nix: Clean up motivation, adding examples

* ret-cont-recursive-nix: Improve syntax highlighting

* Do a lousy job formalizing the detailed design

Break off some previously inline observations into their own subsection.

* ret-cont-recursive-nix: Mention `builtins.exec` in alternatives

* ret-cont-recursive-nix: Fix typo

Thanks @Mic92!

Co-Authored-By: Ericson2314 <git@JohnEricson.me>

* ret-cont-recursive-nix: Remove dangling "$o"

The later examples with `nix-instantiate` automatically get all the outputs of the final rewritten drv, so there's no output iteration needed. `"$o"` was mistakenly copied over from the earlier examples.

Thanks to @ocharles for asking me the question that led me to this. Hopefully this change answers that?

* Update rfcs/0000-ret-cont-recursive-nix.md

Co-Authored-By: Domen Kožar <domen@enlambda.com>

* ret-cont-recursive: Fix typo

about -> out

* ret-cont: Add examples and expand future work

* ret-cont: Fix syntax error

No `let`, so don't need `in`.

* ret-cont: Mention Ninja's upcomming `dyndep` and C++ oppertunity

* ret-cont: Fix missing explicit `outputs` and `__recursive`

This was in the "wrapper" derivation example.

* ret-cont: "caching builds" -> "caching evaluation"

We already cache builds just fine, thanks!

Thanks @globin for catching

* ret-cont: Improve formalism and reference NixOS#62

* drv-build-drv: Start drafting from old ret-cont-recursive-nix RFC

* drv-buiild-drv: WIP rewrite

* plan-dynamism: Rewrite RFC yet again

* plan-dynamism: Rename file accordingly

* plan-dynanism: Fix typo

Thanks @mweinelt.

* plan-dynanism: Fix formalism slightly

* Apply suggestions from code review

Thanks!

Co-authored-by: Rosario Pulella <Rosariopulella@gmail.com>
Co-authored-by: Ninjatrappeur <NinjaTrappeur@users.noreply.github.com>

* plan-dynamism: `Buildables` -> `DerivedPathsWithHints`

Thanks @sternenseemann for catching.

* plan-dynamism: Add semantics and examples for `!` syntax

* plan-dynamism: Too many dashes in `--derivation`

* plan-dynanism: Put pupose of text hashing before name

* Apply suggestions from code review

Co-authored-by: Ollie Charles <ollie@ocharles.org.uk>

* Apply suggestions from code review

Co-authored-by: Ollie Charles <ollie@ocharles.org.uk>

* Apply suggestions from code review

* Update rfcs/0000-plan-dynanism.md

* plan-dynanism: Fix bad sentence

Thanks @roberth!

* plan-dynamism: Number the two parts

* plan-dynamism: Rip out part 2

There is more to do I'm sure, but I wanted to get the ball rolling.

* plan-dynamism: New motivation

* plan-dynamism: Fix typo

Thanks @L-as

* TEMP PLES AMEND

* [RFC 0092] Rename file

* [RFC 0092] Fix YAML header

* [RFC 0092] Rewrite summary

* [RFC 0092] Add link to documentation

* [RFC 0092] Rewrite example section

* [RFC 0092] Small fix

* [RFC 0092] Rewrite drawbacks and alternatives

* [RFC 0092] Improve alternatives section

* [RFC 0092] Fix syntax error

* [RFC 0092] Small change

* [RFC 0092] Remove unnecessary file

* [RFC 0092] Add comment about IFD

* [RFC 0092] Fix typo

* Update rfcs/0092-plan-dynamism.md

Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>

* plan-dynamism-experiment: Make clear is experimental

* plan-dynamism-experiment: Fix typo

Thanks @L-as

Co-authored-by: Langston Barrett <langston.barrett@gmail.com>
Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
Co-authored-by: Robin Gloster <mail@glob.in>
Co-authored-by: Domen Kožar <domen@enlambda.com>
Co-authored-by: Rosario Pulella <Rosariopulella@gmail.com>
Co-authored-by: Ninjatrappeur <NinjaTrappeur@users.noreply.github.com>
Co-authored-by: Ollie Charles <ollie@ocharles.org.uk>
Co-authored-by: Las Safin <me@las.rs>
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet