Skip to content
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

Add setting 'client-only-settings' to prevent forwarding to the daemon #11223

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ struct ClientSettings
return true;
};

auto clientOnlySettings = settings.clientOnlySettings.get();

try {
if (name == "ssh-auth-sock") // obsolete
;
else if (clientOnlySettings.contains(name))
;
else if (name == experimentalFeatureSettings.experimentalFeatures.name) {
// We don’t want to forward the experimental features to
// the daemon, as that could cause some pretty weird stuff
Expand Down
6 changes: 6 additions & 0 deletions src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public:
*/
Path nixDaemonSocketFile;

Setting<StringSet> clientOnlySettings{this, {}, "client-only-settings",
R"(
The names of settings that will not be forwarded from the
Nix client to the Nix daemon.
)"};

Setting<std::string> storeUri{this, getEnv("NIX_REMOTE").value_or("auto"), "store",
R"(
The [URL of the Nix store](@docroot@/store/types/index.md#store-url-format)
Expand Down
3 changes: 3 additions & 0 deletions src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ void RemoteStore::setOptions(Connection & conn)
overrides.erase(loggerSettings.showTrace.name);
overrides.erase(experimentalFeatureSettings.experimentalFeatures.name);
overrides.erase("plugin-files");
overrides.erase(settings.clientOnlySettings.name);
for (auto & i : settings.clientOnlySettings.get())
overrides.erase(i);
conn.to << overrides.size();
for (auto & i : overrides)
conn.to << i.first << i.second.value;
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/common/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ clearCacheCache() {
rm -f "$TEST_HOME/.cache/nix/binary-cache"*
}

extraDaemonFlags=()

startDaemon() {
if isTestOnNixOS; then
die "startDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
Expand All @@ -73,7 +75,7 @@ startDaemon() {
fi
# Start the daemon, wait for the socket to appear.
rm -f "$NIX_DAEMON_SOCKET_PATH"
PATH=$DAEMON_PATH nix --extra-experimental-features 'nix-command' daemon &
PATH=$DAEMON_PATH nix --extra-experimental-features 'nix-command' daemon "${extraDaemonFlags[@]}" &
_NIX_TEST_DAEMON_PID=$!
export _NIX_TEST_DAEMON_PID
for ((i = 0; i < 300; i++)); do
Expand Down
17 changes: 17 additions & 0 deletions tests/functional/remote-store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ NIX_REMOTE= nix-store --dump-db > $TEST_ROOT/d2
cmp $TEST_ROOT/d1 $TEST_ROOT/d2

killDaemon

# Test 'client-only-settings' on the client.
extraDaemonFlags=("--trusted-users" "")
startDaemon
nix store info --netrc-file /foo 2>&1 | grepQuiet "ignoring the client-specified setting 'netrc-file'"
if nix store info --netrc-file /foo --client-only-settings netrc-file 2>&1 | grep "ignoring the client-specified setting 'netrc-file'"; then
exit 1
fi
killDaemon

# Test 'client-only-settings' on the daemon.
extraDaemonFlags=("--trusted-users" "" "--option" "client-only-settings" "netrc-file")
startDaemon
if nix store info --netrc-file /foo 2>&1 | grep "ignoring the client-specified setting 'netrc-file'"; then
exit 1
fi
killDaemon
Loading