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

Lazy flake input fetching #2920

Merged
merged 13 commits into from Jun 6, 2019
Merged

Lazy flake input fetching #2920

merged 13 commits into from Jun 6, 2019

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented Jun 4, 2019

Flake inputs are now fetched lazily. That is, as long as a flake is locked by the top-level lockfile, it won't be fetched unless it's actually needed (i.e. inputs.<foo> is evaluated).

Note that this required a change to the lockfile format: we now store the flake ID of inputs, because this is needed before the flake is fetched to construct the inputs attrset.

Other changes:

  • Moved some lockfile-related stuff to lockfile.{cc,hh}. There's also some funky multiple inheritance going on now to factor out some common code between flake and non-flake inputs and between top-level and non-top-level flakes.

  • resolveFlake() now avoids fetching the top-level flake twice.

As long as the flake input is locked, it is now only fetched when it
is evaluated (e.g. "nixpkgs" is fetched when
"inputs.nixpkgs.<something>" is evaluated).

This required adding an "id" attribute to the members of "inputs" in
lockfiles, e.g.

  "inputs": {
    "nixpkgs/release-19.03": {
      "id": "nixpkgs",
      "inputs": {},
      "narHash": "sha256-eYtxncIMFVmOHaHBtTdPGcs/AnJqKqA6tHCm0UmPYQU=",
      "nonFlakeInputs": {},
      "uri": "github:edolstra/nixpkgs/e9d5882bb861dc48f8d46960e7c820efdbe8f9c1"
    }
  }

because the flake ID needs to be known beforehand to construct the
"inputs" attrset.

Fixes #2913.
Also use nlohmann::json range-based for.
Unfortunately this doesn't work. Maybe we should keep separate roots
for each path.
Also add a proper test for non-flake inputs.
@edolstra edolstra added the flakes label Jun 4, 2019
@edolstra edolstra requested review from grahamc and CSVdB June 4, 2019 19:26
@edolstra
Copy link
Member Author

edolstra commented Jun 5, 2019

Just a heads up that I moved flake-related files from src/libexpr/primops to src/libexpr/flake.

@edolstra edolstra merged commit 671f16a into flakes Jun 6, 2019
@edolstra edolstra deleted the lazy-flakes branch June 6, 2019 10:28
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/improving-flakes/12831/46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants