-
-
Notifications
You must be signed in to change notification settings - Fork 75
darwin: fix activation without darwin-rebuild #416
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughDetects darwin-rebuild presence and new vs legacy activation in src/darwin.rs, conditionally runs either Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant CLI as CLI
participant FS as Filesystem
participant Sudo as Elevation
participant Shell as System Shell
User->>CLI: trigger activation
CLI->>FS: stat `darwin-rebuild`
alt darwin-rebuild exists
CLI->>FS: inspect `activate-user` (detect new activation)
CLI->>CLI: set uses_new_activation, should_elevate
alt should_elevate
CLI->>Sudo: run `darwin-rebuild activate`
Sudo->>Shell: execute activation
else
CLI->>Shell: run `darwin-rebuild activate`
end
else darwin-rebuild missing
CLI->>FS: inspect `out_path/activate` and `activate-user`
CLI->>CLI: set uses_new_activation=false, should_elevate=true
CLI->>Sudo: run `out_path/activate`
Sudo->>Shell: execute activation
opt legacy user activation (not uses_new_activation)
CLI->>Shell: run `out_path/activate-user`
end
end
note over CLI,Shell: Errors include contextual messages for activation vs user activation failures
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45–60 minutes Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. ✨ Finishing Touches
🧪 Generate unit tests
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/darwin.rs (1)
176-182
: Short-circuit file read is correct; consider non-UTF8 safety.Using
||
short-circuits when file is absent. If you want to be extra defensive against unexpected non-UTF8 contents, switch tofs::read(..).map(|b| String::from_utf8_lossy(&b).contains("deprecated"))
to avoid a hard error on encoding.- let uses_new_activation = !activate_user - .try_exists() - .context("Failed to check if activate-user file exists")? - || std::fs::read_to_string(&activate_user) - .context("Failed to read activate-user file")? - .contains("# nix-darwin: deprecated"); + let uses_new_activation = !activate_user + .try_exists() + .context("Failed to check if activate-user file exists")? + || { + let bytes = std::fs::read(&activate_user) + .context("Failed to read activate-user file")?; + std::str::from_utf8(&bytes) + .map(|s| s.contains("# nix-darwin: deprecated")) + .unwrap_or_else(|_| String::from_utf8_lossy(&bytes).contains("# nix-darwin: deprecated")) + };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CHANGELOG.md
(1 hunks)src/darwin.rs
(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check formating & lints
src/darwin.rs
[error] 172-172: cargo fmt --check reported formatting differences in src/darwin.rs. Run 'cargo fmt' to fix the formatting.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Test NH on Darwin
- GitHub Check: Build NH on Darwin
- GitHub Check: Build NH on Linux
- GitHub Check: Test NH on Linux
🔇 Additional comments (6)
CHANGELOG.md (1)
17-23
: Changelog entry reads well and matches behavior.Clear, user-facing description of the Darwin activation fallback. No issues.
src/darwin.rs (5)
170-174
: Presence check for darwin-rebuild: LGTM.Good use of try_exists with contextual errors.
183-188
: Potential mutability requirement for builder variable.If
commands::Command
builder methods take&mut self
(common),activation
should bemut
. If they takeself
by value, current code is fine. Please confirm.- let activation = if has_darwin_rebuild { + let mut activation = if has_darwin_rebuild { Command::new(darwin_rebuild).arg("activate") } else { Command::new(out_path.join("activate")) };
189-199
: Elevation logic looks correct and matches PR intent.
should_elevate = uses_new_activation || !has_darwin_rebuild
aligns with root-only activation in newer nix-darwin and legacy script fallback. Nice use ofthen_some(elevation)
to avoid unnecessary cloning.
200-208
: Fallback to activate-user only when not using darwin-rebuild: LGTM.This matches the stated requirement (“ensure activate-user is invoked when non-deprecated activate is used”). Error context is clear.
170-208
: Normalize code formatting with cargo fmtCI is failing due to formatting differences. Please run
cargo fmt
locally and commit the resulting changes to unblock CI.
34da5b0
to
a7e5346
Compare
Made the comment shorter so it passes the format CI check. Idk what all this AI stuff is I've never seen it before, not sure what I'm supposed to do with it exactly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/darwin.rs (1)
190-191
: Consider documenting the elevation logic.The elevation condition
uses_new_activation || !has_darwin_rebuild
may not be immediately obvious. While the logic is correct (elevate for new-style activation OR when using the fallback path), a comment explaining this would improve maintainability.Add a clarifying comment:
+// Elevate privileges when: +// - Using new activation style (which requires elevation), OR +// - Using fallback activation without darwin-rebuild (legacy behavior) let should_elevate = uses_new_activation || !has_darwin_rebuild;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CHANGELOG.md
(1 hunks)src/darwin.rs
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- CHANGELOG.md
🧰 Additional context used
🧬 Code graph analysis (1)
src/darwin.rs (1)
src/commands.rs (3)
new
(156-167)new
(597-605)new
(719-728)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: treewide-checks
- GitHub Check: Build NH on Darwin
- GitHub Check: Build NH on Linux
- GitHub Check: Test NH on Linux
- GitHub Check: Test NH on Darwin
🔇 Additional comments (5)
src/darwin.rs (5)
170-174
: LGTM! Proper runtime detection of darwin-rebuild.The code correctly checks for darwin-rebuild presence at runtime using
try_exists()
with appropriate error handling. This enables the fallback behavior when darwin-rebuild is not available.
175-183
: LGTM! Well-implemented activation style detection.The logic correctly identifies the new activation style by checking both the absence of
activate-user
and the presence of the deprecation marker. The error handling for file operations is appropriate.
184-189
: LGTM! Clean conditional activation path selection.The conditional logic properly selects between
darwin-rebuild activate
when available or falls back to the directactivate
script. This maintains backward compatibility while supporting the new activation style.
192-200
: LGTM! Proper activation execution with clear messaging.The activation command is executed with appropriate elevation, dry-run support, and clear user messaging. The error context "Darwin activation failed" helps with debugging.
201-209
: LGTM! Correct fallback for legacy user activation.The code properly handles the legacy case where
activate-user
needs to be run separately when darwin-rebuild is not available and the old activation style is in use. The distinct error message helps differentiate between main and user activation failures.
You may disregard the AI comments. I'm currently looking to see if it provides helpful comments that help guide my reviews (as the sole maintainer) or if it creates useless noise. Outlook not so good. I'll take a review later today. Please feel free to remind me with a ping if I forget. Also CC @khaneliman as someone more aware of nix-darwin's internals. |
I mean, it was a deliberate choice #238 (comment) |
I see. So should I add a warning about it and mark that it will be removed in the future? (v5.0.0) |
As part of supporting the new nix-darwin activation style in #238, there was a breaking change made to use
darwin-rebuild
instead of calling the activation scripts directly. Unfortunately this change meant it was no longer meant to usenh
as adarwin-rebuild
replacement, as it would depend ondarwin-rebuild
itself. So ifdarwin-rebuild
was disabled (e.g. by settingsystem.tools.enable = false
),nh
would fail to activate the system with an error like the following:This PR simply adds a check whether
darwin-rebuild
exists, and if not, falls back to the old behavior.(If it's undesirable for this configuration to be supported then perhaps a warning should be added when
activate
is used, but I think compatibility should be kept at least for now, because it was done in a minor release, and breaking changes should only happen in major releases according to semver (which is why marked it as a bug fix, since it's fixing a regression from a semver point of view))Tested in the following cases:
darwin-rebuild
by defaultactivate
ifdarwin-rebuild
doesn't existactivate-user
if it's the non-deprecated version and it invokedactivate
Sanity Checking
nix fmt
to format my Nix codecargo fmt
to format my Rust codecargo clippy
and fixed any new linter warnings.logic
description.
x86_64-linux
aarch64-linux
x86_64-darwin
aarch64-darwin
Add a 👍 reaction to pull requests you find important.
Summary by CodeRabbit
Bug Fixes
Documentation