Skip to content

New store settings system #11139

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
46 changes: 38 additions & 8 deletions doc/manual/generate-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,32 @@ in
prefix,
inlineHTML ? true,
}:
settingsInfo:

let

showSetting =
prefix: setting:
{
description,
documentDefault,
defaultValue,
aliases,
value,

experimentalFeature,

# Whether we document the default, because it is machine agostic,
# or don't because because it is machine-specific.
documentDefault ? true,

# The default value is JSON for new-style config, rather than then
# a string or boolean, for old-style config.
isJson ? false,

defaultValue ? null,

subSettings ? null,

aliases ? [ ],

# The current value for this setting. Purposefully unused.
value ? null,
}:
let
result = squash ''
Expand All @@ -50,7 +63,7 @@ let

${description}

**Default:** ${showDefault documentDefault defaultValue}
${showDefaultOrSubSettings}

${showAliases aliases}
'';
Expand All @@ -72,9 +85,24 @@ let
> ```
'';

showDefaultOrSubSettings =
if !isAttrs subSettings then
# No subsettings, instead single setting. Show the default value.
''
**Default:** ${showDefault}
''
else
# Indent the nested sub-settings, and append the outer setting name onto the prefix
indent " " ''
**Nullable sub-settings**: ${if subSettings.nullable then "true" else "false"}
${builtins.trace prefix (showSettings "${prefix}-${setting}" subSettings.map)}
'';

showDefault =
documentDefault: defaultValue:
if documentDefault then
if isJson then
"`${builtins.toJSON defaultValue}`"
else
# a StringMap value type is specified as a string, but
# this shows the value type. The empty stringmap is `null` in
# JSON, but that converts to `{ }` here.
Expand All @@ -95,5 +123,7 @@ let
in
result;

showSettings =
prefix: settingsInfo: concatStrings (attrValues (mapAttrs (showSetting prefix) settingsInfo));
in
concatStrings (attrValues (mapAttrs (showSetting prefix) settingsInfo))
showSettings prefix
2 changes: 1 addition & 1 deletion src/libstore-c/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
if (!params)
return new Store{nix::openStore(uri_str)};

nix::Store::Config::Params params_map;
nix::StoreReference::Params params_map;
for (size_t i = 0; params[i] != nullptr; i++) {
params_map[params[i][0]] = params[i][1];
}
Expand Down
3 changes: 3 additions & 0 deletions src/libstore-tests/data/store-reference/auto.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"scheme": "auto"
}
4 changes: 4 additions & 0 deletions src/libstore-tests/data/store-reference/auto_param.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": "/foo/bar/baz",
"scheme": "auto"
}
5 changes: 5 additions & 0 deletions src/libstore-tests/data/store-reference/local_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"authority": "",
"root": "/foo/bar/baz",
"scheme": "local"
}
5 changes: 5 additions & 0 deletions src/libstore-tests/data/store-reference/local_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"authority": "/foo/bar/baz",
"scheme": "local",
"trusted": true
}
4 changes: 4 additions & 0 deletions src/libstore-tests/data/store-reference/ssh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"authority": "localhost",
"scheme": "ssh"
}
6 changes: 6 additions & 0 deletions src/libstore-tests/data/store-reference/unix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"authority": "",
"max-connections": 7,
"scheme": "unix",
"trusted": true
}
20 changes: 20 additions & 0 deletions src/libstore-tests/dummy-store.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <gtest/gtest.h>

#include "nix/store/dummy-store.hh"
#include "nix/store/globals.hh"

namespace nix {

TEST(DummyStore, constructConfig)
{
DummyStoreConfig config{"dummy", "", {}};

EXPECT_EQ(config.storeDir, settings.nixStore);
}

TEST(DummyStore, constructConfigNoAuthority)
{
EXPECT_THROW(DummyStoreConfig("dummy", "not-allowed", {}), UsageError);
}

} // namespace nix
8 changes: 5 additions & 3 deletions src/libstore-tests/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ TEST(LegacySSHStore, constructConfig)
LegacySSHStoreConfig config{
"ssh",
"localhost",
StoreConfig::Params{
StoreReference::Params{
{
"remote-program",
// TODO #11106, no more split on space
"foo bar",
{
"foo",
"bar",
},
},
}};
EXPECT_EQ(
Expand Down
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: 2 additions & 12 deletions src/libstore-tests/local-store.cc
Original file line number Diff line number Diff line change
@@ -1,15 +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-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/store/local-store.hh"

namespace nix {

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

} // namespace nix
#endif
1 change: 1 addition & 0 deletions src/libstore-tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ sources = files(
'derivation-advanced-attrs.cc',
'derivation.cc',
'derived-path.cc',
'dummy-store.cc',
'downstream-placeholder.cc',
'http-binary-cache-store.cc',
'legacy-ssh-store.cc',
Expand Down
2 changes: 1 addition & 1 deletion src/libstore-tests/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TEST_F(nix_api_util_context, nix_store_open_dummy)
nix_libstore_init(ctx);
Store * store = nix_store_open(ctx, "dummy://", nullptr);
ASSERT_EQ(NIX_OK, ctx->last_err_code);
ASSERT_STREQ("dummy", store->ptr->getUri().c_str());
ASSERT_STREQ("dummy://", store->ptr->getUri().c_str());

std::string str;
nix_store_get_version(ctx, store, OBSERVE_STRING(str));
Expand Down
80 changes: 65 additions & 15 deletions src/libstore-tests/ssh-store.cc
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// 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"

namespace nix {

TEST(SSHStore, constructConfig)
{
SSHStoreConfig config{
"ssh",
"ssh-ng",
"localhost",
StoreConfig::Params{
StoreReference::Params{
{
"remote-program",
// TODO #11106, no more split on space
"foo bar",
{
"foo",
"bar",
},
},
},
};
Expand All @@ -31,16 +30,64 @@ TEST(SSHStore, constructConfig)

TEST(MountedSSHStore, constructConfig)
{
MountedSSHStoreConfig config{
"mounted-ssh",
ExperimentalFeatureSettings mockXpSettings;
mockXpSettings.set("experimental-features", "mounted-ssh-store");

SSHStoreConfig config{
"ssh-ng",
"localhost",
StoreReference::Params{
{
"remote-program",
{
"foo",
"bar",
},
},
{
"mounted",
nlohmann::json::object_t{},
},
},
mockXpSettings,
};

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

ASSERT_TRUE(config.mounted);

EXPECT_EQ(config.mounted->realStoreDir, "/nix/store");
}

TEST(MountedSSHStore, constructConfigWithFunnyRealStoreDir)
{
ExperimentalFeatureSettings mockXpSettings;
mockXpSettings.set("experimental-features", "mounted-ssh-store");

SSHStoreConfig config{
"ssh-ng",
"localhost",
StoreConfig::Params{
StoreReference::Params{
{
"remote-program",
// TODO #11106, no more split on space
"foo bar",
{
"foo",
"bar",
},
},
{
"mounted",
nlohmann::json::object_t{
{"real", "/foo/bar"},
},
},
},
mockXpSettings,
};

EXPECT_EQ(
Expand All @@ -49,7 +96,10 @@ TEST(MountedSSHStore, constructConfig)
"foo",
"bar",
}));

ASSERT_TRUE(config.mounted);

EXPECT_EQ(config.mounted->realStoreDir, "/foo/bar");
}

}
#endif
Loading
Loading