Skip to content

Stdenv setup: Process dependencies before dependents - #31414

Closed
Ericson2314 wants to merge 6 commits into
NixOS:stagingfrom
obsidiansystems:stdenv-toposort
Closed

Ericson2314 wants to merge 6 commits into
NixOS:stagingfrom
obsidiansystems:stdenv-toposort

Conversation

@Ericson2314

@Ericson2314 Ericson2314 commented Nov 9, 2017 •

Copy link
Copy Markdown
Member
Motivation for this change

This is intended to be reviewed commit-by-commit.

This does 2 things

  1. Change the dependency order. Before, we did the current node before children, now we do the children before current node. Were dependencies forming a tree, this would simply be the inverse traversal, but since they in fact form a DAG, it's a bit more subtle. The opposite of the new invariant "dependencies before dependents" wasn't true: dependents weren't always processed first because it was possible that a dependency was already visited via another dependent.

    This is an observable change because the processing we are doing does not commute: arbitrary bash setup hooks certainly don't, and PATH concatenation doesn't either. I do think having this invariant is valuable, though, and rely on it to simplify cc-wrapper's setup hook.

  2. Cyclic dependencies are now an error. Yes, they are only possible in absurd cases, but possible nonetheless:

    └── /nix/store/asdfasdfasdf-foobar/
        ├── foo
        │   └── nix-support
        │       └── propagated-build-inputs = /nix/store/asdfasdfasdf-foobar/bar
        └── bar
            └── nix-support
                └── propagated-build-inputs = /nix/store/asdfasdfasdf-foobar/foo
    

    (foo and bar are cyclic). The old algo would silently work with this; the new one would naively diverge, so I made it error out instead as such a thing should never be intended. But if we agree this shouldn't happen in practice so infinite recursion is a good enough error, I can simplify things

Things done

Hoping to merge this Monday 2017-11-13 at the latest :). Thanks!

  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built stdenv on platform(s)
    • NixOS -- latest in progress, see nixborg build
    • macOS -- latest in progress
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

CC @bgamari

@copumpkin

Copy link
Copy Markdown
Member

This seems sensible in principle, but can we get a Hydra job showing what the implications might be? Subtly changing behavior (that arguably nobody should rely on the order of, but people probably do) makes me very uncomfortable even if it does make sense.

@GrahamcOfBorg GrahamcOfBorg added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. labels Nov 9, 2017
@globin

globin commented Nov 9, 2017

Copy link
Copy Markdown
Member

@nixborg build

@nixborg

nixborg commented Nov 9, 2017

Copy link
Copy Markdown

Comment thread pkgs/stdenv/generic/setup.sh Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Who calls this function?

Comment thread pkgs/stdenv/generic/setup.sh Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@orivej here

Comment thread pkgs/stdenv/generic/setup.sh Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@orivej And here

@Ericson2314

Copy link
Copy Markdown
Member Author

@globin is there any good known-good jobsest to compare the nixborg one to?

@Ericson2314

Copy link
Copy Markdown
Member Author

Oh hmm, this breaks down when different dependencies are in fact the same derivation. I'm going to have to think about that.

@orivej

orivej commented Nov 10, 2017

Copy link
Copy Markdown
Contributor

Could you give an example in nixpkgs?

@Ericson2314

Copy link
Copy Markdown
Member Author

@orivej Nevermind. The already-visited logic is based on actual paths, I just mistakenly changed the iteration order. [I did have to make _PATH be prepended instead of appended, but that is expected.]

There's still a theoretical issue where "unrelated" deps could clobber each other on the PATH in different ways based on different topological sorts, and our depth-first one might not have the most intuitive behavior in that regard, but I won't worry about this unless it shows up in practice.

I added a cc-wrapper commit from my #29396 branch that actually leverages this, to make sure everything works alright.

@orivej
orivej changed the base branch from master to staging November 10, 2017 19:49
@orivej
orivej changed the base branch from staging to master November 10, 2017 19:51

