-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
9071d83
7762dd2
4d485f3
464f408
d3ff470
94facc9
961b3a1
99f35e1
febe4de
c3270b9
655b26c
38b45aa
0d440c9
06c44ce
c75cab6
16bd9a8
3df518b
66382fe
43e7a7a
24fc713
943aaa4
0159911
7e50ba7
6f272c5
486c48a
1201c72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,17 @@ let | |
| parentNode = allNodes.${getInputByPath lockFile.root node.parent}; | ||
|
|
||
| sourceInfo = | ||
| if hasOverride then | ||
| if node.buildTime or false then | ||
| derivation { | ||
| name = "source"; | ||
| builder = "builtin:fetch-tree"; | ||
| system = "builtin"; | ||
| __structuredAttrs = true; | ||
| input = node.locked; | ||
| outputHashMode = "recursive"; | ||
| outputHash = node.locked.narHash; | ||
| } | ||
|
Comment on lines
+49
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Is that correct or something to worry about?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| else if hasOverride then | ||
| overrides.${key}.sourceInfo | ||
| else if isRelative then | ||
| parentNode.sourceInfo | ||
|
|
@@ -93,6 +103,7 @@ let | |
| result = | ||
| if node.flake or true then | ||
| assert builtins.isFunction flake.outputs; | ||
| assert !(node.buildTime or false); | ||
| result | ||
| else | ||
| sourceInfo // { inherit sourceInfo outPath; }; | ||
|
|
||
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.
What are the implications of not doing this / is it small enough to fix this now?
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.
Just that it's slower / uses more disk space than necessary, since it will first fetch into the tarball cache and then copy it to the store. But we can improve that later.