feat: specify parameters for file and attribute for legacy-style CLIs#129
Conversation
WalkthroughThis PR adds legacy file-based configuration support across CLI commands (apply, install, option, repl): accepts FILE and ATTR positional args and --file/--attr flags in non-flake mode, resolves file paths via a new ResolveNixFilename utility, and extends LegacyConfiguration with explicit path and attribute handling used throughout configuration resolution and build flows. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant CLI as CLI command
participant Parser as Arg Parser
participant Util as ResolveNixFilename
participant Config as Config Resolver
participant Build as Build System
User->>CLI: invoke with [FILE] [ATTR]
CLI->>Parser: parse args / flags
alt Flake mode
Parser->>Config: create/use FlakeRef
Config->>Build: evaluate flake reference (URI#system)
else Non-flake mode
alt FILE provided (or --file)
Parser->>Util: ResolveNixFilename(FILE)
Util-->>Config: resolved absolute file path
Config->>Config: construct LegacyConfiguration{ConfigPath, Attribute, UseExplicitPath=true}
else no FILE
Config->>Config: discover config via NIXOS_CONFIG / NIX_PATH / env
Config->>Config: construct LegacyConfiguration{ConfigPath, UseExplicitPath=false, Includes}
end
Config->>Build: evaluate using LegacyConfiguration (explicit or discovered)
end
Build-->>User: result / output
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes
Areas needing extra attention:
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2025-10-20T02:59:26.118ZApplied to files:
🧬 Code graph analysis (4)cmd/option/option.go (3)
internal/configuration/legacy.go (3)
cmd/repl/repl.go (6)
internal/cmd/opts/opts.go (1)
⏰ 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). (1)
🔇 Additional comments (4)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
doc/man/nixos-cli-install.1.scd (1)
50-50: Fix typo in section heading."EXMAPLES" should be "EXAMPLES".
Apply this diff:
-# EXMAPLES +# EXAMPLES
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
cmd/apply/apply.go(5 hunks)cmd/install/install.go(6 hunks)cmd/option/option.go(3 hunks)cmd/repl/repl.go(7 hunks)doc/man/nixos-cli-apply.1.scd(3 hunks)doc/man/nixos-cli-install.1.scd(3 hunks)doc/man/nixos-cli-option.1.scd(2 hunks)doc/man/nixos-cli-repl.1.scd(2 hunks)internal/cmd/opts/opts.go(3 hunks)internal/configuration/configuration.go(3 hunks)internal/configuration/flake.go(1 hunks)internal/configuration/legacy.go(6 hunks)internal/utils/utils.go(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (7)
internal/configuration/flake.go (1)
internal/system/system.go (1)
System(9-14)
internal/cmd/opts/opts.go (1)
internal/configuration/flake.go (1)
FlakeRef(17-23)
cmd/apply/apply.go (4)
internal/build/vars/vars.go (1)
Flake(9-9)internal/build/build.go (1)
Flake(32-34)internal/utils/utils.go (1)
ResolveNixFilename(72-111)internal/configuration/legacy.go (1)
LegacyConfiguration(17-32)
cmd/option/option.go (3)
internal/configuration/flake.go (2)
FlakeRefFromString(25-52)FlakeRef(17-23)internal/utils/utils.go (1)
ResolveNixFilename(72-111)internal/configuration/legacy.go (1)
LegacyConfiguration(17-32)
cmd/install/install.go (5)
internal/cmd/opts/opts.go (1)
InstallOpts(153-166)internal/build/build.go (1)
Flake(32-34)internal/configuration/flake.go (1)
FlakeRef(17-23)internal/utils/utils.go (1)
ResolveNixFilename(72-111)internal/configuration/legacy.go (1)
LegacyConfiguration(17-32)
internal/configuration/legacy.go (3)
internal/utils/utils.go (1)
ResolveNixFilename(72-111)internal/system/runner.go (1)
CommandRunner(10-14)internal/configuration/configuration.go (1)
BuildType(71-73)
cmd/repl/repl.go (6)
internal/build/vars/vars.go (1)
Flake(9-9)internal/build/build.go (1)
Flake(32-34)internal/configuration/configuration.go (2)
Configuration(28-32)FindConfiguration(43-69)internal/configuration/flake.go (2)
FlakeRef(17-23)FlakeRefFromString(25-52)internal/utils/utils.go (1)
ResolveNixFilename(72-111)internal/configuration/legacy.go (1)
LegacyConfiguration(17-32)
⏰ 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). (1)
- GitHub Check: Build/Test
🔇 Additional comments (12)
doc/man/nixos-cli-install.1.scd (2)
9-16: Clear differentiation between CLI modes.The updated synopsis clearly distinguishes between flake-enabled and legacy CLIs, making it easier for users to understand which arguments apply to their use case.
111-130: Comprehensive FILE and ATTR documentation.The documentation for the new FILE and ATTR arguments is clear and thorough, including fallback behavior and usage notes.
doc/man/nixos-cli-option.1.scd (1)
48-68: Well-documented legacy CLI options.The --attr and --file options are clearly documented with appropriate fallback behavior and legacy CLI restrictions.
doc/man/nixos-cli-repl.1.scd (1)
48-65: Consistent documentation pattern.The FILE and ATTR argument documentation follows the same clear pattern established in other man pages, ensuring consistency across the CLI.
doc/man/nixos-cli-apply.1.scd (2)
47-56: Helpful legacy CLI examples.The examples demonstrate practical usage of FILE and ATTR arguments, including both simple file and attribute set scenarios.
101-120: Complete FILE and ATTR documentation.The argument documentation is thorough and consistent with the pattern used across all man pages.
internal/cmd/opts/opts.go (1)
24-28: Consistent field additions for legacy CLI support.The File and Attr fields are added consistently across option structs to support the new legacy CLI arguments.
internal/configuration/flake.go (1)
80-82: Simple and correct String() implementation.The String() method provides a standard string representation of FlakeRef in the format "URI#System", which is useful for logging and debugging.
internal/configuration/configuration.go (3)
40-40: Improved error diagnostics.Including the evaluation trace in the error message will help users debug configuration issues more effectively.
65-65: Updated logging for legacy configuration.The change from ConfigDirname to ConfigPath aligns with the new explicit path support in LegacyConfiguration.
79-81: Simplified BuildAttr() method.The method now unconditionally returns "toplevel". Ensure this simplification is intentional and doesn't affect any build scenarios where the previous conditional logic was necessary.
internal/utils/utils.go (1)
72-111: Well-implemented path resolution function.The ResolveNixFilename function correctly handles:
- File vs directory input
- Directory resolution to default.nix
- Validation that default.nix is not itself a directory
- Symlink resolution and absolute path conversion
The error handling is appropriate, propagating os.Stat errors and path resolution errors to the caller.
58249e3 to
e1e8172
Compare
For already-instantiated configurations, it can be hard to retrieve their values or build with them purely using Nix include arguments (aka
-I) or by setting$NIXOS_CONFIG.This gives users the explicit ability to pass already-instantiated user configurations as positional arguments, similar to flake refs, but for legacy-style configurations only, for the following commands:
nixos applynixos installnixos optionnixos replCloses #120.
Summary by CodeRabbit
New Features
Improvements
Documentation