From 5663827c7d62e305833e007584c7de82ba7cb303 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 26 Mar 2025 20:02:06 +0000 Subject: [PATCH] Move call-flake.nix to nix-flake As suggested by Ericson2314 in review https://github.com/NixOS/nix/pull/12759#issuecomment-2755352343 (cherry picked from commit 0c75581d8b7cfbfa7a8db9b5dcbf0cbf0709009f) --- src/libexpr/eval.cc | 4 ---- src/libexpr/eval.hh | 4 +--- src/libexpr/meson.build | 1 - src/{libexpr => libflake}/call-flake.nix | 0 src/libflake/flake/flake.cc | 24 ++++++++++++++++++++++-- src/libflake/meson.build | 10 ++++++++++ src/libflake/package.nix | 1 + 7 files changed, 34 insertions(+), 10 deletions(-) rename src/{libexpr => libflake}/call-flake.nix (100%) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 53b649606..b9b89773f 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -288,10 +288,6 @@ EvalState::EvalState( CanonPath("derivation-internal.nix"), #include "primops/derivation.nix.gen.hh" )} - , callFlakeInternal{internalFS->addFile( - CanonPath("call-flake.nix"), - #include "call-flake.nix.gen.hh" - )} , store(store) , buildStore(buildStore ? buildStore : store) , debugRepl(nullptr) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 9b8899ccf..5e3e915c6 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -274,14 +274,12 @@ public: /** * In-memory filesystem for internal, non-user-callable Nix - * expressions like call-flake.nix. + * expressions like `derivation.nix`. */ const ref internalFS; const SourcePath derivationInternal; - const SourcePath callFlakeInternal; - /** * Store used to materialise .drv files. */ diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index fc04c4691..040da3dbc 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -126,7 +126,6 @@ generated_headers = [] foreach header : [ 'imported-drv-to-derivation.nix', 'fetchurl.nix', - 'call-flake.nix', ] generated_headers += gen_header.process(header) endforeach diff --git a/src/libexpr/call-flake.nix b/src/libflake/call-flake.nix similarity index 100% rename from src/libexpr/call-flake.nix rename to src/libflake/call-flake.nix diff --git a/src/libflake/flake/flake.cc b/src/libflake/flake/flake.cc index 47feeb087..b4b987027 100644 --- a/src/libflake/flake/flake.cc +++ b/src/libflake/flake/flake.cc @@ -16,6 +16,8 @@ #include +#include "memory-source-accessor.hh" + namespace nix { using namespace flake; @@ -921,6 +923,25 @@ LockedFlake lockFlake( } } +static ref makeInternalFS() { + auto internalFS = make_ref(MemorySourceAccessor {}); + internalFS->setPathDisplay("«flakes-internal»", ""); + internalFS->addFile( + CanonPath("call-flake.nix"), + #include "call-flake.nix.gen.hh" + ); + return internalFS; +} + +static auto internalFS = makeInternalFS(); + +static Value * requireInternalFile(EvalState & state, CanonPath path) { + SourcePath p {internalFS, path}; + auto v = state.allocValue(); + state.evalFile(p, *v); // has caching + return v; +} + void callFlake(EvalState & state, const LockedFlake & lockedFlake, Value & vRes) @@ -960,8 +981,7 @@ void callFlake(EvalState & state, auto & vOverrides = state.allocValue()->mkAttrs(overrides); - auto vCallFlake = state.allocValue(); - state.evalFile(state.callFlakeInternal, *vCallFlake); + Value * vCallFlake = requireInternalFile(state, CanonPath("call-flake.nix")); auto vLocks = state.allocValue(); vLocks->mkString(lockFileStr); diff --git a/src/libflake/meson.build b/src/libflake/meson.build index 642b85aea..b780722de 100644 --- a/src/libflake/meson.build +++ b/src/libflake/meson.build @@ -39,6 +39,15 @@ add_project_arguments( subdir('nix-meson-build-support/common') +subdir('nix-meson-build-support/generate-header') + +generated_headers = [] +foreach header : [ + 'call-flake.nix', +] + generated_headers += gen_header.process(header) +endforeach + sources = files( 'flake/config.cc', 'flake/flake.cc', @@ -65,6 +74,7 @@ subdir('nix-meson-build-support/windows-version') this_library = library( 'nixflake', sources, + generated_headers, dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args: linker_export_flags, diff --git a/src/libflake/package.nix b/src/libflake/package.nix index 5240ce5e3..d7250c252 100644 --- a/src/libflake/package.nix +++ b/src/libflake/package.nix @@ -28,6 +28,7 @@ mkMesonLibrary (finalAttrs: { ../../.version ./.version ./meson.build + ./call-flake.nix (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ];