Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New store settings system #11139

Draft
wants to merge 76 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
f90e771
feat: Refactor unix domain socket store config
fzakaria Jul 15, 2024
1f72267
uds-remote-store is now clang-formatted
fzakaria Jul 15, 2024
660d868
Removed clang-format changes
fzakaria Jul 15, 2024
6585c6e
Reference public variable
fzakaria Jul 15, 2024
10c5c65
Update src/libstore/uds-remote-store.hh
fzakaria Jul 15, 2024
030d91d
Move constant to within Config object
fzakaria Jul 15, 2024
7169905
Lowercase constexpr
fzakaria Jul 15, 2024
4af5092
Update src/libstore/store-api.cc
fzakaria Jul 15, 2024
dd74b72
Revert back returning daemon for URI if path empty
fzakaria Jul 15, 2024
01fbb4b
Added unit test
fzakaria Jul 15, 2024
6eb3303
Added to meson
fzakaria Jul 15, 2024
d3275e8
Changed to protected and added another test
fzakaria Jul 16, 2024
0087d7d
Clang formatted test file
fzakaria Jul 16, 2024
1e97346
Merge remote-tracking branch 'upstream/master' into issue-10766-unix-…
Ericson2314 Jul 16, 2024
e733f6d
Move `UdsRemoteStore{,Config}` defs out of headers, and other cleanups
Ericson2314 Jul 16, 2024
e435f3e
Add two more headers to try to provide missing template instantiations
Ericson2314 Jul 16, 2024
ed2ccdc
Add globals.hh to uds-remote-store.cc
fzakaria Jul 16, 2024
e9c0636
Fix linking issue, convert many more
Ericson2314 Jul 16, 2024
8162dbd
Merge remote-tracking branch 'upstream/master' into issue-10766-unix-…
Ericson2314 Jul 16, 2024
f23d168
`make format`
Ericson2314 Jul 16, 2024
c4c148f
Declare some template specializations in the header
Ericson2314 Jul 16, 2024
4e79b4e
Move `uriSchemes` to `*StoreConfig`
Ericson2314 Jul 16, 2024
1e25c22
Revert "Declare some template specializations in the header"
Ericson2314 Jul 16, 2024
ea3a420
Merge branch 'move-schemes-set' into new-store-settings
Ericson2314 Jul 16, 2024
414d6ad
`make format`
Ericson2314 Jul 17, 2024
fcf3e32
Merge branch 'move-schemes-set' into HEAD
Ericson2314 Jul 17, 2024
3b0edea
WIP Start getting store settings off config.hh
Ericson2314 Jul 17, 2024
d095fa3
WIP
Ericson2314 Jul 17, 2024
121e607
Merge remote-tracking branch 'upstream/master' into new-store-settings
Ericson2314 Jul 17, 2024
7b135d5
Comment out tests
fzakaria Jul 17, 2024
596a682
Dummy store compiles
Ericson2314 Jul 17, 2024
95b36f4
Merge branch 'issue-10766-unix-socket' of github.com:fzakaria/nix int…
Ericson2314 Jul 17, 2024
0e65638
Merge remote-tracking branch 'upstream/master' into issue-10766-unix-…
Ericson2314 Jul 17, 2024
34f876f
Format, CI hopefully happy now
Ericson2314 Jul 17, 2024
a7d9394
Merge branch 'issue-10766-unix-socket' into new-store-settings
Ericson2314 Jul 17, 2024
4909f9a
Get `LocalFSStore` building
Ericson2314 Jul 18, 2024
9052c09
Merge commit '17051ca80ab9bcee896e040cfe0ea699702ac0ff' into new-stor…
Ericson2314 Jul 18, 2024
118b050
Merge remote-tracking branch 'upstream/master' into new-store-settings
Ericson2314 Jul 18, 2024
307440b
Convert `LocalStoreConfig` to new system
Ericson2314 Jul 18, 2024
de1ec5a
A bunch of small fixes
Ericson2314 Jul 18, 2024
9b30c20
Merge remote-tracking branch 'upstream/master' into new-store-settings
Ericson2314 Jul 18, 2024
bb7bf73
More progress converting
Ericson2314 Jul 18, 2024
ca1e895
WIP
Ericson2314 Jul 18, 2024
901b34f
WIP
Ericson2314 Jul 18, 2024
6e5d7fc
Convert ssh:// to new system
Ericson2314 Jul 18, 2024
74620b9
WIP
Ericson2314 Jul 18, 2024
469ac00
Convert `UDSRemoteStore`
Ericson2314 Jul 18, 2024
2fcb196
Fix `StoreReference`
Ericson2314 Jul 18, 2024
103c90b
More progress
Ericson2314 Jul 18, 2024
3a149b5
Getting close!
Ericson2314 Jul 18, 2024
68ae4dc
It builds, debugging
Ericson2314 Jul 18, 2024
387767b
Fix some bugs
Ericson2314 Jul 18, 2024
b53a4a0
More tests
Ericson2314 Jul 19, 2024
34f9b13
Inline defaults
Ericson2314 Jul 19, 2024
ae93776
Avoid potentially problematic move
Ericson2314 Jul 19, 2024
40955fa
WIP hack so it builds
Ericson2314 Jul 19, 2024
736dd76
Merge remote-tracking branch 'upstream/master' into new-store-settings
Ericson2314 Jul 19, 2024
1b027f7
Merge remote-tracking branch 'upstream/master' into new-store-settings
Ericson2314 Jul 19, 2024
1c5fac5
Adjust registration infra, fix Meson build
Ericson2314 Jul 19, 2024
a6c6852
WIP Store doesn't inherit from config
Ericson2314 Jul 20, 2024
d8856f4
Merge remote-tracking branch 'upstream/master' into new-store-settings
Ericson2314 Jul 20, 2024
48aa3bb
WIP
Ericson2314 Jul 20, 2024
1344bcd
WIP
Ericson2314 Jul 21, 2024
5a1b109
WIP
Ericson2314 Jul 21, 2024
0c8330c
WIP
Ericson2314 Jul 21, 2024
f5df5e7
WIP
Ericson2314 Jul 21, 2024
6ab4817
WIP
Ericson2314 Jul 21, 2024
cc1ce6a
WIP
Ericson2314 Jul 21, 2024
53f692b
WIP
Ericson2314 Jul 21, 2024
e621208
WIP
Ericson2314 Jul 21, 2024
05861c4
WIP
Ericson2314 Jul 21, 2024
b0c6f18
Build `S3BinaryCacheStore` with Meson
Ericson2314 Jul 21, 2024
40ebe0f
S3 binary cache store
Ericson2314 Jul 21, 2024
dd6c7f0
Merge branch 'master' into new-store-settings
Ericson2314 Jul 22, 2024
c9b772f
Merge remote-tracking branch 'upstream/master' into new-store-settings
Ericson2314 Aug 27, 2024
3829f14
Merge branch 'master' into new-store-settings
Ericson2314 Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/build-remote/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "globals.hh"
#include "serialise.hh"
#include "build-result.hh"
#include "store-api.hh"
#include "store-open.hh"
#include "strings.hh"
#include "derivations.hh"
#include "local-store.hh"
Expand Down Expand Up @@ -44,7 +44,7 @@ static AutoCloseFD openSlotLock(const Machine & m, uint64_t slot)

