Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion src/libexpr/eval-profiler-settings.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "nix/expr/eval-profiler-settings.hh"
#include "nix/util/configuration.hh"
#include "nix/util/logging.hh" /* Needs to be included before config-impl.hh */
#include "nix/util/config-impl.hh"
#include "nix/util/abstract-setting-to-json.hh"

Expand Down
14 changes: 10 additions & 4 deletions src/libstore-tests/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ namespace nix {

TEST(LegacySSHStore, constructConfig)
{
LegacySSHStoreConfig config{
initLibStore(/*loadConfig=*/false);

auto config = make_ref<LegacySSHStoreConfig>(
"ssh",
"localhost",
"me@localhost:2222",
StoreConfig::Params{
{
"remote-program",
// TODO #11106, no more split on space
"foo bar",
},
}};
});

EXPECT_EQ(
config.remoteProgram.get(),
config->remoteProgram.get(),
(Strings{
"foo",
"bar",
}));

auto store = config->openStore();
EXPECT_EQ(store->getUri(), "ssh://me@localhost:2222?remote-program=foo%20bar");
}
} // namespace nix
8 changes: 2 additions & 6 deletions src/libstore-tests/local-overlay-store.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// FIXME: Odd failures for templates that are causing the PR to break
// for now with discussion with @Ericson2314 to comment out.
#if 0
# include <gtest/gtest.h>
#include <gtest/gtest.h>

# include "nix/store/local-overlay-store.hh"
#include "nix/store/local-overlay-store.hh"

namespace nix {

Expand Down Expand Up @@ -31,4 +28,3 @@ TEST(LocalOverlayStore, constructConfig_rootPath)
}

} // namespace nix
#endif
14 changes: 5 additions & 9 deletions src/libstore-tests/local-store.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// FIXME: Odd failures for templates that are causing the PR to break
// for now with discussion with @Ericson2314 to comment out.
#if 0
# include <gtest/gtest.h>
#include <gtest/gtest.h>

# include "nix/store/local-store.hh"
#include "nix/store/local-store.hh"

// Needed for template specialisations. This is not good! When we
// overhaul how store configs work, this should be fixed.
# include "nix/util/args.hh"
# include "nix/util/config-impl.hh"
# include "nix/util/abstract-setting-to-json.hh"
#include "nix/util/args.hh"
#include "nix/util/config-impl.hh"
#include "nix/util/abstract-setting-to-json.hh"

namespace nix {

Expand Down Expand Up @@ -37,4 +34,3 @@ TEST(LocalStore, constructConfig_rootPath)
}

} // namespace nix
#endif
9 changes: 8 additions & 1 deletion src/libstore-tests/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "nix/store/tests/nix_api_store.hh"
#include "nix/util/tests/string_callback.hh"
#include "nix/util/url.hh"

#include "store-tests-config.hh"

Expand All @@ -23,7 +24,13 @@ TEST_F(nix_api_store_test, nix_store_get_uri)
std::string str;
auto ret = nix_store_get_uri(ctx, store, OBSERVE_STRING(str));
ASSERT_EQ(NIX_OK, ret);
ASSERT_STREQ("local", str.c_str());
auto expectedStoreURI = "local?"
+ nix::encodeQuery({
{"log", nixLogDir},
{"state", nixStateDir},
{"store", nixStoreDir},
});
ASSERT_EQ(expectedStoreURI, str);
}

TEST_F(nix_api_util_context, nix_store_get_storedir_default)
Expand Down
31 changes: 18 additions & 13 deletions src/libstore-tests/ssh-store.cc
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
// FIXME: Odd failures for templates that are causing the PR to break
// for now with discussion with @Ericson2314 to comment out.
#if 0
# include <gtest/gtest.h>
#include <gtest/gtest.h>

# include "nix/store/ssh-store.hh"
#include "nix/store/ssh-store.hh"
#include "nix/util/config-impl.hh"
#include "nix/util/abstract-setting-to-json.hh"

namespace nix {

TEST(SSHStore, constructConfig)
{
SSHStoreConfig config{
"ssh",
"localhost",
initLibStore(/*loadConfig=*/false);

auto config = make_ref<SSHStoreConfig>(
"ssh-ng",
"me@localhost:2222",
StoreConfig::Params{
{
"remote-program",
// TODO #11106, no more split on space
"foo bar",
},
},
};
});

EXPECT_EQ(
config.remoteProgram.get(),
config->remoteProgram.get(),
(Strings{
"foo",
"bar",
}));

auto store = config->openStore();
EXPECT_EQ(store->getUri(), "ssh-ng://me@localhost:2222?remote-program=foo%20bar");
config->resetOverridden();
store = config->openStore();
EXPECT_EQ(store->getUri(), "ssh-ng://me@localhost:2222");
}

