Skip to content
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
4 changes: 2 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ subproject('nix')

# Docs
if get_option('doc-gen')
subproject('internal-api-docs')
subproject('external-api-docs')
#subproject('internal-api-docs')
#subproject('external-api-docs')
if meson.can_run_host_binaries()
subproject('nix-manual')
endif
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
}
14 changes: 13 additions & 1 deletion src/libstore-tests/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@

namespace nix {

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

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

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

TEST(DummyStore, realisation_read)
{
initLibStore(/*loadConfig=*/false);

auto store = [] {
auto cfg = make_ref<DummyStoreConfig>(StoreReference::Params{});
cfg->readOnly = false;
cfg->readOnly = {false};
return cfg->openDummyStore();
}();

Expand Down
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 @@ -12,13 +12,15 @@ TEST(LegacySSHStore, constructConfig)
StoreConfig::Params{
{
"remote-program",
// TODO #11106, no more split on space
"foo bar",
{
"foo",
"bar",
},
},
});

EXPECT_EQ(
config.remoteProgram.get(),
config.remoteProgram,
(Strings{
"foo",
"bar",
Expand Down
4 changes: 2 additions & 2 deletions src/libstore-tests/local-overlay-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ TEST(LocalOverlayStore, constructConfig_rootQueryParam)
},
};

EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
EXPECT_EQ(config.rootDir, std::optional{"/foo/bar"});
}

TEST(LocalOverlayStore, constructConfig_rootPath)
{
LocalOverlayStoreConfig config{"local-overlay", "/foo/bar", {}};

EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
EXPECT_EQ(config.rootDir, std::optional{"/foo/bar"});
}

} // namespace nix
10 changes: 2 additions & 8 deletions src/libstore-tests/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

#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"

namespace nix {

TEST(LocalStore, constructConfig_rootQueryParam)
Expand All @@ -23,14 +17,14 @@ TEST(LocalStore, constructConfig_rootQueryParam)
},
};

EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
EXPECT_EQ(config.rootDir, std::optional{"/foo/bar"});
}

TEST(LocalStore, constructConfig_rootPath)
{
LocalStoreConfig config{"local", "/foo/bar", {}};

EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
EXPECT_EQ(config.rootDir, std::optional{"/foo/bar"});
}

TEST(LocalStore, constructConfig_to_string)
Expand Down
26 changes: 13 additions & 13 deletions src/libstore-tests/s3-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST(S3BinaryCacheStore, constructConfigWithRegion)
.authority = ParsedURL::Authority{.host = "my-bucket"},
.query = (StringMap) {{"region", "eu-west-1"}},
}));
EXPECT_EQ(config.region.get(), "eu-west-1");
EXPECT_EQ(config.region, "eu-west-1");
}

TEST(S3BinaryCacheStore, defaultSettings)
Expand All @@ -47,18 +47,18 @@ TEST(S3BinaryCacheStore, defaultSettings)
}));

// Check default values
EXPECT_EQ(config.region.get(), "us-east-1");
EXPECT_EQ(config.profile.get(), "default");
EXPECT_EQ(config.scheme.get(), "https");
EXPECT_EQ(config.endpoint.get(), "");
EXPECT_EQ(config.region, "us-east-1");
EXPECT_EQ(config.profile, "default");
EXPECT_EQ(config.scheme, "https");
EXPECT_EQ(config.endpoint, "");
}

/**
* Test that S3BinaryCacheStore properly preserves S3-specific parameters
*/
TEST(S3BinaryCacheStore, s3StoreConfigPreservesParameters)
{
StringMap params;
StoreReference::Params params;
params["region"] = "eu-west-1";
params["endpoint"] = "custom.s3.com";

Expand Down Expand Up @@ -93,7 +93,7 @@ TEST(S3BinaryCacheStore, s3SchemeRegistration)
*/
TEST(S3BinaryCacheStore, parameterFiltering)
{
StringMap params;
StoreReference::Params params;
params["region"] = "eu-west-1";
params["endpoint"] = "minio.local";
params["want-mass-query"] = "true"; // Non-S3 store parameter
Expand All @@ -111,8 +111,8 @@ TEST(S3BinaryCacheStore, parameterFiltering)
}));

// But the non-S3 params should still be set on the config
EXPECT_EQ(config.wantMassQuery.get(), true);
EXPECT_EQ(config.priority.get(), 10);
EXPECT_EQ(config.wantMassQuery, true);
EXPECT_EQ(config.priority, 10);

// And all params (S3 and non-S3) should be returned by getReference()
auto ref = config.getReference();
Expand All @@ -128,16 +128,16 @@ TEST(S3BinaryCacheStore, parameterFiltering)
TEST(S3BinaryCacheStore, storageClassDefault)
{
S3BinaryCacheStoreConfig config{"s3", "test-bucket", {}};
EXPECT_EQ(config.storageClass.get(), std::nullopt);
EXPECT_EQ(config.storageClass, std::nullopt);
}

TEST(S3BinaryCacheStore, storageClassConfiguration)
{
StringMap params;
StoreReference::Params params;
params["storage-class"] = "GLACIER";

S3BinaryCacheStoreConfig config("s3", "test-bucket", params);
EXPECT_EQ(config.storageClass.get(), std::optional<std::string>("GLACIER"));
S3BinaryCacheStoreConfig config{"s3", "test-bucket", params};
EXPECT_EQ(config.storageClass, std::optional<std::string>("GLACIER"));
}

} // namespace nix
Loading
Loading