Skip to content

Commit 1f3c3a3

Browse files
committed
Make the flake options work when using the daemon
When setting flake-local options (with the `nixConfig` field), forward these options to the daemon in case we’re using one. This is necessary in particular for options like `binary-caches` or `post-build-hook` to make sense. Fix <NixOS@343239f#r44356843>
1 parent 7d6017b commit 1f3c3a3

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

src/libexpr/flake/flake.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ LockedFlake lockFlake(
307307

308308
if (lockFlags.applyNixConfig) {
309309
flake.config.apply();
310-
// FIXME: send new config to the daemon.
310+
state.store->setOptions();
311311
}
312312

313313
try {

src/libstore/remote-store.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ ConnectionHandle RemoteStore::getConnection()
290290
return ConnectionHandle(connections->get());
291291
}
292292

293+
void RemoteStore::setOptions()
294+
{
295+
setOptions(*(getConnection().handle));
296+
}
293297

294298
bool RemoteStore::isValidPathUncached(const StorePath & path)
295299
{

src/libstore/remote-store.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ protected:
147147

148148
virtual void setOptions(Connection & conn);
149149

150+
void setOptions() override;
151+
150152
ConnectionHandle getConnection();
151153

152154
friend struct ConnectionHandle;

src/libstore/store-api.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,11 @@ public:
724724
virtual void createUser(const std::string & userName, uid_t userId)
725725
{ }
726726

727+
/*
728+
* Synchronises the options of the client with those of the daemon
729+
* (a no-op when there’s no daemon)
730+
*/
731+
virtual void setOptions() { }
727732
protected:
728733

729734
Stats stats;

tests/flake-local-settings.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
source common.sh
2+
3+
clearStore
4+
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
5+
6+
cp ./simple.nix ./simple.builder.sh ./config.nix $TEST_HOME
7+
8+
cd $TEST_HOME
9+
10+
rm -f post-hook-ran
11+
cat <<EOF > echoing-post-hook.sh
12+
#!/bin/sh
13+
14+
echo "ThePostHookRan" > $PWD/post-hook-ran
15+
EOF
16+
chmod +x echoing-post-hook.sh
17+
18+
cat <<EOF > flake.nix
19+
{
20+
nixConfig.post-build-hook = "$PWD/echoing-post-hook.sh";
21+
22+
outputs = a: {
23+
defaultPackage.$system = import ./simple.nix;
24+
};
25+
}
26+
EOF
27+
28+
# Ugly hack for testing
29+
mkdir -p .local/share/nix
30+
cat <<EOF > .local/share/nix/trusted-settings.json
31+
{"post-build-hook":{"$PWD/echoing-post-hook.sh":true}}
32+
EOF
33+
34+
nix build
35+
test -f post-hook-ran || fail "The post hook should have ran"

tests/local.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ nix_tests = \
4646
recursive.sh \
4747
describe-stores.sh \
4848
flakes.sh \
49+
flake-local-settings.sh \
4950
build.sh \
5051
compute-levels.sh \
5152
repl.sh \

0 commit comments

Comments
 (0)