installable: drop state passing via environment variables#550
Conversation
WalkthroughIntroduce a public CommandContext enum and Installable::resolve(CommandContext) to centralize context-aware NH_FLAKE resolution; replace scattered NH_FLAKE and NH_CURRENT_COMMAND handling with resolve calls across darwin.rs, home.rs, nixos.rs, and remove env-mutation side effects in interface.rs. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI (nh)
participant Interface as Interface (dispatch)
participant Installable as Installable::resolve
participant Env as Environment (NH_*_FLAKE)
participant Command as Command.run
CLI->>Interface: invoke command
Interface->>Installable: resolve(context)
Installable->>Env: read prioritized env vars (context-specific)
Env-->>Installable: env value or none
Installable-->>Interface: resolved Installable (or Unspecified)
Interface->>Command: run with resolved Installable
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
91d190e to
e004d20
Compare
NotAShelf
left a comment
There was a problem hiding this comment.
LGTM overall, leaving a quick comment a few typos that I'd like for you to fix before I'm on my desktop to review properly.
e004d20 to
c82629a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/installable.rs`:
- Around line 308-368: The code currently consumes NH_*_FLAKE in
Installable::from_arg_matches_mut before Installable::resolve runs, allowing
global env vars to bypass CommandContext-specific precedence; change
from_arg_matches_mut to not read or consume any NH_*_FLAKE env vars (leave the
Installable as Unspecified when no explicit CLI/arg provided) and let
Installable::resolve(context: CommandContext) perform all NH_*_FLAKE
parsing/selection (or, if you prefer, re-run resolve when an env-derived value
is detected) so that NH_OS_FLAKE / NH_HOME_FLAKE / NH_DARWIN_FLAKE take
precedence per CommandContext; also update the resolve() docstring to document
that Ok(Unspecified) is returned when no env/default is present.
🧹 Nitpick comments (1)
src/installable.rs (1)
759-1119: Consider restoring pre‑existing env vars in tests.
These tests mutateNH_*_FLAKEbut don’t restore prior values, so a CI/dev environment with those vars set can leak state across tests. A small snapshot/restore guard would make this suite more robust.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@src/darwin.rs`:
- Around line 103-109: The call to update() is passing the unresolved CLI
installable (&self.common.installable) which can be Unspecified when
NH_DARWIN_FLAKE/NH_FLAKE is used; change the call to pass the resolved
installable (&installable) instead so update() receives the concrete value
(match the fix used in home.rs and the pattern in nixos.rs), i.e., locate the
block where update(&self.common.installable, ...) is invoked in the darwin
update flow and replace the first argument with &installable.
In `@src/home.rs`:
- Around line 84-90: The call to update(...) is passing the unresolved CLI value
(&self.common.installable) which can be Unspecified; change it to pass the
resolved installable (the toplevel variable computed earlier) so update() sees a
Flake variant — i.e., replace &self.common.installable with &toplevel (or
whatever the resolved installable binding is) in the update(...) invocation
while keeping the same update_args and commit_lock_file arguments.
In `@src/nixos.rs`:
- Around line 650-656: rebuild_and_activate() currently ignores OsRebuildArgs
update flags; mirror the build_only() behavior by invoking update(&toplevel,
self.update_args.update_input.clone(), self.common.passthrough.commit_lock_file)
when self.update_args.update_all || self.update_args.update_input.is_some().
Locate rebuild_and_activate(), add the same conditional update() call (using the
same toplevel, update_args, and commit_lock_file symbols as in build_only()),
and propagate any returned Result/handle the ? operator consistent with the
surrounding function.
88ba3db to
7d675da
Compare
Sanity Checking
nix fmtto format my Nix codecargo fmtto format my Rust codecargo clippyand fixed any new linter warnings.logic
description.
x86_64-linuxaarch64-linuxx86_64-darwinaarch64-darwinAdd a 👍 reaction to pull requests you find important.
Summary by CodeRabbit
Refactor
Bug Fixes