forked from NixOS/nix
-
Notifications
You must be signed in to change notification settings - Fork 3
Build-time flake inputs #49
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
Open
edolstra
wants to merge
26
commits into
main
Choose a base branch
from
build-time-fetch-tree
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9071d83
Allow dynamic registration of builtin builders
edolstra 7762dd2
Put the builder context in a struct
edolstra 4d485f3
Add builtin:fetch-tree
edolstra 464f408
Pass tmpDirInSandbox to the builtin builders
edolstra d3ff470
Move fetchSettings back to libfetchers
edolstra 94facc9
Hack to disable the fetcher cache in forked processes
edolstra 961b3a1
builtin:fetch-tree: Propagate access tokens, set cache directory
edolstra 99f35e1
Allow flake inputs to be fetched at build time
edolstra febe4de
Formatting
edolstra c3270b9
Always add a NAR hash for build-time inputs
edolstra 655b26c
Revert "Hack to disable the fetcher cache in forked processes"
edolstra 38b45aa
Sync: Support moving out of another Sync
edolstra 0d440c9
Remove global fetcher cache
edolstra 06c44ce
builtin:fetch-tree: Hack to avoid touching the parent's FileTransfer …
edolstra c75cab6
Move getTarballCache() into fetchers::Settings
edolstra 16bd9a8
Formatting
edolstra 3df518b
Add test
edolstra 66382fe
Merge commit '47281531e' into build-time-fetch-tree
edolstra 43e7a7a
Merge commit '09fbe1569430ca561c461b9b4ece3428785a53d6' into build-ti…
edolstra 24fc713
Merge remote-tracking branch 'detsys/detsys-main' into build-time-fet…
edolstra 943aaa4
Fix test
edolstra 0159911
Add build-time-fetch-tree experimental feature
edolstra 7e50ba7
Provide downloadFile() with a writable store
edolstra 6f272c5
Fix segfault destroying prevFileTransfer
edolstra 486c48a
Add tests for build-time fetching of GitHub flakes
edolstra 1201c72
GitRepo::fetch(): Fall back to using libgit2 for fetching
edolstra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "nix/store/builtins.hh" | ||
#include "nix/store/parsed-derivations.hh" | ||
#include "nix/fetchers/fetchers.hh" | ||
#include "nix/fetchers/fetch-settings.hh" | ||
#include "nix/util/archive.hh" | ||
#include "nix/store/filetransfer.hh" | ||
#include "nix/store/store-open.hh" | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
namespace nix { | ||
|
||
static void builtinFetchTree(const BuiltinBuilderContext & ctx) | ||
{ | ||
experimentalFeatureSettings.require(Xp::BuildTimeFetchTree); | ||
|
||
auto out = get(ctx.drv.outputs, "out"); | ||
if (!out) | ||
throw Error("'builtin:fetch-tree' requires an 'out' output"); | ||
|
||
if (!(ctx.drv.type().isFixed() || ctx.drv.type().isImpure())) | ||
throw Error("'builtin:fetch-tree' must be a fixed-output or impure derivation"); | ||
|
||
if (!ctx.parsedDrv) | ||
throw Error("'builtin:fetch-tree' must have '__structuredAttrs = true'"); | ||
|
||
setenv("NIX_CACHE_HOME", ctx.tmpDirInSandbox.c_str(), 1); | ||
|
||
using namespace fetchers; | ||
|
||
fetchers::Settings myFetchSettings; | ||
myFetchSettings.accessTokens = fetchSettings.accessTokens.get(); | ||
|
||
// Make sure we don't use the FileTransfer object of the parent | ||
// since it's in a broken state after the fork. We also must not | ||
// delete it, so hang on to the shared_ptr. | ||
// FIXME: move FileTransfer into fetchers::Settings. | ||
static auto prevFileTransfer = resetFileTransfer(); | ||
|
||
// FIXME: disable use of the git/tarball cache | ||
|
||
auto input = Input::fromAttrs(myFetchSettings, jsonToAttrs(ctx.parsedDrv->structuredAttrs["input"])); | ||
|
||
std::cerr << fmt("fetching '%s'...\n", input.to_string()); | ||
|
||
/* Functions like downloadFile() expect a store. We can't use the | ||
real one since we're in a forked process. FIXME: use recursive | ||
Nix's daemon so we can use the real store? */ | ||
auto tmpStore = openStore(ctx.tmpDirInSandbox + "/nix"); | ||
|
||
auto [accessor, lockedInput] = input.getAccessor(tmpStore); | ||
|
||
auto source = sinkToSource([&](Sink & sink) { accessor->dumpPath(CanonPath::root, sink); }); | ||
|
||
restorePath(ctx.outputs.at("out"), *source); | ||
} | ||
|
||
static RegisterBuiltinBuilder registerUnpackChannel("fetch-tree", builtinFetchTree); | ||
|
||
} // namespace nix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
#include "nix/fetchers/fetch-settings.hh" | ||
#include "nix/util/config-global.hh" | ||
|
||
namespace nix::fetchers { | ||
|
||
Settings::Settings() {} | ||
|
||
} // namespace nix::fetchers | ||
|
||
namespace nix { | ||
|
||
fetchers::Settings fetchSettings; | ||
|
||
static GlobalConfig::Register rFetchSettings(&fetchSettings); | ||
|
||
} // namespace nix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My memory is that, because of the way derivations are added to the store by way of
registerOutputs
, they are scanned for references to the Nix store. Since the eval-time fetcher doesn't do that (and so the retrieved sources can contain paths to the Nix store), the build-time fetcher will reject some of the sources which the eval-time fetcher would accept (since fixed-output derivations are not allowed to contain references to the Nix store).Is that correct or something to worry about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nix only scans for references that are part of the input closure of a derivation. It doesn't scan for arbitrary references. For the build-time fetcher, the input closure is empty, so no sources will ever be rejected by the build-time fetcher. This also means Nix won't find references that are "hard-coded" (e.g. part of the tarball), but that's the same for other types of derivations (e.g.
fetchurl
in Nixpkgs).