From e02481ded216ffb5b06b413e3695d4e11e62e02f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 11 Mar 2020 16:36:36 +0100 Subject: parseExprFromString(): Use std::string_view --- src/libexpr/eval.hh | 4 ++-- src/libexpr/parser.y | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 34a212aa4..f3e8a34bd 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -144,8 +144,8 @@ public: Expr * parseExprFromFile(const Path & path, StaticEnv & staticEnv); /* Parse a Nix expression from the specified string. */ - Expr * parseExprFromString(const string & s, const Path & basePath, StaticEnv & staticEnv); - Expr * parseExprFromString(const string & s, const Path & basePath); + Expr * parseExprFromString(std::string_view s, const Path & basePath, StaticEnv & staticEnv); + Expr * parseExprFromString(std::string_view s, const Path & basePath); Expr * parseStdin(); diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index afa1fd439..9c769e803 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -611,13 +611,13 @@ Expr * EvalState::parseExprFromFile(const Path & path, StaticEnv & staticEnv) } -Expr * EvalState::parseExprFromString(const string & s, const Path & basePath, StaticEnv & staticEnv) +Expr * EvalState::parseExprFromString(std::string_view s, const Path & basePath, StaticEnv & staticEnv) { - return parse(s.c_str(), "(string)", basePath, staticEnv); + return parse(s.data(), "(string)", basePath, staticEnv); } -Expr * EvalState::parseExprFromString(const string & s, const Path & basePath) +Expr * EvalState::parseExprFromString(std::string_view s, const Path & basePath) { return parseExprFromString(s, basePath, staticBaseEnv); } -- cgit v1.2.3 From 9950cdec3514949942a79c58764b1ea9bf9d5d57 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 11 Mar 2020 16:41:22 +0100 Subject: Move some corepkgs into the nix binary --- corepkgs/buildenv.nix | 25 ------------------------- corepkgs/imported-drv-to-derivation.nix | 21 --------------------- corepkgs/local.mk | 5 ++++- src/libexpr/imported-drv-to-derivation.nix | 21 +++++++++++++++++++++ src/libexpr/local.mk | 2 ++ src/libexpr/primops.cc | 15 +++++++++++---- src/nix-env/buildenv.nix | 25 +++++++++++++++++++++++++ src/nix-env/user-env.cc | 4 +++- src/nix/local.mk | 2 ++ tests/lang/eval-okay-search-path.nix | 2 +- 10 files changed, 69 insertions(+), 53 deletions(-) delete mode 100644 corepkgs/buildenv.nix delete mode 100644 corepkgs/imported-drv-to-derivation.nix create mode 100644 src/libexpr/imported-drv-to-derivation.nix create mode 100644 src/nix-env/buildenv.nix diff --git a/corepkgs/buildenv.nix b/corepkgs/buildenv.nix deleted file mode 100644 index 0bac4c44b..000000000 --- a/corepkgs/buildenv.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ derivations, manifest }: - -derivation { - name = "user-environment"; - system = "builtin"; - builder = "builtin:buildenv"; - - inherit manifest; - - # !!! grmbl, need structured data for passing this in a clean way. - derivations = - map (d: - [ (d.meta.active or "true") - (d.meta.priority or 5) - (builtins.length d.outputs) - ] ++ map (output: builtins.getAttr output d) d.outputs) - derivations; - - # Building user environments remotely just causes huge amounts of - # network traffic, so don't do that. - preferLocalBuild = true; - - # Also don't bother substituting. - allowSubstitutes = false; -} diff --git a/corepkgs/imported-drv-to-derivation.nix b/corepkgs/imported-drv-to-derivation.nix deleted file mode 100644 index eab8b050e..000000000 --- a/corepkgs/imported-drv-to-derivation.nix +++ /dev/null @@ -1,21 +0,0 @@ -attrs @ { drvPath, outputs, name, ... }: - -let - - commonAttrs = (builtins.listToAttrs outputsList) // - { all = map (x: x.value) outputsList; - inherit drvPath name; - type = "derivation"; - }; - - outputToAttrListElement = outputName: - { name = outputName; - value = commonAttrs // { - outPath = builtins.getAttr outputName attrs; - inherit outputName; - }; - }; - - outputsList = map outputToAttrListElement outputs; - -in (builtins.head outputsList).value diff --git a/corepkgs/local.mk b/corepkgs/local.mk index 362c8eb61..2c72d3a31 100644 --- a/corepkgs/local.mk +++ b/corepkgs/local.mk @@ -1,4 +1,7 @@ -corepkgs_FILES = buildenv.nix unpack-channel.nix derivation.nix fetchurl.nix imported-drv-to-derivation.nix +corepkgs_FILES = \ + unpack-channel.nix \ + derivation.nix \ + fetchurl.nix $(foreach file,config.nix $(corepkgs_FILES),$(eval $(call install-data-in,$(d)/$(file),$(datadir)/nix/corepkgs))) diff --git a/src/libexpr/imported-drv-to-derivation.nix b/src/libexpr/imported-drv-to-derivation.nix new file mode 100644 index 000000000..eab8b050e --- /dev/null +++ b/src/libexpr/imported-drv-to-derivation.nix @@ -0,0 +1,21 @@ +attrs @ { drvPath, outputs, name, ... }: + +let + + commonAttrs = (builtins.listToAttrs outputsList) // + { all = map (x: x.value) outputsList; + inherit drvPath name; + type = "derivation"; + }; + + outputToAttrListElement = outputName: + { name = outputName; + value = commonAttrs // { + outPath = builtins.getAttr outputName attrs; + inherit outputName; + }; + }; + + outputsList = map outputToAttrListElement outputs; + +in (builtins.head outputsList).value diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk index 26b9f14ba..8a9b3c2ea 100644 --- a/src/libexpr/local.mk +++ b/src/libexpr/local.mk @@ -31,3 +31,5 @@ clean-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexe dist-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh $(eval $(call install-file-in, $(d)/nix-expr.pc, $(prefix)/lib/pkgconfig, 0644)) + +$(d)/primops.cc: $(d)/imported-drv-to-derivation.nix.gen.hh diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 4cd28698c..8de234951 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -121,10 +121,17 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args mkString(*(outputsVal->listElems()[outputs_index++]), o.first); } w.attrs->sort(); - Value fun; - state.evalFile(settings.nixDataDir + "/nix/corepkgs/imported-drv-to-derivation.nix", fun); - state.forceFunction(fun, pos); - mkApp(v, fun, w); + + static Value * fun = nullptr; + if (!fun) { + fun = state.allocValue(); + state.eval(state.parseExprFromString( + #include "imported-drv-to-derivation.nix.gen.hh" + , "/"), *fun); + } + + state.forceFunction(*fun, pos); + mkApp(v, *fun, w); state.forceAttrs(v, pos); } else { state.forceAttrs(*args[0]); diff --git a/src/nix-env/buildenv.nix b/src/nix-env/buildenv.nix new file mode 100644 index 000000000..0bac4c44b --- /dev/null +++ b/src/nix-env/buildenv.nix @@ -0,0 +1,25 @@ +{ derivations, manifest }: + +derivation { + name = "user-environment"; + system = "builtin"; + builder = "builtin:buildenv"; + + inherit manifest; + + # !!! grmbl, need structured data for passing this in a clean way. + derivations = + map (d: + [ (d.meta.active or "true") + (d.meta.priority or 5) + (builtins.length d.outputs) + ] ++ map (output: builtins.getAttr output d) d.outputs) + derivations; + + # Building user environments remotely just causes huge amounts of + # network traffic, so don't do that. + preferLocalBuild = true; + + # Also don't bother substituting. + allowSubstitutes = false; +} diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index 8e4ecda4e..717431b7a 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -106,7 +106,9 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, /* Get the environment builder expression. */ Value envBuilder; - state.evalFile(state.findFile("nix/buildenv.nix"), envBuilder); + state.eval(state.parseExprFromString( + #include "buildenv.nix.gen.hh" + , "/"), envBuilder); /* Construct a Nix expression that calls the user environment builder with the manifest as argument. */ diff --git a/src/nix/local.mk b/src/nix/local.mk index a34cca9fd..a486a37cc 100644 --- a/src/nix/local.mk +++ b/src/nix/local.mk @@ -23,3 +23,5 @@ $(foreach name, \ nix-build nix-channel nix-collect-garbage nix-copy-closure nix-daemon nix-env nix-hash nix-instantiate nix-prefetch-url nix-shell nix-store, \ $(eval $(call install-symlink, nix, $(bindir)/$(name)))) $(eval $(call install-symlink, $(bindir)/nix, $(libexecdir)/nix/build-remote)) + +src/nix-env/nix-env.cc: src/nix-env/buildenv.nix.gen.hh diff --git a/tests/lang/eval-okay-search-path.nix b/tests/lang/eval-okay-search-path.nix index cca41f821..c5a123d04 100644 --- a/tests/lang/eval-okay-search-path.nix +++ b/tests/lang/eval-okay-search-path.nix @@ -1,7 +1,7 @@ with import ./lib.nix; with builtins; -assert pathExists ; +assert pathExists ; assert length __nixPath == 6; assert length (filter (x: x.prefix == "nix") __nixPath) == 1; -- cgit v1.2.3