Skip to content

Run daemon at startup#1782

Merged
grahamc merged 1 commit into
mainfrom
sep-cole/nix-284-automatically-start-determinate-nix-daemon-after
Mar 5, 2026
Merged

Run daemon at startup#1782
grahamc merged 1 commit into
mainfrom
sep-cole/nix-284-automatically-start-determinate-nix-daemon-after

Conversation

@cole-h
Copy link
Copy Markdown
Member

@cole-h cole-h commented Feb 23, 2026

Description
Checklist
  • Formatted with cargo fmt
  • Built with nix build
  • Ran flake checks with nix flake check
  • Added or updated relevant tests (leave unchecked if not applicable)
  • Added or updated relevant documentation (leave unchecked if not applicable)
  • Linked to related issues (leave unchecked if not applicable)
Validating with install.determinate.systems

If a maintainer has added the upload to s3 label to this PR, it will become available for installation via install.determinate.systems:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/pr/$PR_NUMBER | sh -s -- install

Summary by CodeRabbit

  • Bug Fixes
    • Daemon service now set to start automatically when the system loads.
    • Initialization now enables the main service unit during setup so the service can be activated immediately (includes conditional --now behavior respecting the "start daemon" setting).

@cole-h cole-h added the upload to s3 The labeled PR is allowed to upload its artifacts to S3 for easy testing label Feb 23, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3239b5e and fa7231d.

📒 Files selected for processing (2)
  • src/action/common/configure_determinate_nixd_init_service/mod.rs
  • src/action/common/configure_init_service.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/action/common/configure_init_service.rs
  • src/action/common/configure_determinate_nixd_init_service/mod.rs

📝 Walkthrough

Walkthrough

Set DeterminateNixDaemon plist run_at_load to true. In the systemd path, add a conditional enable (and optional start) step for the main service unit after socket configuration; errors are propagated.

Changes

Cohort / File(s) Summary
Nix Daemon Initialization
src/action/common/configure_determinate_nixd_init_service/mod.rs
Changed generated DeterminateNixDaemonPlist run_at_load from false to true.
Systemd Service Configuration
src/action/common/configure_init_service.rs
Introduced service_dest local variable, updated unit source explanations, added an enable call enable(service_dest, *start_daemon) after socket handling (conditionally uses --now), and propagated errors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • grahamc
  • colemickens

Poem

🐇
I nudged a plist awake at dawn,
Sockets hum and services yawn,
A gentle enable, a soft command,
The daemon hops to life on hand,
Carrot cheers from the launchd land 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Run daemon at startup' directly corresponds to the main changes: setting RunAtLoad to true for the DeterminateNixDaemon and adding enable calls in the systemd service configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sep-cole/nix-284-automatically-start-determinate-nix-daemon-after

Comment @coderabbitai help to get the list of available commands and usage tips.

@cole-h cole-h marked this pull request as ready for review February 23, 2026 22:40
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/action/common/configure_init_service.rs (1)

460-484: ⚠️ Potential issue | 🟠 Major

Unconditional systemctl enable on service contradicts socket activation goal.

Line 344 documents the intended behavior: "The goal state is the socket enabled and active, the service not enabled and stopped (it activates via socket activation)". However, lines 482-484 unconditionally enable the service regardless of start_daemon, which directly contradicts this goal and systemd socket activation best practices.

With socket activation, the socket alone manages when the service starts—the service should remain disabled. This is inconsistent with how socket units are handled (gated on start_daemon at line 463) and other operations like daemon-reload and kickstart (both gated on start_daemon).

Gate this on *start_daemon:

Suggested fix
-                enable(service_dest.display().to_string().as_ref(), true)
-                    .await
-                    .map_err(Self::error)?;
+                if *start_daemon {
+                    enable(service_dest.display().to_string().as_ref(), true)
+                        .await
+                        .map_err(Self::error)?;
+                }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/action/common/configure_init_service.rs` around lines 460 - 484, The code
unconditionally calls enable(service_dest..., true) which contradicts the
socket-activation goal; change this to only enable the service when start_daemon
is true. Locate the enable call for service_dest and wrap it in a conditional
checking *start_daemon (or pass a boolean derived from *start_daemon) so the
service is not enabled when socket activation is desired; keep the existing
enable(...) call and error handling inside that conditional.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/action/common/configure_determinate_nixd_init_service/mod.rs`:
- Around line 207-212: The plist currently hardcodes run_at_load=true in
generate_plist(), causing launchd to ignore the start_daemon flag; modify
generate_plist to accept a boolean parameter (e.g., start_daemon: bool) and set
DeterminateNixDaemonPlist.run_at_load based on that parameter (true when
start_daemon is true, false otherwise), then thread the caller-side start_daemon
value into generate_plist(start_daemon) so the RunAtLoad behaviour matches the
start_daemon setting.

