Skip to content

Commit

Permalink
More progress converting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 18, 2024
1 parent 9b30c20 commit bb7bf73
Show file tree
Hide file tree
Showing 19 changed files with 251 additions and 104 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
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
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
49 changes: 47 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,45 @@

#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 +58,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
10 changes: 5 additions & 5 deletions src/libstore/local-fs-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ LocalFSStore::Config::Descriptions::Descriptions()

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

LocalFSStoreConfigT<config::JustValue> LocalFSStoreConfig::defaults(
LocalFSStoreConfigT<config::JustValue> LocalFSStore::Config::defaults(
const Store::Config & storeConfig,
const std::optional<Path> rootDir)
{
return {
.rootDir = {.value = std::nullopt },
.stateDir = {.value = rootDir ? *rootDir + "/nix/var/nix" : settings.nixStateDir },
.logDir = {.value = rootDir ? *rootDir + "/nix/var/log/nix" : settings.nixLogDir },
.realStoreDir = {.value = rootDir ? *rootDir + "/nix/store" : storeConfig.storeDir },
.rootDir = {std::nullopt},
.stateDir = {rootDir ? *rootDir + "/nix/var/nix" : settings.nixStateDir},
.logDir = {rootDir ? *rootDir + "/nix/var/log/nix" : settings.nixLogDir},
.realStoreDir = {rootDir ? *rootDir + "/nix/store" : storeConfig.storeDir},
};
}

Expand Down
3 changes: 0 additions & 3 deletions src/libstore/local-fs-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ template<template<typename> class F>
struct LocalFSStoreConfigT
{
const F<std::optional<Path>> rootDir;

const F<Path> stateDir;

const F<Path> logDir;

const F<Path> realStoreDir;
};

Expand Down
4 changes: 2 additions & 2 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ LocalStore::Config::Descriptions::Descriptions()
const LocalStore::Config::Descriptions LocalStore::Config::descriptions{};

decltype(LocalStore::Config::defaults) LocalStore::Config::defaults = {
.requireSigs = {.value = settings.requireSigs },
.readOnly = {.value = false },
.requireSigs = {settings.requireSigs},
.readOnly = {false},
};

LocalStore::Config::LocalStoreConfig(
Expand Down
1 change: 0 additions & 1 deletion src/libstore/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ template<template<typename> class F>
struct LocalStoreConfigT
{
const F<bool> requireSigs;

const F<bool> readOnly;
};

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/remote-fs-accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RemoteFSAccessor : public SourceAccessor

std::pair<ref<SourceAccessor>, CanonPath> fetch(const CanonPath & path);

friend class BinaryCacheStore;
friend struct BinaryCacheStore;

Path makeCacheFile(std::string_view hashPart, const std::string & ext);

Expand Down
Loading

0 comments on commit bb7bf73

Please sign in to comment.