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

Refactor unix domain socket store config #11109

Merged
merged 27 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 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
1e25c22
Revert "Declare some template specializations in the header"
Ericson2314 Jul 16, 2024
7b135d5
Comment out tests
fzakaria 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
8886d94
Comment out another test
Ericson2314 Jul 17, 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
20 changes: 12 additions & 8 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 @@ -19,18 +26,15 @@ struct DummyStoreConfig : virtual StoreConfig {
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 Down
50 changes: 26 additions & 24 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 Down
21 changes: 21 additions & 0 deletions src/libstore/http-binary-cache-store.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#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";
}

std::string doc() override;
};

}
36 changes: 17 additions & 19 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 Down
21 changes: 21 additions & 0 deletions src/libstore/local-binary-cache-store.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "binary-cache-store.hh"

namespace nix {

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

LocalBinaryCacheStoreConfig(std::string_view scheme, PathView binaryCacheDir, const Params & params);

Path binaryCacheDir;

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

std::string doc() override;
};

}
14 changes: 14 additions & 0 deletions src/libstore/local-fs-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

namespace nix {

LocalFSStoreConfig::LocalFSStoreConfig(PathView rootDir, const Params & params)
: StoreConfig(params)
// Default `?root` from `rootDir` if non set
// FIXME don't duplicate description once we don't have root setting
, rootDir{
this,
!rootDir.empty() && params.count("root") == 0
? (std::optional<Path>{rootDir})
: std::nullopt,
"root",
"Directory prefixed to all other paths."}
{
}

LocalFSStore::LocalFSStore(const Params & params)
: Store(params)
{
Expand Down
9 changes: 9 additions & 0 deletions src/libstore/local-fs-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ struct LocalFSStoreConfig : virtual StoreConfig
{
using StoreConfig::StoreConfig;

/**
* Used to override the `root` settings. Can't be done via modifying
* `params` reliably because this parameter is unused except for
* passing to base class constructors.
*
* @todo Make this less error-prone with new store settings system.
*/
LocalFSStoreConfig(PathView path, const Params & params);

const OptionalPathSetting rootDir{this, std::nullopt,
"root",
"Directory prefixed to all other paths."};
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/local-overlay-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Path LocalOverlayStoreConfig::toUpperPath(const StorePath & path) {
return upperLayer + "/" + path.to_string();
}

LocalOverlayStore::LocalOverlayStore(const Params & params)
LocalOverlayStore::LocalOverlayStore(std::string_view scheme, PathView path, const Params & params)
: StoreConfig(params)
, LocalFSStoreConfig(params)
, LocalFSStoreConfig(path, params)
, LocalStoreConfig(params)
, LocalOverlayStoreConfig(params)
, LocalOverlayStoreConfig(scheme, path, params)
, Store(params)
, LocalFSStore(params)
, LocalStore(params)
Expand Down
21 changes: 12 additions & 9 deletions src/libstore/local-overlay-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ namespace nix {
struct LocalOverlayStoreConfig : virtual LocalStoreConfig
{
LocalOverlayStoreConfig(const StringMap & params)
: StoreConfig(params)
, LocalFSStoreConfig(params)
, LocalStoreConfig(params)
: LocalOverlayStoreConfig("local-overlay", "", params)
{ }

LocalOverlayStoreConfig(std::string_view scheme, PathView path, const Params & params)
: StoreConfig(params)
, LocalFSStoreConfig(path, params)
, LocalStoreConfig(scheme, path, params)
{
}

const Setting<std::string> lowerStoreUri{(StoreConfig*) this, "", "lower-store",
R"(
[Store URL](@docroot@/command-ref/new-cli/nix3-help-stores.md#store-url-format)
Expand Down Expand Up @@ -90,15 +95,13 @@ class LocalOverlayStore : public virtual LocalOverlayStoreConfig, public virtual
ref<LocalFSStore> lowerStore;

public:
LocalOverlayStore(const Params & params);

LocalOverlayStore(std::string_view scheme, PathView path, const Params & params)
: LocalOverlayStore(params)
LocalOverlayStore(const Params & params)
: LocalOverlayStore("local-overlay", "", params)
{
if (!path.empty())
throw UsageError("local-overlay:// store url doesn't support path part, only scheme and query params");
}

LocalOverlayStore(std::string_view scheme, PathView path, const Params & params);

static std::set<std::string> uriSchemes()
{
return { "local-overlay" };
Expand Down
33 changes: 17 additions & 16 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@

namespace nix {

LocalStoreConfig::LocalStoreConfig(
std::string_view scheme,
std::string_view authority,
const Params & params)
: StoreConfig(params)
, LocalFSStoreConfig(authority, params)
{
}

std::string LocalStoreConfig::doc()
{
return
Expand Down Expand Up @@ -183,10 +192,13 @@ void migrateCASchema(SQLite& db, Path schemaPath, AutoCloseFD& lockFd)
}
}

LocalStore::LocalStore(const Params & params)
LocalStore::LocalStore(
std::string_view scheme,
PathView path,
const Params & params)
: StoreConfig(params)
, LocalFSStoreConfig(params)
, LocalStoreConfig(params)
, LocalFSStoreConfig(path, params)
, LocalStoreConfig(scheme, path, params)
, Store(params)
, LocalFSStore(params)
, dbDir(stateDir + "/db")
Expand Down Expand Up @@ -465,19 +477,8 @@ LocalStore::LocalStore(const Params & params)
}


LocalStore::LocalStore(
std::string_view scheme,
PathView path,
const Params & _params)
: LocalStore([&]{
// Default `?root` from `path` if non set
if (!path.empty() && _params.count("root") == 0) {
auto params = _params;
params.insert_or_assign("root", std::string { path });
return params;
}
return _params;
}())
LocalStore::LocalStore(const Params & params)
: LocalStore("local", "", params)
{
}

Expand Down
5 changes: 5 additions & 0 deletions src/libstore/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ struct LocalStoreConfig : virtual LocalFSStoreConfig
{
using LocalFSStoreConfig::LocalFSStoreConfig;

LocalStoreConfig(
std::string_view scheme,
std::string_view authority,
const Params & params);

Setting<bool> requireSigs{this,
settings.requireSigs,
"require-sigs",
Expand Down
2 changes: 2 additions & 0 deletions src/libstore/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,12 @@ headers = [config_h] + files(
'filetransfer.hh',
'gc-store.hh',
'globals.hh',
'http-binary-cache-store.hh',
'indirect-root-store.hh',
'keys.hh',
'legacy-ssh-store.hh',
'length-prefixed-protocol-helper.hh',
'local-binary-cache-store.hh',
'local-fs-store.hh',
'local-overlay-store.hh',
'local-store.hh',
Expand Down
Loading
Loading