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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port the flags of nix-daemon to nix daemon #8788

Merged
merged 9 commits into from
Aug 28, 2023
41 changes: 40 additions & 1 deletion src/nix/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,45 @@ static RegisterLegacyCommand r_nix_daemon("nix-daemon", main_nix_daemon);

struct CmdDaemon : StoreCommand
{
bool stdio = false;
std::optional<TrustedFlag> isTrustedOpt = std::nullopt;

CmdDaemon()
{
addFlag({
.longName = "stdio",
.description = "Attach to standard I/O, instead of trying to bind to a UNIX socket.",
.handler = {&stdio, true},
});

addFlag({
.longName = "force-trusted",
.description = "Forces the daemon to trust connecting clients, forwarding the connection without the receiving daemon processing it.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually forward the connection? I assume that depends on nix daemon's own --store parameter: If it's "local", then it won't forward to another daemon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true. Forcing untrusted does make not force in the --stdio case when --store is a RemoteStore subclass, but forcing trusted (if I am reading the code above right) doesn't seem to affect when forwarding happens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, just "Forces the daemon to trust connecting clients." would be enough as a description in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think that is good

tomberek marked this conversation as resolved.
Show resolved Hide resolved
.handler = {[&]() {
isTrustedOpt = Trusted;
}},
.experimentalFeature = Xp::DaemonTrustOverride,
});

addFlag({
.longName = "force-untrusted",
.description = "Forces the daemon to not trust connecting clients, the connection will be processed by the receiving daemon before forwarding commands.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.description = "Forces the daemon to not trust connecting clients, the connection will be processed by the receiving daemon before forwarding commands.",
.description = "Force the daemon to not trust connecting clients. The connection will be processed by the receiving daemon before forwarding commands.",

tomberek marked this conversation as resolved.
Show resolved Hide resolved
.handler = {[&]() {
isTrustedOpt = NotTrusted;
}},
.experimentalFeature = Xp::DaemonTrustOverride,
});

addFlag({
.longName = "default-trust",
.description = "Use Nix's default trust.",
.handler = {[&]() {
isTrustedOpt = std::nullopt;
}},
.experimentalFeature = Xp::DaemonTrustOverride,
});
}

std::string description() override
{
return "daemon to perform store operations on behalf of non-root clients";
Expand All @@ -516,7 +555,7 @@ struct CmdDaemon : StoreCommand

void run(ref<Store> store) override
{
runDaemon(false, std::nullopt);
runDaemon(stdio, isTrustedOpt);
}
};

Expand Down
30 changes: 27 additions & 3 deletions src/nix/daemon.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
R""(

# Example
# Examples

* Run the daemon in the foreground:
* Run the daemon:

```console
# nix daemon
```

* Run the daemon and listen on standard I/O instead of binding to a UNIX socket:

```console
# nix daemon --stdio
```

* Run the daemon and force all connections to be trusted:

```console
# nix daemon --force-trusted
```

* Run the daemon and force all connections to be untrusted:

```console
# nix daemon --force-untrusted
```

* Run the daemon, listen on standard I/O, and force all connections to use Nix's default trust:

```console
# nix daemon --stdio --default-trust
```

# Description

This command runs the Nix daemon, which is a required component in
multi-user Nix installations. It runs build tasks and other
operations on the Nix store on behalf of non-root users. Usually you
don't run the daemon directly; instead it's managed by a service
management framework such as `systemd`.
management framework such as `systemd` on Linux, or `launchctl` on Darwin.

Note that this daemon does not fork into the background.

Expand Down