aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-12-22 14:43:20 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-12-22 14:43:20 +0100
commit75efa421340b8fb2be6cf5351d3ef36a93b294e1 (patch)
tree23ae93853edaa38505ce0727bbdac780402e9488 /src
parent5373f4be3b1427ed73303448a1fa801726f4dfa0 (diff)
Move <nix/fetchurl.nix> into the nix binary
This makes the statically linked nix binary just work, without needing any additional files.
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval.cc7
-rw-r--r--src/libexpr/eval.hh2
-rw-r--r--src/libexpr/fetchurl.nix41
-rw-r--r--src/libexpr/local.mk2
-rw-r--r--src/libexpr/parser.y4
-rw-r--r--src/libexpr/primops.cc10
6 files changed, 59 insertions, 7 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 5a641d02c..ead5bf8c7 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -402,11 +402,6 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store)
for (auto & i : evalSettings.nixPath.get()) addToSearchPath(i);
}
- try {
- addToSearchPath("nix=" + canonPath(settings.nixDataDir + "/nix/corepkgs", true));
- } catch (Error &) {
- }
-
if (evalSettings.restrictEval || evalSettings.pureEval) {
allowedPaths = PathSet();
@@ -457,6 +452,8 @@ Path EvalState::checkSourcePath(const Path & path_)
*/
Path abspath = canonPath(path_);
+ if (hasPrefix(abspath, corepkgsPrefix)) return abspath;
+
for (auto & i : *allowedPaths) {
if (isDirOrInDir(abspath, i)) {
found = true;
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 0e1f61baa..e3eaed6d3 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -432,4 +432,6 @@ struct EvalSettings : Config
extern EvalSettings evalSettings;
+static const std::string corepkgsPrefix{"/__corepkgs__/"};
+
}
diff --git a/src/libexpr/fetchurl.nix b/src/libexpr/fetchurl.nix
new file mode 100644
index 000000000..02531103b
--- /dev/null
+++ b/src/libexpr/fetchurl.nix
@@ -0,0 +1,41 @@
+{ system ? "" # obsolete
+, url
+, hash ? "" # an SRI hash
+
+# Legacy hash specification
+, md5 ? "", sha1 ? "", sha256 ? "", sha512 ? ""
+, outputHash ?
+ if hash != "" then hash else if sha512 != "" then sha512 else if sha1 != "" then sha1 else if md5 != "" then md5 else sha256
+, outputHashAlgo ?
+ if hash != "" then "" else if sha512 != "" then "sha512" else if sha1 != "" then "sha1" else if md5 != "" then "md5" else "sha256"
+
+, executable ? false
+, unpack ? false
+, name ? baseNameOf (toString url)
+}:
+
+derivation {
+ builder = "builtin:fetchurl";
+
+ # New-style output content requirements.
+ inherit outputHashAlgo outputHash;
+ outputHashMode = if unpack || executable then "recursive" else "flat";
+
+ inherit name url executable unpack;
+
+ system = "builtin";
+
+ # No need to double the amount of network traffic
+ preferLocalBuild = true;
+
+ impureEnvVars = [
+ # We borrow these environment variables from the caller to allow
+ # easy proxy configuration. This is impure, but a fixed-output
+ # derivation like fetchurl is allowed to do so since its result is
+ # by definition pure.
+ "http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"
+ ];
+
+ # To make "nix-prefetch-url" work.
+ urls = [ url ];
+}
diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk
index 519da33f7..26c53d301 100644
--- a/src/libexpr/local.mk
+++ b/src/libexpr/local.mk
@@ -40,6 +40,6 @@ $(eval $(call install-file-in, $(d)/nix-expr.pc, $(prefix)/lib/pkgconfig, 0644))
$(foreach i, $(wildcard src/libexpr/flake/*.hh), \
$(eval $(call install-file-in, $(i), $(includedir)/nix/flake, 0644)))
-$(d)/primops.cc: $(d)/imported-drv-to-derivation.nix.gen.hh $(d)/primops/derivation.nix.gen.hh
+$(d)/primops.cc: $(d)/imported-drv-to-derivation.nix.gen.hh $(d)/primops/derivation.nix.gen.hh $(d)/fetchurl.nix.gen.hh
$(d)/flake/flake.cc: $(d)/flake/call-flake.nix.gen.hh
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index a4c84c526..85eb05d61 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -698,6 +698,10 @@ Path EvalState::findFile(SearchPath & searchPath, const string & path, const Pos
Path res = r.second + suffix;
if (pathExists(res)) return canonPath(res);
}
+
+ if (hasPrefix(path, "nix/"))
+ return corepkgsPrefix + path.substr(4);
+
throw ThrownError({
.hint = hintfmt(evalSettings.pureEval
? "cannot look up '<%s>' in pure evaluation mode (use '--impure' to override)"
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 18438f681..c73a94f4e 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -164,7 +164,15 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
state.forceFunction(**fun, pos);
mkApp(v, **fun, w);
state.forceAttrs(v, pos);
- } else {
+ }
+
+ else if (path == corepkgsPrefix + "fetchurl.nix") {
+ state.eval(state.parseExprFromString(
+ #include "fetchurl.nix.gen.hh"
+ , "/"), v);
+ }
+
+ else {
if (!vScope)
state.evalFile(realPath, v);
else {