Skip to content

Commit 382f994

Browse files
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 Part of #10766
1 parent 7156737 commit 382f994

File tree

106 files changed

+2786
-1227
lines changed

Some content is hidden

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

106 files changed

+2786
-1227
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+
json ? 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 json 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

doc/manual/generate-store-info.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let
3333
{
3434
settings,
3535
doc,
36+
uri-schemes,
3637
experimentalFeature,
3738
}:
3839
let

src/build-remote/build-remote.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "nix/store/globals.hh"
1717
#include "nix/util/serialise.hh"
1818
#include "nix/store/build-result.hh"
19-
#include "nix/store/store-api.hh"
19+
#include "nix/store/store-open.hh"
2020
#include "nix/util/strings.hh"
2121
#include "nix/store/derivations.hh"
2222
#include "nix/store/local-store.hh"
@@ -44,7 +44,7 @@ static AutoCloseFD openSlotLock(const Machine & m, uint64_t slot)
4444

4545
static bool allSupportedLocally(Store & store, const std::set<std::string>& requiredFeatures) {
4646
for (auto & feature : requiredFeatures)
47-
if (!store.systemFeatures.get().count(feature)) return false;
47+
if (!store.config.systemFeatures.get().count(feature)) return false;
4848
return true;
4949
}
5050

@@ -85,7 +85,7 @@ static int main_build_remote(int argc, char * * argv)
8585
that gets cleared on reboot, but it wouldn't work on macOS. */
8686
auto currentLoadName = "/current-load";
8787
if (auto localStore = store.dynamic_pointer_cast<LocalFSStore>())
88-
currentLoad = std::string { localStore->stateDir } + currentLoadName;
88+
currentLoad = std::string { localStore->config.stateDir } + currentLoadName;
8989
else
9090
currentLoad = settings.nixStateDir + currentLoadName;
9191

src/libcmd/command.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "nix/cmd/command.hh"
55
#include "nix/cmd/markdown.hh"
6-
#include "nix/store/store-api.hh"
6+
#include "nix/store/store-open.hh"
77
#include "nix/store/local-fs-store.hh"
88
#include "nix/store/derivations.hh"
99
#include "nix/expr/nixexpr.hh"

src/libcmd/common-eval-args.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "nix/fetchers/registry.hh"
1010
#include "nix/flake/flakeref.hh"
1111
#include "nix/flake/settings.hh"
12-
#include "nix/store/store-api.hh"
12+
#include "nix/store/store-open.hh"
1313
#include "nix/cmd/command.hh"
1414
#include "nix/fetchers/tarball.hh"
1515
#include "nix/fetchers/fetch-to-store.hh"

src/libcmd/include/nix/cmd/command.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern char ** savedArgv;
1818
class EvalState;
1919
struct Pos;
2020
class Store;
21-
class LocalFSStore;
21+
struct LocalFSStore;
2222

2323
static constexpr Command::Category catHelp = -1;
2424
static constexpr Command::Category catSecondary = 100;

src/libcmd/repl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "nix/expr/eval-settings.hh"
1313
#include "nix/expr/attr-path.hh"
1414
#include "nix/util/signals.hh"
15-
#include "nix/store/store-api.hh"
15+
#include "nix/store/store-open.hh"
1616
#include "nix/store/log-store.hh"
1717
#include "nix/cmd/common-eval-args.hh"
1818
#include "nix/expr/get-drvs.hh"

src/libexpr/primops/fetchClosure.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "nix/expr/primops.hh"
2-
#include "nix/store/store-api.hh"
2+
#include "nix/store/store-open.hh"
33
#include "nix/store/realisation.hh"
44
#include "nix/store/make-content-addressed.hh"
55
#include "nix/util/url.hh"

src/libstore-c/nix_api_store.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "nix/store/path.hh"
77
#include "nix/store/store-api.hh"
8+
#include "nix/store/store-open.hh"
89
#include "nix/store/build-result.hh"
910

1011
#include "nix/store/globals.hh"
@@ -42,7 +43,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
4243
if (!params)
4344
return new Store{nix::openStore(uri_str)};
4445

45-
nix::Store::Params params_map;
46+
nix::StoreReference::Params params_map;
4647
for (size_t i = 0; params[i] != nullptr; i++) {
4748
params_map[params[i][0]] = params[i][1];
4849
}

src/libstore-test-support/include/nix/store/tests/libstore.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <gmock/gmock.h>
66

77
#include "nix/store/store-api.hh"
8+
#include "nix/store/store-open.hh"
89

910
namespace nix {
1011

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));

0 commit comments

Comments
 (0)