Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 18, 2024
1 parent bb7bf73 commit ca1e895
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 152 deletions.
43 changes: 22 additions & 21 deletions src/libstore/common-ssh-store-config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@ 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).
.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{};

Expand Down
4 changes: 2 additions & 2 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;
std::shared_ptr<Store> openStore() const override;
};


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

std::shared_ptr<Store> DummyStore::Config::openStore()
std::shared_ptr<Store> DummyStore::Config::openStore() const
{
return std::make_shared<DummyStore>(*this);
}
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
32 changes: 18 additions & 14 deletions src/libstore/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "globals.hh"
#include "nar-info-disk-cache.hh"
#include "callback.hh"
#include "store-registration.hh"

namespace nix {

Expand All @@ -12,7 +13,7 @@ MakeError(UploadToHTTP, Error);
HttpBinaryCacheStoreConfig::HttpBinaryCacheStoreConfig(
std::string_view scheme,
std::string_view _cacheUri,
const Params & params)
const StoreReference::Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, cacheUri(
Expand All @@ -35,10 +36,10 @@ std::string HttpBinaryCacheStoreConfig::doc()
}


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

struct State
{
bool enabled = true;
Expand All @@ -49,15 +50,14 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v

public:

HttpBinaryCacheStore(
std::string_view scheme,
PathView cacheUri,
const Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, HttpBinaryCacheStoreConfig(scheme, cacheUri, params)
, Store(params)
, BinaryCacheStore(params)
using Config = HttpBinaryCacheStoreConfig;

HttpBinaryCacheStore(const Config & config)
: Store::Config{config}
, BinaryCacheStore::Config{config}
, HttpBinaryCacheStore::Config{config}
, Store{static_cast<const Store::Config &>(*this)}
, BinaryCacheStore{static_cast<const BinaryCacheStore::Config &>(*this)}
{
diskCache = getNarInfoDiskCache();
}
Expand Down Expand Up @@ -207,6 +207,10 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v
}
};

static RegisterStoreImplementation<HttpBinaryCacheStore, HttpBinaryCacheStoreConfig> regHttpBinaryCacheStore;
std::shared_ptr<Store> HttpBinaryCacheStore::Config::openStore() const {
return std::make_shared<HttpBinaryCacheStore>(*this);
}

static RegisterStoreImplementation<HttpBinaryCacheStore> regHttpBinaryCacheStore;

}
7 changes: 4 additions & 3 deletions src/libstore/http-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ namespace nix {

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

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

Path cacheUri;

Expand All @@ -25,6 +24,8 @@ struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
}

std::string doc() override;

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

}
30 changes: 14 additions & 16 deletions src/libstore/local-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "globals.hh"
#include "nar-info-disk-cache.hh"
#include "signals.hh"
#include "store-registration.hh"

#include <atomic>

Expand All @@ -10,7 +11,7 @@ namespace nix {
LocalBinaryCacheStoreConfig::LocalBinaryCacheStoreConfig(
std::string_view scheme,
PathView binaryCacheDir,
const Params & params)
const StoreReference::Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, binaryCacheDir(binaryCacheDir)
Expand All @@ -26,21 +27,18 @@ std::string LocalBinaryCacheStoreConfig::doc()
}


struct LocalBinaryCacheStore : virtual LocalBinaryCacheStoreConfig, virtual BinaryCacheStore
struct LocalBinaryCacheStore :
virtual LocalBinaryCacheStoreConfig,
virtual BinaryCacheStore
{
/**
* @param binaryCacheDir `file://` is a short-hand for `file:///`
* for now.
*/
LocalBinaryCacheStore(
std::string_view scheme,
PathView binaryCacheDir,
const Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, LocalBinaryCacheStoreConfig(scheme, binaryCacheDir, params)
, Store(params)
, BinaryCacheStore(params)
using Config = LocalBinaryCacheStoreConfig;

LocalBinaryCacheStore(const Config & config)
: Store::Config{config}
, BinaryCacheStore::Config{config}
, LocalBinaryCacheStore::Config{config}
, Store{static_cast<const Store::Config &>(*this)}
, BinaryCacheStore{static_cast<const BinaryCacheStore::Config &>(*this)}
{
}

Expand Down Expand Up @@ -127,6 +125,6 @@ std::set<std::string> LocalBinaryCacheStoreConfig::uriSchemes()
return {"file"};
}

static RegisterStoreImplementation<LocalBinaryCacheStore, LocalBinaryCacheStoreConfig> regLocalBinaryCacheStore;
static RegisterStoreImplementation<LocalBinaryCacheStore> regLocalBinaryCacheStore;

}
11 changes: 8 additions & 3 deletions src/libstore/local-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ namespace nix {

struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
{
using BinaryCacheStoreConfig::BinaryCacheStoreConfig;

LocalBinaryCacheStoreConfig(std::string_view scheme, PathView binaryCacheDir, const Params & params);
/**
* @param binaryCacheDir `file://` is a short-hand for `file:///`
* for now.
*/
LocalBinaryCacheStoreConfig(
std::string_view scheme, PathView binaryCacheDir, const StoreReference::Params & params);

Path binaryCacheDir;

Expand All @@ -18,6 +21,8 @@ struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
static std::set<std::string> uriSchemes();

std::string doc() override;

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

}
2 changes: 1 addition & 1 deletion src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ std::string LocalStoreConfig::doc()
;
}