TEST(MountedSSHStore, constructConfig)
Expand All @@ -51,5 +57,4 @@ TEST(MountedSSHStore, constructConfig)
}));
}

}
#endif
} // namespace nix
8 changes: 2 additions & 6 deletions src/libstore-tests/uds-remote-store.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// FIXME: Odd failures for templates that are causing the PR to break
// for now with discussion with @Ericson2314 to comment out.
#if 0
# include <gtest/gtest.h>
#include <gtest/gtest.h>

# include "nix/store/uds-remote-store.hh"
#include "nix/store/uds-remote-store.hh"

namespace nix {

Expand All @@ -20,4 +17,3 @@ TEST(UDSRemoteStore, constructConfigWrongScheme)
}

} // namespace nix
#endif
5 changes: 5 additions & 0 deletions src/libstore/include/nix/store/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace nix {

typedef enum { smEnabled, smRelaxed, smDisabled } SandboxMode;

template<>
SandboxMode BaseSetting<SandboxMode>::parse(const std::string & str) const;
template<>
std::string BaseSetting<SandboxMode>::to_string() const;

struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
{
MaxBuildJobsSetting(
Expand Down
13 changes: 13 additions & 0 deletions src/libstore/include/nix/store/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ struct StoreConfig : public StoreDirConfig
return "";
}

/**
* Get overridden store reference query parameters.
*/
StringMap getQueryParams() const
{
auto queryParams = std::map<std::string, AbstractConfig::SettingInfo>{};
getSettings(queryParams, /*overriddenOnly=*/true);
StringMap res;
for (const auto & [name, info] : queryParams)
res.insert({name, info.value});
return res;
}

/**
* An experimental feature this type store is gated, if it is to be
* experimental.
Expand Down
4 changes: 3 additions & 1 deletion src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()

std::string LegacySSHStore::getUri()
{
return *Config::uriSchemes().begin() + "://" + config->authority.to_string();
return ParsedURL{
.scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()}
.to_string();
}

std::map<StorePath, UnkeyedValidPathInfo> LegacySSHStore::queryPathInfosUncached(const StorePathSet & paths)
Expand Down
9 changes: 8 additions & 1 deletion src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "nix/store/posix-fs-canonicalise.hh"
#include "nix/util/posix-source-accessor.hh"
#include "nix/store/keys.hh"
#include "nix/util/url.hh"
#include "nix/util/users.hh"
#include "nix/store/store-open.hh"
#include "nix/store/store-registration.hh"
Expand Down Expand Up @@ -440,7 +441,13 @@ LocalStore::~LocalStore()

std::string LocalStore::getUri()
{
return "local";
std::ostringstream oss;
oss << *config->uriSchemes().begin();
auto queryParams = config->getQueryParams();
if (!queryParams.empty())
oss << "?";
oss << encodeQuery(queryParams);
return std::move(oss).str();
}

int LocalStore::getSchema()
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ struct SSHStore : virtual RemoteStore

std::string getUri() override
{
return *Config::uriSchemes().begin() + "://" + host;
return ParsedURL{
.scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()}
.to_string();
}

// FIXME extend daemon protocol, move implementation to RemoteStore
Expand All @@ -66,8 +68,6 @@ struct SSHStore : virtual RemoteStore

ref<RemoteStore::Connection> openConnection() override;

std::string host;

std::vector<std::string> extraRemoteProgramArgs;

SSHMaster master;
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/config-global.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool GlobalConfig::set(const std::string & name, const std::string & value)
return false;
}

void GlobalConfig::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly)
void GlobalConfig::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly) const
{
for (auto & config : configRegistrations())
config->getSettings(res, overriddenOnly);
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void AbstractConfig::reapplyUnknownSettings()
set(s.first, s.second);
}

void Config::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly)
void Config::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly) const
{
for (const auto & opt : _settings)
if (!opt.second.isAlias && (!overriddenOnly || opt.second.setting->overridden)
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/include/nix/util/config-global.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct GlobalConfig : public AbstractConfig

bool set(const std::string & name, const std::string & value) override;

void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) override;
void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) const override;

void resetOverridden() override;

Expand Down
2 changes: 2 additions & 0 deletions src/libutil/include/nix/util/config-impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
* instantiation.
*/

#include "nix/util/util.hh"
#include "nix/util/configuration.hh"
#include "nix/util/args.hh"
#include "nix/util/logging.hh"

namespace nix {

Expand Down
4 changes: 2 additions & 2 deletions src/libutil/include/nix/util/configuration.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public:
* - res: map to store settings in
* - overriddenOnly: when set to true only overridden settings will be added to `res`
*/
virtual void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) = 0;
virtual void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) const = 0;

/**
* Parses the configuration in `contents` and applies it
Expand Down Expand Up @@ -160,7 +160,7 @@ public:

void addSetting(AbstractSetting * setting);

void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) override;
void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) const override;

void resetOverridden() override;

Expand Down
Loading