@orivej orivej left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. https://hydra.mayflower.de/jobset/nixos/pr-31414 did not pick your changes yet… And since AFAIK it does not contribute to the nixos cache, shouldn't this PR go to staging first?

@Ericson2314
Ericson2314 changed the base branch from master to staging November 10, 2017 20:58
@globin

globin commented Nov 11, 2017

Copy link
Copy Markdown
Member

@nixborg build

@nixborg

nixborg commented Nov 11, 2017

Copy link
Copy Markdown

@Ericson2314 Ericson2314 mentioned this pull request May 7, 2018
8 tasks
Ericson2314 referenced this pull request Jul 27, 2018
This will be very useful for bootstrapping, eventually.
Ericson2314 referenced this pull request Sep 17, 2018
…d of strings

This is generally cleaner: less eval, less worrying about separators,
and probably also faster. I got the idea from that python wrapper
script.
@FRidh

FRidh commented Jul 20, 2019

Copy link
Copy Markdown
Member

I like the motivation behind this change but because nothing is happening I am closing this.

@FRidh FRidh closed this Jul 20, 2019
@JohnAZoidberg

Copy link
Copy Markdown
Member

This issue is mentioned in nixpkgs stdenv: https://github.com/nixos/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L1167

@Ericson2314

Copy link
Copy Markdown
Member Author

Yes maybe a GitHub issue rather than open PR canbe made for that.

@Ericson2314 Ericson2314 reopened this Aug 1, 2021
@github-actions github-actions Bot added 6.topic: emacs Text editor 6.topic: erlang General-purpose, concurrent, functional high-level programming language 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 6.topic: ocaml OCaml is a general-purpose, high-level, multi-paradigm programming language. 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: qt/kde Object-oriented framework for GUI creation 6.topic: ruby A dynamic, open source programming language with a focus on simplicity and productivity. 6.topic: stdenv Standard environment 6.topic: TeX Issues regarding texlive and TeX in general labels Aug 1, 2021
@Ericson2314
Ericson2314 marked this pull request as draft August 1, 2021 16:31
@Ericson2314

Copy link
Copy Markdown
Member Author

Reopning and marking as draft because I ought to finish it at some point.

@ofborg ofborg Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 1, 2021
@Ericson2314

Copy link
Copy Markdown
Member Author

Should be possible to finish after #132340 is the default and cc-wrapper is simplified.

@stale

stale Bot commented Apr 19, 2022

Copy link
Copy Markdown

I marked this as stale due to inactivity. → More info

@stale stale Bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 19, 2022
@ConnorBaker

Copy link
Copy Markdown
Contributor

I think this is still relevant and (time permitting) I'd like to revive this PR.

@Ericson2314 in terms of how this would look on current master, any advice? I started by trying to apply the spirit of the changes each commit contains, but I'm not sure what some of the changes should look like post #26805.

For example, what should 229eed3 look like since 3a50395? That is, I'm not sure what the offsets are for the wrapper and scripts relative to the consumers.

Additionally, I see a lot of interpolation of derivations into store paths in various strings -- is this a concern with respect to splicing? I know that mkDerivation includes code to handle retrieving packages from the correct package set when they are in dependency arrays, but I don't think that applies to the various string arguments passed to mkDerivation (nor could it, I suppose).

@Ericson2314

Copy link
Copy Markdown
Member Author

That is, I'm not sure what the offsets are for the wrapper and scripts relative to the consumers.

I think the offsets can stay the same? Or at least if

  • the old PR moved things to propagated deps
  • master had recategorized which type of dep

Do "propagated" per the PR, and the offset per master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: emacs Text editor 6.topic: erlang General-purpose, concurrent, functional high-level programming language 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 6.topic: ocaml OCaml is a general-purpose, high-level, multi-paradigm programming language. 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: qt/kde Object-oriented framework for GUI creation 6.topic: ruby A dynamic, open source programming language with a focus on simplicity and productivity. 6.topic: stdenv Standard environment 6.topic: TeX Issues regarding texlive and TeX in general 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.