static bool allSupportedLocally(Store & store, const std::set<std::string>& requiredFeatures) {
for (auto & feature : requiredFeatures)
if (!store.systemFeatures.get().count(feature)) return false;
if (!store.config.systemFeatures.get().count(feature)) return false;
return true;
}

Expand Down Expand Up @@ -85,7 +85,7 @@ static int main_build_remote(int argc, char * * argv)
that gets cleared on reboot, but it wouldn't work on macOS. */
auto currentLoadName = "/current-load";
if (auto localStore = store.dynamic_pointer_cast<LocalFSStore>())
currentLoad = std::string { localStore->stateDir } + currentLoadName;
currentLoad = std::string { localStore->config.stateDir } + currentLoadName;
else
currentLoad = settings.nixStateDir + currentLoadName;

Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "command.hh"
#include "markdown.hh"
#include "store-api.hh"
#include "store-open.hh"
#include "local-fs-store.hh"
#include "derivations.hh"
#include "nixexpr.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "registry.hh"
#include "flake/flakeref.hh"
#include "flake/settings.hh"
#include "store-api.hh"
#include "store-open.hh"
#include "command.hh"
#include "tarball.hh"
#include "fetch-to-store.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "eval-settings.hh"
#include "attr-path.hh"
#include "signals.hh"
#include "store-api.hh"
#include "store-open.hh"
#include "log-store.hh"
#include "common-eval-args.hh"
#include "get-drvs.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/primops/fetchClosure.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "primops.hh"
#include "store-api.hh"
#include "store-open.hh"
#include "realisation.hh"
#include "make-content-addressed.hh"
#include "url.hh"
Expand Down
3 changes: 2 additions & 1 deletion src/libstore-c/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "path.hh"
#include "store-api.hh"
#include "store-open.hh"
#include "build-result.hh"

