Skip to content

Commit

Permalink
Move some code to a new libnixflake
Browse files Browse the repository at this point in the history
For now, this sits between `libnixfetchers` and `libnixflakes`, but
eventually I hope it can sit atop `libexprs`. Baby steps though, this is
fine for now.

The immediate impact of this is that some flakes-specific parts of
`libnixfetchers` can move here, after which I hearby declare libfetchers
is free of layer violations, and we are thus (baring something unrelated
I missed) ready to stabilize `builtins.fetchTree`.
  • Loading branch information
Ericson2314 committed Sep 29, 2023
1 parent 89b3952 commit bf70b88
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 38 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions src/libcmd/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions src/libexpr/flake/config.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "flake.hh"
#include "globals.hh"
#include "fetch-settings.hh"
#include "flake-settings.hh"

#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "fetchers.hh"
#include "finally.hh"
#include "fetch-settings.hh"
#include "flake-settings.hh"

namespace nix {

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions src/libfetchers/fetch-settings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,6 @@ struct FetchSettings : public Config

Setting<bool> warnDirty{this, true, "warn-dirty",
"Whether to warn about dirty Git/Mercurial trees."};

Setting<std::string> 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<bool> useRegistries{this, true, "use-registries",
"Whether to use flake registries to resolve flake references.",
{}, true, Xp::Flakes};

Setting<bool> acceptFlakeConfig{this, false, "accept-flake-config",
"Whether to accept nix configuration from a flake without prompting.",
{}, true, Xp::Flakes};

Setting<std::string> 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.
Expand Down
13 changes: 13 additions & 0 deletions src/libflake/flake-settings.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "flake-settings.hh"

namespace nix {

FlakeSettings::FlakeSettings()
{
}

FlakeSettings flakeSettings;

static GlobalConfig::Register rFlakeSettings(&flakeSettings);

}
48 changes: 48 additions & 0 deletions src/libflake/flake-settings.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once
///@file

#include "types.hh"
#include "config.hh"
#include "util.hh"

#include <map>
#include <limits>

#include <sys/types.h>

namespace nix {

struct FlakeSettings : public Config
{
FlakeSettings();

Setting<std::string> 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<bool> useRegistries{this, true, "use-registries",
"Whether to use flake registries to resolve flake references.",
{}, true, Xp::Flakes};

Setting<bool> acceptFlakeConfig{this, false, "accept-flake-config",
"Whether to accept nix configuration from a flake without prompting.",
{}, true, Xp::Flakes};

Setting<std::string> 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;

}
File renamed without changes.
13 changes: 13 additions & 0 deletions src/libflake/local.mk
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/libfetchers/registry.cc → src/libflake/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "store-api.hh"
#include "local-fs-store.hh"

#include "fetch-settings.hh"
#include "flake-settings.hh"

#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -152,7 +152,7 @@ void overrideRegistry(
static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store)
{
static auto reg = [&]() {
auto path = fetchSettings.flakeRegistry.get();
auto path = flakeSettings.flakeRegistry.get();
if (path == "") {
return std::make_shared<Registry>(Registry::Global); // empty registry
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/nix/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit bf70b88

Please sign in to comment.