diff --git a/Makefile b/Makefile index 2eabeb077477..f5f0298116db 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ makefiles = \ src/libutil/local.mk \ src/libstore/local.mk \ src/libfetchers/local.mk \ + src/libflake/local.mk \ src/libmain/local.mk \ src/libexpr/local.mk \ src/libcmd/local.mk \ diff --git a/src/libcmd/local.mk b/src/libcmd/local.mk index 541a7d2bac71..d944fa937b18 100644 --- a/src/libcmd/local.mk +++ b/src/libcmd/local.mk @@ -6,10 +6,10 @@ libcmd_DIR := $(d) libcmd_SOURCES := $(wildcard $(d)/*.cc) -libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers +libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libflake -I src/libexpr -I src/libmain libcmd_LDFLAGS = $(EDITLINE_LIBS) $(LOWDOWN_LIBS) -pthread -libcmd_LIBS = libstore libutil libexpr libmain libfetchers +libcmd_LIBS = libutil libstore libfetchers libflake libexpr libmain $(eval $(call install-file-in, $(d)/nix-cmd.pc, $(libdir)/pkgconfig, 0644)) diff --git a/src/libexpr/flake/config.cc b/src/libexpr/flake/config.cc index e890148621eb..d6093569bb5b 100644 --- a/src/libexpr/flake/config.cc +++ b/src/libexpr/flake/config.cc @@ -1,6 +1,6 @@ #include "flake.hh" #include "globals.hh" -#include "fetch-settings.hh" +#include "flake-settings.hh" #include @@ -50,7 +50,7 @@ void ConfigFile::apply() else assert(false); - if (!whitelist.count(baseName) && !nix::fetchSettings.acceptFlakeConfig) { + if (!whitelist.count(baseName) && !nix::flakeSettings.acceptFlakeConfig) { bool trusted = false; auto trustedList = readTrustedList(); auto tlname = get(trustedList, name); diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index a6212c12f4be..0de9c779a275 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -8,6 +8,7 @@ #include "fetchers.hh" #include "finally.hh" #include "fetch-settings.hh" +#include "flake-settings.hh" namespace nix { @@ -329,7 +330,7 @@ LockedFlake lockFlake( FlakeCache flakeCache; - auto useRegistries = lockFlags.useRegistries.value_or(fetchSettings.useRegistries); + auto useRegistries = lockFlags.useRegistries.value_or(flakeSettings.useRegistries); auto flake = getFlake(state, topRef, useRegistries, flakeCache); @@ -664,7 +665,7 @@ LockedFlake lockFlake( } std::string cm; - cm = fetchSettings.commitLockFileSummary.get(); + cm = flakeSettings.commitLockFileSummary.get(); if (cm == "") { cm = fmt("%s: %s", relPath, lockFileExists ? "Update" : "Add"); @@ -761,7 +762,7 @@ static void prim_getFlake(EvalState & state, const PosIdx pos, Value * * args, V LockFlags { .updateLockFile = false, .writeLockFile = false, - .useRegistries = !evalSettings.pureEval && fetchSettings.useRegistries, + .useRegistries = !evalSettings.pureEval && flakeSettings.useRegistries, .allowUnlocked = !evalSettings.pureEval, }), v); diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk index d243b9cec1d1..9a3cda4dafd9 100644 --- a/src/libexpr/local.mk +++ b/src/libexpr/local.mk @@ -12,9 +12,9 @@ libexpr_SOURCES := \ $(d)/lexer-tab.cc \ $(d)/parser-tab.cc -libexpr_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libmain -I src/libexpr +libexpr_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libflake -I src/libexpr -libexpr_LIBS = libutil libstore libfetchers +libexpr_LIBS = libutil libstore libfetchers libflake libexpr_LDFLAGS += -lboost_context -pthread ifdef HOST_LINUX diff --git a/src/libfetchers/fetch-settings.hh b/src/libfetchers/fetch-settings.hh index 6108a179cda4..10caa70b8af7 100644 --- a/src/libfetchers/fetch-settings.hh +++ b/src/libfetchers/fetch-settings.hh @@ -70,31 +70,6 @@ struct FetchSettings : public Config Setting warnDirty{this, true, "warn-dirty", "Whether to warn about dirty Git/Mercurial trees."}; - - Setting flakeRegistry{this, "https://channels.nixos.org/flake-registry.json", "flake-registry", - R"( - Path or URI of the global flake registry. - - When empty, disables the global flake registry. - )", - {}, true, Xp::Flakes}; - - - Setting useRegistries{this, true, "use-registries", - "Whether to use flake registries to resolve flake references.", - {}, true, Xp::Flakes}; - - Setting acceptFlakeConfig{this, false, "accept-flake-config", - "Whether to accept nix configuration from a flake without prompting.", - {}, true, Xp::Flakes}; - - Setting commitLockFileSummary{ - this, "", "commit-lockfile-summary", - R"( - The commit summary to use when committing changed flake lock files. If - empty, the summary is generated based on the action performed. - )", - {}, true, Xp::Flakes}; }; // FIXME: don't use a global variable. diff --git a/src/libflake/flake-settings.cc b/src/libflake/flake-settings.cc new file mode 100644 index 000000000000..03ac4f94f305 --- /dev/null +++ b/src/libflake/flake-settings.cc @@ -0,0 +1,13 @@ +#include "flake-settings.hh" + +namespace nix { + +FlakeSettings::FlakeSettings() +{ +} + +FlakeSettings flakeSettings; + +static GlobalConfig::Register rFlakeSettings(&flakeSettings); + +} diff --git a/src/libflake/flake-settings.hh b/src/libflake/flake-settings.hh new file mode 100644 index 000000000000..72ea55e61984 --- /dev/null +++ b/src/libflake/flake-settings.hh @@ -0,0 +1,48 @@ +#pragma once +///@file + +#include "types.hh" +#include "config.hh" +#include "util.hh" + +#include +#include + +#include + +namespace nix { + +struct FlakeSettings : public Config +{ + FlakeSettings(); + + Setting flakeRegistry{this, "https://channels.nixos.org/flake-registry.json", "flake-registry", + R"( + Path or URI of the global flake registry. + + When empty, disables the global flake registry. + )", + {}, true, Xp::Flakes}; + + + Setting useRegistries{this, true, "use-registries", + "Whether to use flake registries to resolve flake references.", + {}, true, Xp::Flakes}; + + Setting acceptFlakeConfig{this, false, "accept-flake-config", + "Whether to accept nix configuration from a flake without prompting.", + {}, true, Xp::Flakes}; + + Setting commitLockFileSummary{ + this, "", "commit-lockfile-summary", + R"( + The commit summary to use when committing changed flake lock files. If + empty, the summary is generated based on the action performed. + )", + {}, true, Xp::Flakes}; +}; + +// FIXME: don't use a global variable. +extern FlakeSettings flakeSettings; + +} diff --git a/src/libfetchers/indirect.cc b/src/libflake/indirect.cc similarity index 100% rename from src/libfetchers/indirect.cc rename to src/libflake/indirect.cc diff --git a/src/libflake/local.mk b/src/libflake/local.mk new file mode 100644 index 000000000000..fad11b0c1683 --- /dev/null +++ b/src/libflake/local.mk @@ -0,0 +1,13 @@ +libraries += libflake + +libflake_NAME = libnixflake + +libflake_DIR := $(d) + +libflake_SOURCES := $(wildcard $(d)/*.cc) + +libflake_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers + +libflake_LDFLAGS += -pthread + +libflake_LIBS = libutil libstore libfetchers diff --git a/src/libfetchers/registry.cc b/src/libflake/registry.cc similarity index 98% rename from src/libfetchers/registry.cc rename to src/libflake/registry.cc index 43c03beec17f..162c25c6ecca 100644 --- a/src/libfetchers/registry.cc +++ b/src/libflake/registry.cc @@ -5,7 +5,7 @@ #include "store-api.hh" #include "local-fs-store.hh" -#include "fetch-settings.hh" +#include "flake-settings.hh" #include @@ -152,7 +152,7 @@ void overrideRegistry( static std::shared_ptr getGlobalRegistry(ref store) { static auto reg = [&]() { - auto path = fetchSettings.flakeRegistry.get(); + auto path = flakeSettings.flakeRegistry.get(); if (path == "") { return std::make_shared(Registry::Global); // empty registry } diff --git a/src/libfetchers/registry.hh b/src/libflake/registry.hh similarity index 100% rename from src/libfetchers/registry.hh rename to src/libflake/registry.hh diff --git a/src/nix/local.mk b/src/nix/local.mk index 20ea29d10fac..a6860aff9a26 100644 --- a/src/nix/local.mk +++ b/src/nix/local.mk @@ -14,9 +14,9 @@ nix_SOURCES := \ $(wildcard src/nix-instantiate/*.cc) \ $(wildcard src/nix-store/*.cc) \ -nix_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libexpr -I src/libmain -I src/libcmd -I doc/manual +nix_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libflake -I src/libexpr -I src/libmain -I src/libcmd -I doc/manual -nix_LIBS = libexpr libmain libfetchers libstore libutil libcmd +nix_LIBS = libexpr libmain libflake libfetchers libstore libutil libcmd nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) $(LOWDOWN_LIBS)