#include "globals.hh"
Expand Down Expand Up @@ -42,7 +43,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
if (!params)
return new Store{nix::openStore(uri_str)};

nix::Store::Params params_map;
nix::StoreReference::Params params_map;
for (size_t i = 0; params[i] != nullptr; i++) {
params_map[params[i][0]] = params[i][1];
}
Expand Down
117 changes: 99 additions & 18 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "callback.hh"
#include "signals.hh"
#include "archive.hh"
#include "config-parse-impl.hh"

#include <chrono>
#include <future>
Expand All @@ -24,17 +25,91 @@

namespace nix {

BinaryCacheStore::BinaryCacheStore(const Params & params)
: BinaryCacheStoreConfig(params)
, Store(params)
static const BinaryCacheStoreConfigT<config::SettingInfo> binaryCacheStoreConfigDescriptions = {
.compression = {
.name = "compression",
.description = "NAR compression method (`xz`, `bzip2`, `gzip`, `zstd`, or `none`).",
},
.writeNARListing = {
.name = "write-nar-listing",
.description = "Whether to write a JSON file that lists the files in each NAR.",
},
.writeDebugInfo = {
.name = "index-debug-info",
.description = R"(
Whether to index DWARF debug info files by build ID. This allows [`dwarffs`](https://github.com/edolstra/dwarffs) to
fetch debug info on demand
)",
},
.secretKeyFile{
.name = "secret-key",
.description = "Path to the secret key used to sign the binary cache.",
},
.localNarCache{
.name = "local-nar-cache",
.description = "Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`.",
},
.parallelCompression{
.name = "parallel-compression",
.description = "Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`.",
},
.compressionLevel{
.name = "compression-level",
.description = R"(
The *preset level* to be used when compressing NARs.
The meaning and accepted values depend on the compression method selected.
`-1` specifies that the default compression level should be used.
)",
},
};

#define BINARY_CACHE_STORE_CONFIG_FIELDS(X) \
X(compression), \
X(writeNARListing), \
X(writeDebugInfo), \
X(secretKeyFile), \
X(localNarCache), \
X(parallelCompression), \
X(compressionLevel),

MAKE_PARSE(BinaryCacheStoreConfig, binaryCacheStoreConfig, BINARY_CACHE_STORE_CONFIG_FIELDS)

static BinaryCacheStoreConfigT<config::JustValue> binaryCacheStoreConfigDefaults()
{
if (secretKeyFile != "")
return {
.compression = {"xz"},
.writeNARListing = {false},
.writeDebugInfo = {false},
.secretKeyFile = {""},
.localNarCache = {""},
.parallelCompression = {false},
.compressionLevel = {-1},
};
}

MAKE_APPLY_PARSE(BinaryCacheStoreConfig, binaryCacheStoreConfig, BINARY_CACHE_STORE_CONFIG_FIELDS)

BinaryCacheStore::Config::BinaryCacheStoreConfig(
const Store::Config & storeConfig,
const StoreReference::Params & params)
: BinaryCacheStoreConfigT<config::JustValue>{binaryCacheStoreConfigApplyParse(params)}
, storeConfig{storeConfig}
{
}

BinaryCacheStore::BinaryCacheStore(const Config & config)
: Store{config.storeConfig}
, config{config}
{
if (config.secretKeyFile != "")
signer = std::make_unique<LocalSigner>(
SecretKey { readFile(secretKeyFile) });
SecretKey { readFile(config.secretKeyFile) });

