Skip to content

Commit 2ea9f59

Browse files
Ericson2314roberthxokdvium
committed
New store settings system
Motivation: See the linked issues for details. The most notable user-relevant bits are: - This cleans up the `MountedSSHStore`: decomposed into its orthogonal parts - This brings us pretty close to being able to then implement a JSON-based config. - Store query parameters can be JSON - Stores can entirely be specified via JSON objects, but this is not yet hooked up to anything. Also behind the scenes have these benefits: 1. The docs are moved out of the headers, good for less rebuilding when they changes 2. Stores are always constructed from store configs 3. Use JSON, avoid custom serializers Context: Part of #11106 Co-Authored-By: Robert Hensing <[email protected]> Co-authored-by: Sergei Zimmerman <[email protected]>
1 parent bf5d544 commit 2ea9f59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2057
-696
lines changed

doc/manual/generate-settings.nix

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,32 @@ in
1919
prefix,
2020
inlineHTML ? true,
2121
}:
22-
settingsInfo:
2322

2423
let
2524

2625
showSetting =
2726
prefix: setting:
2827
{
2928
description,
30-
documentDefault,
31-
defaultValue,
32-
aliases,
33-
value,
29+
3430
experimentalFeature,
31+
32+
# Whether we document the default, because it is machine agostic,
33+
# or don't because because it is machine-specific.
34+
documentDefault ? true,
35+
36+
# The default value is JSON for new-style config, rather than then
37+
# a string or boolean, for old-style config.
38+
isJson ? false,
39+
40+
defaultValue ? null,
41+
42+
subSettings ? null,
43+
44+
aliases ? [ ],
45+
46+
# The current value for this setting. Purposefully unused.
47+
value ? null,
3548
}:
3649
let
3750
result = squash ''
@@ -50,7 +63,7 @@ let
5063
5164
${description}
5265
53-
**Default:** ${showDefault documentDefault defaultValue}
66+
${showDefaultOrSubSettings}
5467
5568
${showAliases aliases}
5669
'';
@@ -72,9 +85,24 @@ let
7285
> ```
7386
'';
7487

88+
showDefaultOrSubSettings =
89+
if !isAttrs subSettings then
90+
# No subsettings, instead single setting. Show the default value.
91+
''
92+
**Default:** ${showDefault}
93+
''
94+
else
95+
# Indent the nested sub-settings, and append the outer setting name onto the prefix
96+
indent " " ''
97+
**Nullable sub-settings**: ${if subSettings.nullable then "true" else "false"}
98+
${builtins.trace prefix (showSettings "${prefix}-${setting}" subSettings.map)}
99+
'';
100+
75101
showDefault =
76-
documentDefault: defaultValue:
77102
if documentDefault then
103+
if isJson then
104+
"`${builtins.toJSON defaultValue}`"
105+
else
78106
# a StringMap value type is specified as a string, but
79107
# this shows the value type. The empty stringmap is `null` in
80108
# JSON, but that converts to `{ }` here.
@@ -95,5 +123,7 @@ let
95123
in
96124
result;
97125

126+
showSettings =
127+
prefix: settingsInfo: concatStrings (attrValues (mapAttrs (showSetting prefix) settingsInfo));
98128
in
99-
concatStrings (attrValues (mapAttrs (showSetting prefix) settingsInfo))
129+
showSettings prefix

src/libstore-c/nix_api_store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
4343
if (!params)
4444
return new Store{nix::openStore(uri_str)};
4545

46-
nix::Store::Config::Params params_map;
46+
nix::StoreReference::Params params_map;
4747
for (size_t i = 0; params[i] != nullptr; i++) {
4848
params_map[params[i][0]] = params[i][1];
4949
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"scheme": "auto"
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": "/foo/bar/baz",
3+
"scheme": "auto"
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"authority": "",
3+
"root": "/foo/bar/baz",
4+
"scheme": "local"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"authority": "/foo/bar/baz",
3+
"scheme": "local",
4+
"trusted": true
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"authority": "localhost",
3+
"scheme": "ssh"
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"authority": "",
3+
"max-connections": 7,
4+
"scheme": "unix",
5+
"trusted": true
6+
}

src/libstore-tests/dummy-store.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <gtest/gtest.h>
2+
3+
#include "nix/store/dummy-store.hh"
4+
#include "nix/store/globals.hh"
5+
6+
namespace nix {
7+
8+
TEST(DummyStore, constructConfig)
9+
{
10+
DummyStoreConfig config{"dummy", "", {}};
11+
12+
EXPECT_EQ(config.storeDir, settings.nixStore);
13+
}
14+
15+
TEST(DummyStore, constructConfigNoAuthority)
16+
{
17+
EXPECT_THROW(DummyStoreConfig("dummy", "not-allowed", {}), UsageError);
18+
}
19+
20+
} // namespace nix

src/libstore-tests/legacy-ssh-store.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ TEST(LegacySSHStore, constructConfig)
99
LegacySSHStoreConfig config{
1010
"ssh",
1111
"localhost",
12-
StoreConfig::Params{
12+
StoreReference::Params{
1313
{
1414
"remote-program",
15-
// TODO #11106, no more split on space
16-
"foo bar",
15+
{
16+
"foo",
17+
"bar",
18+
},
1719
},
1820
}};
1921
EXPECT_EQ(

src/libstore-tests/local-overlay-store.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
// FIXME: Odd failures for templates that are causing the PR to break
2-
// for now with discussion with @Ericson2314 to comment out.
3-
#if 0
4-
# include <gtest/gtest.h>
1+
#include <gtest/gtest.h>
52

6-
# include "nix/store/local-overlay-store.hh"
3+
#include "nix/store/local-overlay-store.hh"
74

85
namespace nix {
96

@@ -31,4 +28,3 @@ TEST(LocalOverlayStore, constructConfig_rootPath)
3128
}
3229

3330
} // namespace nix
34-
#endif

src/libstore-tests/local-store.cc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
// FIXME: Odd failures for templates that are causing the PR to break
2-
// for now with discussion with @Ericson2314 to comment out.
3-
#if 0
4-
# include <gtest/gtest.h>
1+
#include <gtest/gtest.h>
52

6-
# include "nix/store/local-store.hh"
7-
8-
// Needed for template specialisations. This is not good! When we
9-
// overhaul how store configs work, this should be fixed.
10-
# include "nix/util/args.hh"
11-
# include "nix/util/config-impl.hh"
12-
# include "nix/util/abstract-setting-to-json.hh"
3+
#include "nix/store/local-store.hh"
134

145
namespace nix {
156

@@ -37,4 +28,3 @@ TEST(LocalStore, constructConfig_rootPath)
3728
}
3829

3930
} // namespace nix
40-
#endif

src/libstore-tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ sources = files(
5858
'derivation-advanced-attrs.cc',
5959
'derivation.cc',
6060
'derived-path.cc',
61+
'dummy-store.cc',
6162
'downstream-placeholder.cc',
6263
'http-binary-cache-store.cc',
6364
'legacy-ssh-store.cc',

src/libstore-tests/nix_api_store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ TEST_F(nix_api_util_context, nix_store_open_dummy)
9797
nix_libstore_init(ctx);
9898
Store * store = nix_store_open(ctx, "dummy://", nullptr);
9999
ASSERT_EQ(NIX_OK, ctx->last_err_code);
100-
ASSERT_STREQ("dummy", store->ptr->getUri().c_str());
100+
ASSERT_STREQ("dummy://", store->ptr->getUri().c_str());
101101

102102
std::string str;
103103
nix_store_get_version(ctx, store, OBSERVE_STRING(str));

src/libstore-tests/ssh-store.cc

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
// FIXME: Odd failures for templates that are causing the PR to break
2-
// for now with discussion with @Ericson2314 to comment out.
3-
#if 0
4-
# include <gtest/gtest.h>
1+
#include <gtest/gtest.h>
52

6-
# include "nix/store/ssh-store.hh"
3+
#include "nix/store/ssh-store.hh"
74

85
namespace nix {
96

107
TEST(SSHStore, constructConfig)
118
{
129
SSHStoreConfig config{
13-
"ssh",
10+
"ssh-ng",
1411
"localhost",
15-
StoreConfig::Params{
12+
StoreReference::Params{
1613
{
1714
"remote-program",
18-
// TODO #11106, no more split on space
19-
"foo bar",
15+
{
16+
"foo",
17+
"bar",
18+
},
2019
},
2120
},
2221
};
@@ -31,16 +30,64 @@ TEST(SSHStore, constructConfig)
3130

3231
TEST(MountedSSHStore, constructConfig)
3332
{
34-
MountedSSHStoreConfig config{
35-
"mounted-ssh",
33+
ExperimentalFeatureSettings mockXpSettings;
34+
mockXpSettings.set("experimental-features", "mounted-ssh-store");
35+
36+
SSHStoreConfig config{
37+
"ssh-ng",
38+
"localhost",
39+
StoreReference::Params{
40+
{
41+
"remote-program",
42+
{
43+
"foo",
44+
"bar",
45+
},
46+
},
47+
{
48+
"mounted",
49+
nlohmann::json::object_t{},
50+
},
51+
},
52+
mockXpSettings,
53+
};
54+
55+
EXPECT_EQ(
56+
config.remoteProgram.get(),
57+
(Strings{
58+
"foo",
59+
"bar",
60+
}));
61+
62+
ASSERT_TRUE(config.mounted);
63+
64+
EXPECT_EQ(config.mounted->realStoreDir, "/nix/store");
65+
}
66+
67+
TEST(MountedSSHStore, constructConfigWithFunnyRealStoreDir)
68+
{
69+
ExperimentalFeatureSettings mockXpSettings;
70+
mockXpSettings.set("experimental-features", "mounted-ssh-store");
71+
72+
SSHStoreConfig config{
73+
"ssh-ng",
3674
"localhost",
37-
StoreConfig::Params{
75+
StoreReference::Params{
3876
{
3977
"remote-program",
40-
// TODO #11106, no more split on space
41-
"foo bar",
78+
{
79+
"foo",
80+
"bar",
81+
},
82+
},
83+
{
84+
"mounted",
85+
nlohmann::json::object_t{
86+
{"real", "/foo/bar"},
87+
},
4288
},
4389
},
90+
mockXpSettings,
4491
};
4592

4693
EXPECT_EQ(
@@ -49,7 +96,10 @@ TEST(MountedSSHStore, constructConfig)
4996
"foo",
5097
"bar",
5198
}));
99+
100+
ASSERT_TRUE(config.mounted);
101+
102+
EXPECT_EQ(config.mounted->realStoreDir, "/foo/bar");
52103
}
53104

54105
}
55-
#endif

0 commit comments

Comments
 (0)