Skip to content

Commit

Permalink
Merge branch 'new-store-settings' into settings-split
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 17, 2024
2 parents 13d573b + 3b0edea commit afee3ee
Show file tree
Hide file tree
Showing 36 changed files with 721 additions and 295 deletions.
12 changes: 6 additions & 6 deletions maintainers/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,14 @@
''^src/libflake/flake/lockfile\.cc$''
''^src/libflake/flake/lockfile\.hh$''
''^src/libflake/flake/url-name\.cc$''
''^src/libmain/args/root\.hh$''
''^src/libmain/args\.cc$''
''^src/libmain/args\.hh$''
''^src/libmain/common-args\.cc$''
''^src/libmain/common-args\.hh$''
''^src/libmain/config-impl\.hh$''
''^src/libmain/config\.cc$''
''^src/libmain/config\.hh$''
''^src/libmain/loggers\.cc$''
''^src/libmain/loggers\.hh$''
''^src/libmain/progress-bar\.cc$''
Expand Down Expand Up @@ -258,19 +264,13 @@
''^src/libutil-c/nix_api_util_internal\.h$''
''^src/libutil/archive\.cc$''
''^src/libutil/archive\.hh$''
''^src/libutil/args\.cc$''
''^src/libutil/args\.hh$''
''^src/libutil/args/root\.hh$''
''^src/libutil/callback\.hh$''
''^src/libutil/canon-path\.cc$''
''^src/libutil/canon-path\.hh$''
''^src/libutil/chunked-vector\.hh$''
''^src/libutil/closure\.hh$''
''^src/libutil/comparator\.hh$''
''^src/libutil/compute-levels\.cc$''
''^src/libutil/config-impl\.hh$''
''^src/libutil/config\.cc$''
''^src/libutil/config\.hh$''
''^src/libutil/current-process\.cc$''
''^src/libutil/current-process\.hh$''
''^src/libutil/english\.cc$''
Expand Down
22 changes: 13 additions & 9 deletions src/libmain/config-upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace nix {
struct LoggerSettings : Config
{
Setting<bool> showTrace{
this, false, "show-trace",
this,
false,
"show-trace",
R"(
Whether Nix should print out a stack trace in case of Nix
expression evaluation errors.
Expand All @@ -17,22 +19,24 @@ static GlobalConfig::Register r1(&restoreSinkSettings);

struct RestoreSinkSettings : Config
{
Setting<bool> preallocateContents{this, false, "preallocate-contents",
"Whether to preallocate files when writing objects with known size."};
Setting<bool> preallocateContents{
this, false, "preallocate-contents", "Whether to preallocate files when writing objects with known size."};
};

static GlobalConfig::Register rLoggerSettings(&loggerSettings);

struct ArchiveSettings : Config
{
Setting<bool> useCaseHack{this,
#if __APPLE__
Setting<bool> useCaseHack
{
this,
#if __APPLE__
true,
#else
#else
false,
#endif
"use-case-hack",
"Whether to enable a Darwin-specific hack for dealing with file name collisions."};
#endif
"use-case-hack", "Whether to enable a Darwin-specific hack for dealing with file name collisions."
};
};

static GlobalConfig::Register rArchiveSettings(&archiveSettings);
Expand Down
13 changes: 13 additions & 0 deletions src/libstore/config-parse.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

/**
* Look up the setting's name in a map, falling back on the default if
* it does not exist.
*/
#define CONFIG_ROW(FIELD) \
.FIELD = { \
.value = ({ \
auto p = get(params, descriptions.FIELD.name); \
p ? *p : defaults.FIELD.value; \
}), \
}
28 changes: 16 additions & 12 deletions src/libstore/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ namespace nix {
struct DummyStoreConfig : virtual StoreConfig {
using StoreConfig::StoreConfig;

DummyStoreConfig(std::string_view scheme, std::string_view authority, const Params & params)
: StoreConfig(params)
{
if (!authority.empty())
throw UsageError("`%s` store URIs must not contain an authority part %s", scheme, authority);
}

const std::string name() override { return "Dummy Store"; }

std::string doc() override
Expand All @@ -14,23 +21,24 @@ struct DummyStoreConfig : virtual StoreConfig {
#include "dummy-store.md"
;
}

static std::set<std::string> uriSchemes() {
return {"dummy"};
}
};

struct DummyStore : public virtual DummyStoreConfig, public virtual Store
{
DummyStore(std::string_view scheme, std::string_view authority, const Params & params)
: DummyStore(params)
{
if (!authority.empty())
throw UsageError("`%s` store URIs must not contain an authority part %s", scheme, authority);
}

DummyStore(const Params & params)
: StoreConfig(params)
, DummyStoreConfig(params)
, DummyStoreConfig(scheme, authority, params)
, Store(params)
{ }

DummyStore(const Params & params)
: DummyStore("dummy", "", params)
{ }

std::string getUri() override
{
return *uriSchemes().begin();
Expand All @@ -50,10 +58,6 @@ struct DummyStore : public virtual DummyStoreConfig, public virtual Store
return Trusted;
}

static std::set<std::string> uriSchemes() {
return {"dummy"};
}

std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
{ unsupported("queryPathFromHashPart"); }

Expand Down
58 changes: 26 additions & 32 deletions src/libstore/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "binary-cache-store.hh"
#include "http-binary-cache-store.hh"
#include "filetransfer.hh"
#include "globals.hh"
#include "nar-info-disk-cache.hh"
Expand All @@ -8,26 +8,37 @@ namespace nix {

MakeError(UploadToHTTP, Error);

struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig

HttpBinaryCacheStoreConfig::HttpBinaryCacheStoreConfig(
std::string_view scheme,
std::string_view _cacheUri,
const Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, cacheUri(
std::string { scheme }
+ "://"
+ (!_cacheUri.empty()
? _cacheUri
: throw UsageError("`%s` Store requires a non-empty authority in Store URL", scheme)))
{
using BinaryCacheStoreConfig::BinaryCacheStoreConfig;
while (!cacheUri.empty() && cacheUri.back() == '/')
cacheUri.pop_back();
}

const std::string name() override { return "HTTP Binary Cache Store"; }

std::string doc() override
{
return
#include "http-binary-cache-store.md"
;
}
};
std::string HttpBinaryCacheStoreConfig::doc()
{
return
#include "http-binary-cache-store.md"
;
}


class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public virtual BinaryCacheStore
{
private:

Path cacheUri;

struct State
{
bool enabled = true;
Expand All @@ -40,23 +51,14 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v

HttpBinaryCacheStore(
std::string_view scheme,
PathView _cacheUri,
PathView cacheUri,
const Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, HttpBinaryCacheStoreConfig(params)
, HttpBinaryCacheStoreConfig(scheme, cacheUri, params)
, Store(params)
, BinaryCacheStore(params)
, cacheUri(
std::string { scheme }
+ "://"
+ (!_cacheUri.empty()
? _cacheUri
: throw UsageError("`%s` Store requires a non-empty authority in Store URL", scheme)))
{
while (!cacheUri.empty() && cacheUri.back() == '/')
cacheUri.pop_back();

diskCache = getNarInfoDiskCache();
}

Expand All @@ -81,14 +83,6 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v
}
}

static std::set<std::string> uriSchemes()
{
static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1";
auto ret = std::set<std::string>({"http", "https"});
if (forceHttp) ret.insert("file");
return ret;
}

protected:

void maybeDisable()
Expand Down
30 changes: 30 additions & 0 deletions src/libstore/http-binary-cache-store.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "binary-cache-store.hh"

namespace nix {

struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
{
using BinaryCacheStoreConfig::BinaryCacheStoreConfig;

HttpBinaryCacheStoreConfig(std::string_view scheme, std::string_view _cacheUri, const Params & params);

Path cacheUri;

const std::string name() override
{
return "HTTP Binary Cache Store";
}

static std::set<std::string> uriSchemes()
{
static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1";
auto ret = std::set<std::string>({"http", "https"});
if (forceHttp)
ret.insert("file");
return ret;
}

std::string doc() override;
};

}
4 changes: 2 additions & 2 deletions src/libstore/legacy-ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct LegacySSHStoreConfig : virtual CommonSSHStoreConfig

const std::string name() override { return "SSH Store"; }

static std::set<std::string> uriSchemes() { return {"ssh"}; }

std::string doc() override;
};

Expand All @@ -46,8 +48,6 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor

SSHMaster master;

static std::set<std::string> uriSchemes() { return {"ssh"}; }

LegacySSHStore(
std::string_view scheme,
std::string_view host,
Expand Down
40 changes: 18 additions & 22 deletions src/libstore/local-binary-cache-store.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "binary-cache-store.hh"
#include "local-binary-cache-store.hh"
#include "globals.hh"
#include "nar-info-disk-cache.hh"
#include "signals.hh"
Expand All @@ -7,28 +7,27 @@

namespace nix {

struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
LocalBinaryCacheStoreConfig::LocalBinaryCacheStoreConfig(
std::string_view scheme,
PathView binaryCacheDir,
const Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, binaryCacheDir(binaryCacheDir)
{
using BinaryCacheStoreConfig::BinaryCacheStoreConfig;

const std::string name() override { return "Local Binary Cache Store"; }
}

std::string doc() override
{
return
#include "local-binary-cache-store.md"
;
}
};

class LocalBinaryCacheStore : public virtual LocalBinaryCacheStoreConfig, public virtual BinaryCacheStore
std::string LocalBinaryCacheStoreConfig::doc()
{
private:

Path binaryCacheDir;
return
#include "local-binary-cache-store.md"
;
}

public:

struct LocalBinaryCacheStore : virtual LocalBinaryCacheStoreConfig, virtual BinaryCacheStore
{
/**
* @param binaryCacheDir `file://` is a short-hand for `file:///`
* for now.
Expand All @@ -39,10 +38,9 @@ class LocalBinaryCacheStore : public virtual LocalBinaryCacheStoreConfig, public
const Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, LocalBinaryCacheStoreConfig(params)
, LocalBinaryCacheStoreConfig(scheme, binaryCacheDir, params)
, Store(params)
, BinaryCacheStore(params)
, binaryCacheDir(binaryCacheDir)
{
}

Expand All @@ -53,8 +51,6 @@ class LocalBinaryCacheStore : public virtual LocalBinaryCacheStoreConfig, public
return "file://" + binaryCacheDir;
}

static std::set<std::string> uriSchemes();

protected:

bool fileExists(const std::string & path) override;
Expand Down Expand Up @@ -123,7 +119,7 @@ bool LocalBinaryCacheStore::fileExists(const std::string & path)
return pathExists(binaryCacheDir + "/" + path);
}

std::set<std::string> LocalBinaryCacheStore::uriSchemes()
std::set<std::string> LocalBinaryCacheStoreConfig::uriSchemes()
{
if (getEnv("_NIX_FORCE_HTTP") == "1")
return {};
Expand Down
Loading

0 comments on commit afee3ee

Please sign in to comment.