StringSink sink;
sink << narVersionMagic1;
narMagic = sink.s;

init();
}

void BinaryCacheStore::init()
Expand All @@ -55,9 +130,11 @@ void BinaryCacheStore::init()
throw Error("binary cache '%s' is for Nix stores with prefix '%s', not '%s'",
getUri(), value, storeDir);
} else if (name == "WantMassQuery") {
wantMassQuery.setDefault(value == "1");
resolvedSubstConfig.wantMassQuery.value =
config.storeConfig.wantMassQuery.optValue.value_or(value == "1");
} else if (name == "Priority") {
priority.setDefault(std::stoi(value));
resolvedSubstConfig.priority.value =
config.storeConfig.priority.optValue.value_or(std::stoi(value));
}
}
}
Expand Down Expand Up @@ -144,7 +221,11 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
{
FdSink fileSink(fdTemp.get());
TeeSink teeSinkCompressed { fileSink, fileHashSink };
auto compressionSink = makeCompressionSink(compression, teeSinkCompressed, parallelCompression, compressionLevel);
auto compressionSink = makeCompressionSink(
config.compression,
teeSinkCompressed,
config.parallelCompression,
config.compressionLevel);
TeeSink teeSinkUncompressed { *compressionSink, narHashSink };
TeeSource teeSource { narSource, teeSinkUncompressed };
narAccessor = makeNarAccessor(teeSource);
Expand All @@ -156,17 +237,17 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(

auto info = mkInfo(narHashSink.finish());
auto narInfo = make_ref<NarInfo>(info);
narInfo->compression = compression;
narInfo->compression = config.compression;
auto [fileHash, fileSize] = fileHashSink.finish();
narInfo->fileHash = fileHash;
narInfo->fileSize = fileSize;
narInfo->url = "nar/" + narInfo->fileHash->to_string(HashFormat::Nix32, false) + ".nar"
+ (compression == "xz" ? ".xz" :
compression == "bzip2" ? ".bz2" :
compression == "zstd" ? ".zst" :
compression == "lzip" ? ".lzip" :
compression == "lz4" ? ".lz4" :
compression == "br" ? ".br" :
+ (config.compression == "xz" ? ".xz" :
config.compression == "bzip2" ? ".bz2" :
config.compression == "zstd" ? ".zst" :
config.compression == "lzip" ? ".lzip" :
config.compression == "lz4" ? ".lz4" :
config.compression == "br" ? ".br" :
"");

auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now2 - now1).count();
Expand All @@ -188,7 +269,7 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(

/* Optionally write a JSON file containing a listing of the
contents of the NAR. */
if (writeNARListing) {
if (config.writeNARListing) {
nlohmann::json j = {
{"version", 1},
{"root", listNar(ref<SourceAccessor>(narAccessor), CanonPath::root, true)},
Expand All @@ -200,7 +281,7 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
/* Optionally maintain an index of DWARF debug info files
consisting of JSON files named 'debuginfo/<build-id>' that
specify the NAR file and member containing the debug info. */
if (writeDebugInfo) {
if (config.writeDebugInfo) {

CanonPath buildIdDir("lib/debug/.build-id");

Expand Down Expand Up @@ -512,7 +593,7 @@ void BinaryCacheStore::registerDrvOutput(const Realisation& info) {

ref<SourceAccessor> BinaryCacheStore::getFSAccessor(bool requireValidPath)
{
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), requireValidPath, localNarCache);
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), requireValidPath, config.localNarCache);
}

void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSet & sigs)
Expand Down
61 changes: 28 additions & 33 deletions src/libstore/binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,39 @@ namespace nix {

struct NarInfo;

struct BinaryCacheStoreConfig : virtual StoreConfig
template<template<typename> class F>
struct BinaryCacheStoreConfigT
{
using StoreConfig::StoreConfig;

const Setting<std::string> compression{this, "xz", "compression",
"NAR compression method (`xz`, `bzip2`, `gzip`, `zstd`, or `none`)."};

const Setting<bool> writeNARListing{this, false, "write-nar-listing",
"Whether to write a JSON file that lists the files in each NAR."};

const Setting<bool> writeDebugInfo{this, false, "index-debug-info",
R"(
Whether to index DWARF debug info files by build ID. This allows [`dwarffs`](https://github.com/edolstra/dwarffs) to
fetch debug info on demand
)"};

const Setting<Path> secretKeyFile{this, "", "secret-key",
"Path to the secret key used to sign the binary cache."};
F<std::string> compression;
F<bool> writeNARListing;
F<bool> writeDebugInfo;
F<Path> secretKeyFile;
F<Path> localNarCache;
F<bool> parallelCompression;
F<int> compressionLevel;
};

const Setting<Path> localNarCache{this, "", "local-nar-cache",
"Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."};
struct BinaryCacheStoreConfig :
BinaryCacheStoreConfigT<config::JustValue>
{
static config::SettingDescriptionMap descriptions();

const Setting<bool> parallelCompression{this, false, "parallel-compression",
"Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`."};
const Store::Config & storeConfig;

const Setting<int> compressionLevel{this, -1, "compression-level",
R"(
The *preset level* to be used when compressing NARs.
The meaning and accepted values depend on the compression method selected.
`-1` specifies that the default compression level should be used.
)"};
BinaryCacheStoreConfig(const Store::Config &, const StoreReference::Params &);
};


/**
* @note subclasses must implement at least one of the two
* virtual getFile() methods.
*/
class BinaryCacheStore : public virtual BinaryCacheStoreConfig,
public virtual Store,
public virtual LogStore
struct BinaryCacheStore :
virtual Store,
virtual LogStore
{
using Config = BinaryCacheStoreConfig;

const Config & config;

private:
std::unique_ptr<Signer> signer;
Expand All @@ -64,7 +55,7 @@ protected:
// The prefix under which realisation infos will be stored
const std::string realisationsPrefix = "realisations";

BinaryCacheStore(const Params & params);
BinaryCacheStore(const Config &);

public:

Expand Down Expand Up @@ -96,7 +87,11 @@ public:

public:

virtual void init() override;
/**
* Perform any necessary effectful operation to make the store up and
* running
*/
virtual void init();

private:

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/build/derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ Path DerivationGoal::openLogFile()
/* Create a log file. */
Path logDir;
if (auto localStore = dynamic_cast<LocalStore *>(&worker.store))
logDir = localStore->logDir;
logDir = localStore->config->logDir;
else
logDir = settings.nixLogDir;
Path dir = fmt("%s/%s/%s/", logDir, LocalFSStore::drvsLogDir, baseName.substr(0, 2));
Expand Down
1 change: 1 addition & 0 deletions src/libstore/build/drv-output-substitution-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "worker.hh"
#include "substitution-goal.hh"
#include "callback.hh"
#include "store-open.hh"

namespace nix {

Expand Down
5 changes: 3 additions & 2 deletions src/libstore/build/substitution-goal.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "worker.hh"
#include "store-open.hh"
#include "substitution-goal.hh"
#include "nar-info.hh"
#include "finally.hh"
Expand Down Expand Up @@ -121,7 +122,7 @@ Goal::Co PathSubstitutionGoal::init()
/* Bail out early if this substituter lacks a valid
signature. LocalStore::addToStore() also checks for this, but
only after we've downloaded the path. */
if (!sub->isTrusted && worker.store.pathInfoIsUntrusted(*info))
if (!sub->config.isTrusted && worker.store.pathInfoIsUntrusted(*info))
{
warn("ignoring substitute for '%s' from '%s', as it's not signed by any of the keys in 'trusted-public-keys'",
worker.store.printStorePath(storePath), sub->getUri());
Expand Down Expand Up @@ -210,7 +211,7 @@ Goal::Co PathSubstitutionGoal::tryToRun(StorePath subPath, nix::ref<Store> sub,
PushActivity pact(act.id);

copyStorePath(*sub, worker.store,
subPath, repair, sub->isTrusted ? NoCheckSigs : CheckSigs);
subPath, repair, sub->config.isTrusted ? NoCheckSigs : CheckSigs);

promise.set_value();
} catch (...) {
Expand Down
Loading
Loading