std::shared_ptr<Store> LocalStore::Config::openStore()
std::shared_ptr<Store> LocalStore::Config::openStore() const
{
return std::make_shared<LocalStore>(*this);
}
Expand Down
5 changes: 1 addition & 4 deletions src/libstore/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ struct LocalStoreConfig :

static const Descriptions descriptions;

/**
* The other defaults depend on the choice of `storeDir` and `rootDir`
*/
static LocalStoreConfigT<config::JustValue> defaults;

LocalStoreConfig(const StoreReference::Params &);
Expand All @@ -75,7 +72,7 @@ struct LocalStoreConfig :

std::string doc() override;

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

class LocalStore :
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/machines.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "machines.hh"
#include "globals.hh"
#include "store-api.hh"
#include "store-open.hh"

#include <algorithm>

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "derivations.hh"
#include "parsed-derivations.hh"
#include "globals.hh"
#include "store-api.hh"
#include "store-open.hh"
#include "thread-pool.hh"
#include "realisation.hh"
#include "topo-sort.hh"
Expand Down
76 changes: 69 additions & 7 deletions src/libstore/s3-binary-cache-store.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#if ENABLE_S3

#include <assert.h>

#include "s3.hh"
#include "s3-binary-cache-store.hh"
#include "nar-info.hh"
Expand Down Expand Up @@ -187,6 +185,75 @@ S3Helper::FileTransferResult S3Helper::getObject(
return res;
}

const Setting<std::string> profile{
this,
"",
"profile",
R"(
The name of the AWS configuration profile to use. By default
Nix will use the `default` profile.
)"};

const Setting<std::string> region{
this,
Aws::Region::US_EAST_1,
"region",
R"(
The region of the S3 bucket. If your bucket is not in
`us–east-1`, you should always explicitly specify the region
parameter.
)"};

const Setting<std::string> scheme{
this,
"",
"scheme",
R"(
The scheme used for S3 requests, `https` (default) or `http`. This
option allows you to disable HTTPS for binary caches which don't
support it.
> **Note**
>
> HTTPS should be used if the cache might contain sensitive
> information.
)"};

const Setting<std::string> endpoint{
this,
"",
"endpoint",
R"(
The URL of the endpoint of an S3-compatible service such as MinIO.
Do not specify this setting if you're using Amazon S3.
> **Note**
>
> This endpoint must support HTTPS and will use path-based
> addressing instead of virtual host based addressing.
)"};

const Setting<std::string> narinfoCompression{
this, "", "narinfo-compression", "Compression method for `.narinfo` files."};

const Setting<std::string> lsCompression{this, "", "ls-compression", "Compression method for `.ls` files."};

const Setting<std::string> logCompression{
this,
"",
"log-compression",
R"(
Compression method for `log/*` files. It is recommended to
use a compression method supported by most web browsers
(e.g. `brotli`).
)"};

const Setting<bool> multipartUpload{this, false, "multipart-upload", "Whether to use multi-part uploads."};

const Setting<uint64_t> bufferSize{
this, 5 * 1024 * 1024, "buffer-size", "Size (in bytes) of each part in multi-part uploads."};


S3BinaryCacheStore::S3BinaryCacheStore(const Params & params)
: BinaryCacheStoreConfig(params)
, BinaryCacheStore(params)
Expand All @@ -201,11 +268,6 @@ S3BinaryCacheStoreConfig::S3BinaryCacheStoreConfig(
, BinaryCacheStoreConfig(params)
, bucketName(bucketName)
{
// Don't want to use use AWS SDK in header, so we check the default
// here. TODO do this better after we overhaul the store settings
// system.
assert(std::string{defaultRegion} == std::string{Aws::Region::US_EAST_1});

if (bucketName.empty())
throw UsageError("`%s` store requires a bucket name in its Store URI", uriScheme);
}
Expand Down
Loading

0 comments on commit ca1e895

Please sign in to comment.