Skip to content

Commit c6597bd

Browse files
committed
Add plugins to make Nix more extensible.
See plugins.hh for the full details. Currently plugins to extend the evaluator are supported.
1 parent f201b77 commit c6597bd

File tree

30 files changed

+233
-5
lines changed

30 files changed

+233
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ perl/Makefile.config
3838
/scripts/nix-copy-closure
3939
/scripts/nix-reduce-build
4040
/scripts/nix-http-export.cgi
41+
/scripts/nix-profile-daemon.sh
4142

4243
# /src/libexpr/
4344
/src/libexpr/lexer-tab.cc

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ makefiles = \
2424
misc/launchd/local.mk \
2525
misc/upstart/local.mk \
2626
doc/manual/local.mk \
27-
tests/local.mk
27+
tests/local.mk \
28+
tests/plugins/local.mk
2829

2930
GLOBAL_CXXFLAGS += -std=c++14 -g -Wall -include config.h
3031

doc/manual/command-ref/conf-file.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,19 @@ builtins.fetchurl {
742742
</varlistentry>
743743

744744

745+
<varlistentry xml:id="conf-plugin-files">
746+
<term><literal>plugin-files</literal></term>
747+
<listitem>
748+
<para>
749+
A list of plugin files to be loaded by Nix. This allows
750+
extending nix in various ways; see the documentation in
751+
<filename>plugins.hh</filename> for more information.
752+
</para>
753+
</listitem>
754+
755+
</varlistentry>
756+
757+
745758
</variablelist>
746759

747760
</para>

doc/manual/release-notes/rl-2.0.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,15 @@ configureFlags = "--prefix=${placeholder "out"} --includedir=${placeholder "dev"
389389
</para>
390390
</listitem>
391391

392+
<listitem>
393+
<para>
394+
Nix can now be extended with plugins. See the documentation in
395+
<filename>plugins.hh</filename> for more details. Currently,
396+
plugins to modify the Nix expression evaluator state are
397+
supported.
398+
</para>
399+
</listitem>
400+
392401
</itemizedlist>
393402

394403
<para>Some features were removed:</para>

mk/libraries.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ endif
4545
# - $(1)_INSTALL_DIR: the directory where the library will be
4646
# installed. Defaults to $(libdir).
4747
#
48+
# - $(1)_EXCLUDE_FROM_LIBRARY_LIST: if defined, the library will not
49+
# be automatically marked as a dependency of the top-level all
50+
# target andwill not be listed in the make help output. This is
51+
# useful for libraries built solely for testing, for example.
52+
#
4853
# - BUILD_SHARED_LIBS: if equal to ‘1’, a dynamic library will be
4954
# built, otherwise a static library.
5055
define build-library
@@ -149,7 +154,9 @@ define build-library
149154
$(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn)))
150155
-include $$($(1)_DEPS)
151156

157+
ifndef $(1)_EXCLUDE_FROM_LIBRARY_LIST
152158
libs-list += $$($(1)_PATH)
159+
endif
153160
clean-files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS)
154161
dist-files += $$(_srcs)
155162
endef

src/build-remote/build-remote.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "store-api.hh"
1818
#include "derivations.hh"
1919
#include "local-store.hh"
20+
#include "plugins.hh"
2021

2122
using namespace nix;
2223
using std::cin;
@@ -64,6 +65,8 @@ int main (int argc, char * * argv)
6465

6566
settings.maxBuildJobs.set("1"); // hack to make tests with local?root= work
6667

68+
initPlugins();
69+
6770
auto store = openStore().cast<LocalStore>();
6871

6972
/* It would be more appropriate to use $XDG_RUNTIME_DIR, since

src/buildenv/buildenv.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "shared.hh"
2+
#include "plugins.hh"
23
#include <sys/stat.h>
34
#include <sys/types.h>
45
#include <fcntl.h>
@@ -135,6 +136,7 @@ int main(int argc, char ** argv)
135136
{
136137
return handleExceptions(argv[0], [&]() {
137138
initNix();
139+
initPlugins();
138140
out = getEnv("out");
139141
if (mkdir(out.c_str(), 0755) == -1)
140142
throw SysError(format("creating %1%") % out);

src/libexpr/eval.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store)
323323
vEmptySet.type = tAttrs;
324324
vEmptySet.attrs = allocBindings(0);
325325

326+
/* This should always be last so plugins see a fully initialized
327+
state, modulo builtins sorting. */
326328
createBaseEnv();
327329
}
328330

src/libexpr/eval.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ private:
210210

211211
void createBaseEnv();
212212

213+
public:
214+
213215
void addConstant(const string & name, Value & v);
214216

215217
Value * addPrimOp(const string & name,
216218
unsigned int arity, PrimOpFun primOp);
217219

218-
public:
219-
220220
Value & getBuiltin(const string & name);
221221

222222
private:

src/libexpr/primops.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,9 @@ void EvalState::createBaseEnv()
22282228
for (auto & primOp : *RegisterPrimOp::primOps)
22292229
addPrimOp(std::get<0>(primOp), std::get<1>(primOp), std::get<2>(primOp));
22302230

2231+
for (const auto & plugin : settings.plugins.evalPlugins)
2232+
plugin(*this);
2233+
22312234
/* Now that we've added all primops, sort the `builtins' set,
22322235
because attribute lookups expect it to be sorted. */
22332236
baseEnv.values[0]->attrs->sort();

0 commit comments

Comments
 (0)