---

Outside diff comments:
In `@src/action/common/configure_init_service.rs`:
- Around line 460-484: The code unconditionally calls enable(service_dest...,
true) which contradicts the socket-activation goal; change this to only enable
the service when start_daemon is true. Locate the enable call for service_dest
and wrap it in a conditional checking *start_daemon (or pass a boolean derived
from *start_daemon) so the service is not enabled when socket activation is
desired; keep the existing enable(...) call and error handling inside that
conditional.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee7e5f6 and fc6cc34.

📒 Files selected for processing (2)
  • src/action/common/configure_determinate_nixd_init_service/mod.rs
  • src/action/common/configure_init_service.rs

Comment thread src/action/common/configure_determinate_nixd_init_service/mod.rs
@cole-h cole-h force-pushed the sep-cole/nix-284-automatically-start-determinate-nix-daemon-after branch from fc6cc34 to 06bf5fc Compare February 24, 2026 17:26
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/action/common/configure_init_service.rs (1)

225-229: ⚠️ Potential issue | 🟡 Minor

execute_description not updated to reflect the new unconditional service enable

Lines 225–229 document socket enables only when start_daemon is true. The new unconditional enable --now on the service unit has no corresponding description entry. Users inspecting the planned actions will not see this step.

📝 Proposed fix
                 if self.start_daemon {
                     for SocketFile { name, .. } in self.socket_files.iter() {
                         explanation.push(format!("Run `systemctl enable --now {}`", name));
                     }
+                    explanation.push(format!(
+                        "Run `systemctl enable --now {}`",
+                        self.service_dest
+                            .as_ref()
+                            .expect("service_dest should be defined for systemd")
+                            .display()
+                    ));
                 }

Adjust the condition to match whatever guard is ultimately applied to the enable call.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/action/common/configure_init_service.rs` around lines 225 - 229, The
description block in execute_description currently only documents socket enables
under the conditional using self.start_daemon and iterating over
self.socket_files (SocketFile { name, .. }) and pushing explanation entries;
update it so the planned-action text matches the actual unconditional service
"systemctl enable --now <service>" call: either remove the self.start_daemon
guard around the explanation push or add an unconditional explanation.push for
the service unit enable, and ensure the same service unit name used in the
enable code is referenced in the explanation (use the same symbol/name as in the
enable logic) so users see the service enable step in execute_description.
♻️ Duplicate comments (1)
src/action/common/configure_determinate_nixd_init_service/mod.rs (1)

207-209: ⚠️ Potential issue | 🟠 Major

run_at_load: true still ignores start_daemon — previously flagged

generate_plist() takes no parameters, so RunAtLoad is hardcoded to true. Because retry_bootstrap (line 314) loads the plist with this flag, the daemon starts immediately upon installation even when start_daemon=false. The past review recommended threading start_daemon into generate_plist(run_at_load: bool) to align launchd behavior with the systemd path.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/action/common/configure_determinate_nixd_init_service/mod.rs` around
lines 207 - 209, generate_plist currently hardcodes run_at_load to true,
ignoring the start_daemon flag; change the function signature generate_plist to
accept a run_at_load: bool parameter and use that value for the
DeterminateNixDaemonPlist.run_at_load field, then update all call sites (notably
retry_bootstrap which loads the plist) to pass the start_daemon boolean so
launchd behavior matches the systemd path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/action/common/configure_init_service.rs`:
- Around line 481-484: The enable call currently forces starting the unit by
passing true; change it to use the same guard as the socket enables (i.e.,
compute enable_now as *start_daemon || any_socket_was_active and pass that
instead of true), and ensure daemon-reload has run before calling enable so
systemd knows about the new unit (move or duplicate the daemon-reload invocation
outside the if *start_daemon guard or run it when enable_now is true). Also
avoid invoking enable --now when systemd is not running by ensuring the
plan/execute checks for /run/systemd/system are respected when enable_now is
true; use the existing start_daemon / any_socket_was_active logic rather than
unconditional true in the enable(service_dest.display().to_string().as_ref(),
...) call.

---

Outside diff comments:
In `@src/action/common/configure_init_service.rs`:
- Around line 225-229: The description block in execute_description currently
only documents socket enables under the conditional using self.start_daemon and
iterating over self.socket_files (SocketFile { name, .. }) and pushing
explanation entries; update it so the planned-action text matches the actual
unconditional service "systemctl enable --now <service>" call: either remove the
self.start_daemon guard around the explanation push or add an unconditional
explanation.push for the service unit enable, and ensure the same service unit
name used in the enable code is referenced in the explanation (use the same
symbol/name as in the enable logic) so users see the service enable step in
execute_description.

---

Duplicate comments:
In `@src/action/common/configure_determinate_nixd_init_service/mod.rs`:
- Around line 207-209: generate_plist currently hardcodes run_at_load to true,
ignoring the start_daemon flag; change the function signature generate_plist to
accept a run_at_load: bool parameter and use that value for the
DeterminateNixDaemonPlist.run_at_load field, then update all call sites (notably
retry_bootstrap which loads the plist) to pass the start_daemon boolean so
launchd behavior matches the systemd path.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc6cc34 and 06bf5fc.

📒 Files selected for processing (2)
  • src/action/common/configure_determinate_nixd_init_service/mod.rs
  • src/action/common/configure_init_service.rs

Comment thread src/action/common/configure_init_service.rs
@cole-h cole-h force-pushed the sep-cole/nix-284-automatically-start-determinate-nix-daemon-after branch from 06bf5fc to 3239b5e Compare February 24, 2026 17:34
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/action/common/configure_init_service.rs (1)

223-229: ⚠️ Potential issue | 🟡 Minor

execute_description does not mention the new service-enable step

The service unit is now unconditionally enabled (with --now when start_daemon=true, plain otherwise), but execute_description has no corresponding entry for it. This leaves the human-readable plan description out of sync with what execute actually does.

📝 Proposed fix
                if self.start_daemon {
                    for SocketFile { name, .. } in self.socket_files.iter() {
                        explanation.push(format!("Run `systemctl enable --now {}`", name));
                    }
+                   explanation.push(format!(
+                       "Run `systemctl enable --now {}`",
+                       self.service_dest
+                           .as_ref()
+                           .expect("service_dest should be defined for systemd")
+                           .display()
+                   ));
+               } else {
+                   explanation.push(format!(
+                       "Run `systemctl enable {}`",
+                       self.service_dest
+                           .as_ref()
+                           .expect("service_dest should be defined for systemd")
+                           .display()
+                   ));
                }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/action/common/configure_init_service.rs` around lines 223 - 229,
