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 18, 2024
2 parents f7df182 + 901b34f commit 9e6d1eb
Show file tree
Hide file tree
Showing 37 changed files with 533 additions and 289 deletions.
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/installable-value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct ExtraPathInfoValue : ExtraPathInfo
};

/**
* An Installable which corresponds a Nix langauge value, in addition to
* An Installable which corresponds a Nix language value, in addition to
* a collection of \ref DerivedPath "derived paths".
*/
struct InstallableValue : Installable
Expand Down
4 changes: 2 additions & 2 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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 Expand Up @@ -635,7 +635,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
// When missing, trigger the normal exception
// e.g. :doc builtins.foo
// behaves like
// nix-repl> builtins.foo
// nix-repl> builtins.foo
// error: attribute 'foo' missing
evalString(arg, v);
assert(false);
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct AttrDb
{
try {
auto state(_state->lock());
if (!failed)
if (!failed && state->txn->active)
state->txn->commit();
state->txn.reset();
} catch (...) {
Expand Down
72 changes: 69 additions & 3 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,9 +25,74 @@

namespace nix {

BinaryCacheStore::BinaryCacheStore(const Params & params)
: BinaryCacheStoreConfig(params)
, Store(params)
BinaryCacheStore::Config::Descriptions::Descriptions()
: Store::Config::Descriptions{Store::Config::descriptions}
, BinaryCacheStoreConfigT<config::SettingInfo>{
.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.
)",
},
}
{}

const BinaryCacheStore::Config::Descriptions BinaryCacheStore::Config::descriptions{};

decltype(BinaryCacheStore::Config::defaults) BinaryCacheStore::Config::defaults = {
.compression = {"xz"},
.writeNARListing{false},
.writeDebugInfo{false},
.secretKeyFile{""},
.localNarCache{""},
.parallelCompression{false},
.compressionLevel{-1},
};

BinaryCacheStore::Config::BinaryCacheStoreConfig(const StoreReference::Params & params)
: StoreConfig{params}
, BinaryCacheStoreConfigT<config::JustValue>{
CONFIG_ROW(compression),
CONFIG_ROW(secretKeyFile),
CONFIG_ROW(localNarCache),
CONFIG_ROW(parallelCompression),
CONFIG_ROW(compressionLevel),
}
{
}

BinaryCacheStore::BinaryCacheStore(const Config & config)
: Config{config}
, Store{static_cast<const Store::Config &>(*this)}
{
if (secretKeyFile != "")
signer = std::make_unique<LocalSigner>(
Expand Down
60 changes: 29 additions & 31 deletions src/libstore/binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,46 @@ 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 F<std::string> compression;
const F<bool> writeNARListing;
const F<bool> writeDebugInfo;
const F<Path> secretKeyFile;
const F<Path> localNarCache;
const F<bool> parallelCompression;
const F<int> compressionLevel;
};

const Setting<Path> secretKeyFile{this, "", "secret-key",
"Path to the secret key used to sign the binary cache."};
struct BinaryCacheStoreConfig :
virtual Store::Config,
BinaryCacheStoreConfigT<config::JustValue>
{
struct Descriptions :
virtual Store::Config::Descriptions,
BinaryCacheStoreConfigT<config::SettingInfo>
{
Descriptions();
};

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`."};
static const Descriptions descriptions;

const Setting<bool> parallelCompression{this, false, "parallel-compression",
"Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`."};
static BinaryCacheStoreConfigT<config::JustValue> defaults;

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 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 BinaryCacheStoreConfig,
virtual Store,
virtual LogStore
{
using Config = BinaryCacheStoreConfig;

private:
std::unique_ptr<Signer> signer;
Expand All @@ -64,7 +62,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
1 change: 1 addition & 0 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
50 changes: 48 additions & 2 deletions src/libstore/common-ssh-store-config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,46 @@

#include "common-ssh-store-config.hh"
#include "ssh.hh"
#include "config-parse-impl.hh"

namespace nix {

CommonSSHStoreConfig::Descriptions::Descriptions()
: Store::Config::Descriptions{Store::Config::descriptions}
, CommonSSHStoreConfigT<config::SettingInfo>{
.sshKey{
.name = "ssh-key",
.description = "Path to the SSH private key used to authenticate to the remote machine.",
},
.sshPublicHostKey{
.name = "base64-ssh-public-host-key",
.description = "The public host key of the remote machine.",
},
.compress{
.name = "compress",
.description = "Whether to enable SSH compression.",
},
.remoteStore{
.name = "remote-store",
.description = R"(
[Store URL](@docroot@/store/types/index.md#store-url-format)
to be used on the remote machine. The default is `auto`
(i.e. use the Nix daemon or `/nix/store` directly).
)",
},
}
{
}

const CommonSSHStoreConfig::Descriptions CommonSSHStoreConfig::descriptions{};

decltype(CommonSSHStoreConfig::defaults) CommonSSHStoreConfig::defaults = {
.sshKey{""},
.sshPublicHostKey{""},
.compress{false},
.remoteStore{""},
};

static std::string extractConnStr(std::string_view scheme, std::string_view _connStr)
{
if (_connStr.empty())
Expand All @@ -22,8 +59,17 @@ static std::string extractConnStr(std::string_view scheme, std::string_view _con
return connStr;
}

CommonSSHStoreConfig::CommonSSHStoreConfig(std::string_view scheme, std::string_view host, const Params & params)
: StoreConfig(params)
CommonSSHStoreConfig::CommonSSHStoreConfig(
std::string_view scheme,
std::string_view host,
const StoreReference::Params & params)
: Store::Config(params)
, CommonSSHStoreConfigT<config::JustValue>{
CONFIG_ROW(sshKey),
CONFIG_ROW(sshPublicHostKey),
CONFIG_ROW(compress),
CONFIG_ROW(remoteStore),
}
, host(extractConnStr(scheme, host))
{
}
Expand Down
43 changes: 27 additions & 16 deletions src/libstore/common-ssh-store-config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,38 @@ namespace nix {

class SSHMaster;

struct CommonSSHStoreConfig : virtual StoreConfig
template<template<typename> class F>
struct CommonSSHStoreConfigT
{
using StoreConfig::StoreConfig;

CommonSSHStoreConfig(std::string_view scheme, std::string_view host, const Params & params);
const F<Path> sshKey;
const F<std::string> sshPublicHostKey;
const F<bool> compress;
const F<std::string> remoteStore;
};

const Setting<Path> sshKey{this, "", "ssh-key",
"Path to the SSH private key used to authenticate to the remote machine."};
struct CommonSSHStoreConfig :
virtual Store::Config,
CommonSSHStoreConfigT<config::JustValue>
{
struct Descriptions :
virtual Store::Config::Descriptions,
CommonSSHStoreConfigT<config::SettingInfo>
{
Descriptions();
};

const Setting<std::string> sshPublicHostKey{this, "", "base64-ssh-public-host-key",
"The public host key of the remote machine."};
static const Descriptions descriptions;

const Setting<bool> compress{this, false, "compress",
"Whether to enable SSH compression."};
static CommonSSHStoreConfigT<config::JustValue> defaults;

const Setting<std::string> remoteStore{this, "", "remote-store",
R"(
[Store URL](@docroot@/store/types/index.md#store-url-format)
to be used on the remote machine. The default is `auto`
(i.e. use the Nix daemon or `/nix/store` directly).
)"};
/**
* @param scheme Note this isn't stored by this mix-in class, but
* just used for better error messages.
*/
CommonSSHStoreConfig(
std::string_view scheme,
std::string_view host,
const StoreReference::Params & params);

/**
* The `parseURL` function supports both IPv6 URIs as defined in
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct DummyStoreConfig : virtual StoreConfig {
return {"dummy"};
}

std::shared_ptr<Store> openStore() override;
ref<Store> openStore() const override;
};


Expand Down Expand Up @@ -100,9 +100,9 @@ struct DummyStore : public virtual DummyStoreConfig, public virtual Store
{ unsupported("getFSAccessor"); }
};

std::shared_ptr<Store> DummyStore::Config::openStore()
ref<Store> DummyStore::Config::openStore() const
{
return std::make_shared<DummyStore>(*this);
return make_ref<DummyStore>(*this);
}

static RegisterStoreImplementation<DummyStore> regDummyStore;
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/filetransfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ struct curlFileTransfer : public FileTransfer
}

#if ENABLE_S3
std::tuple<std::string, std::string, Store::Params> parseS3Uri(std::string uri)
std::tuple<std::string, std::string, StoreReference::Params> parseS3Uri(std::string uri)
{
auto [path, params] = splitUriAndParams(uri);

Expand Down
Loading

0 comments on commit 9e6d1eb

Please sign in to comment.