execute_description is out of sync with execute: the code now enables the
service units unconditionally but the human-readable plan (explanation vector
built in execute_description) lacks that step. Update execute_description so it
iterates over self.socket_files (SocketFile { name, .. }) and pushes an
appropriate enable message for each service—use "Run `systemctl enable --now
{name}`" when self.start_daemon is true and "Run `systemctl enable {name}`" when
false—so the explanation matches what execute performs.
♻️ Duplicate comments (1)
src/action/common/configure_init_service.rs (1)

344-344: Stale comment: "the service not enabled and stopped" no longer holds

The comment still claims the goal state leaves the service not enabled, but the code now explicitly enables it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/action/common/configure_init_service.rs` at line 344, Update the stale
inline comment that says "the service not enabled and stopped" to match the
current behavior where the service is explicitly enabled; locate the comment
near the configure_init_service logic (e.g., around the block that enables the
service/socket in configure_init_service or the variables named `socket` and
`service`) and change it to state the actual goal state (e.g., both socket and
service are enabled and active, service may be socket-activated) or remove the
inaccurate clause.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/action/common/configure_init_service.rs`:
- Around line 223-229: execute_description is out of sync with execute: the code
now enables the service units unconditionally but the human-readable plan
(explanation vector built in execute_description) lacks that step. Update
execute_description so it iterates over self.socket_files (SocketFile { name, ..
}) and pushes an appropriate enable message for each service—use "Run `systemctl
enable --now {name}`" when self.start_daemon is true and "Run `systemctl enable
{name}`" when false—so the explanation matches what execute performs.

---

Duplicate comments:
In `@src/action/common/configure_init_service.rs`:
- Line 344: Update the stale inline comment that says "the service not enabled
and stopped" to match the current behavior where the service is explicitly
enabled; locate the comment near the configure_init_service logic (e.g., around
the block that enables the service/socket in configure_init_service or the
variables named `socket` and `service`) and change it to state the actual goal
state (e.g., both socket and service are enabled and active, service may be
socket-activated) or remove the inaccurate clause.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06bf5fc and 3239b5e.

📒 Files selected for processing (2)
  • src/action/common/configure_determinate_nixd_init_service/mod.rs
  • src/action/common/configure_init_service.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/action/common/configure_determinate_nixd_init_service/mod.rs

@cole-h cole-h force-pushed the sep-cole/nix-284-automatically-start-determinate-nix-daemon-after branch from 3239b5e to fa7231d Compare February 24, 2026 17:45
@grahamc grahamc merged commit 7ed5b7a into main Mar 5, 2026
19 checks passed
@grahamc grahamc deleted the sep-cole/nix-284-automatically-start-determinate-nix-daemon-after branch March 5, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upload to s3 The labeled PR is allowed to upload its artifacts to S3 for easy testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants