8000 feat: Headless CLI use by dhnaranjo · Pull Request #649 · nix-community/nix-init · GitHub
[go: up one dir, main page]

Skip to content

feat: Headless CLI use - #649

Closed
dhnaranjo wants to merge 12 commits into
nix-community:mainfrom
dhnaranjo:headless-cli
Closed

dhnaranjo wants to merge 12 commits into
nix-community:mainfrom
dhnaranjo:headless-cli

Conversation

@dhnaranjo
@dhnaranjo dhnaranjo commented Oct 13, 2025 •
Copy link
Copy Markdown

Add headless mode to nix-init, enabling fully non-interactive package
initialization through CLI flags. --headless requires --url, all other flags use the default value logic from the interactive flow.

I'mma be real with you, I am not a Rust guy and I did have heavy LLM involvement in this thing, but I did sit here and write it, no vibe nonsense. I stand by it, but it might not be super idiomatic Rust.

fixes #648

• --headless - Enable non-interactive mode (requires --url)
• --rev - Specify git revision, tag, or commit hash
• --version-name - Specify package version
• --pname - Specify package name
• --build - Specify build type (go-mod, python-app, python-pkg, rust-pkg, drv)
• --fetch-submodules - Control submodule fetching (defaults to false in headless mode)
• --force - Allow overwriting existing output files in headless mode

Add --headless flag that accepts defaults for all prompts except URL,
enabling automation and CI/CD integration.

When --headless is enabled:
- URL must be provided via --url (required)
- Package name must be auto-detected or provided
- Build type uses first auto-detected option
- Output path defaults to current directory
- Submodule fetching skipped by default
- File overwrite protection (errors instead of prompting)

Future commits will add flags to customize behavior in headless mode.
Introduce a macro to handle the repetitive pattern of:
- Use flag value if provided
- Use default value in headless mode
- Prompt user in interactive mode

Apply the macro to URL handling, replacing the early validation
with a more idiomatic error in the default branch.

This pattern will be used for all subsequent flag additions.
Add --rev flag to specify the git revision, tag, or commit hash
from the command line, making version selection non-interactive.

Uses the flag_or_prompt macro to integrate with headless mode,
falling back to the default revision in headless mode when not
specified.
Add new --pname/-p CLI flag that allows users to specify the package
name directly. Refactor pname handling to use flag_or_prompt! macro
for consistent behavior between headless and interactive modes.
Add --build flag to specify the build type from the command line,
making build system selection non-interactive.

Accepts short flag values:
  go-mod (buildGoModule)
  python-app (buildPythonApplication)
  python-pkg (buildPythonPackage)
  rust-pkg (buildRustPackage)
  drv (stdenv.mkDerivation)

Validates against detected options and provides clear error messages
listing available choices. In headless mode without --build, defaults
to the first auto-detected build type.
Add --version/-v flag to specify the package version from the command
line, allowing users to override auto-detected versions.

Uses the flag_or_prompt macro to integrate with headless mode. In
headless mode without --version, uses the auto-detected version
directly without confirmation.
Add --fetch-submodules flag to explicitly control whether git
submodules should be fetched.

Behavior:
- With --fetch-submodules: Always fetch submodules
- Without flag in headless mode: Skip submodules (default)
- Without flag in interactive mode: Prompt user
Add --force/-f flag to control file overwrite behavior in headless
mode.

Behavior:
- With --force: Silently overwrite existing files
- Without --force in headless mode: Error with helpful message
- In interactive mode: Prompt user (--force has no effect)

This provides safe defaults while allowing automation when needed.
Replace large pattern matching blocks with centralized methods in BuildType:
- Add cli_flag() to get flag name for each build type
- Add from_cli_flag() to parse flag string into BuildType
- Reduces ~60 lines of repetitive matching to ~15 lines
- Improves maintainability for adding new build types
- Error messages now automatically filter unavailable options
@figsoda
figsoda commented Dec 31, 2025
Copy link
Copy Markdown
Member

Thank you for working on this, and also being honest with the LLM usage. I have a few design differences I want to make, which will involve moving around a lot of code, so I figured it will probably be easier for me to create a new pull request rather than going through every single detail with reviews. I will open a new pull request soon in favor of this one explaining those details and why I made those decisions.

@figsoda figsoda closed this Dec 31, 2025
@figsoda figsoda mentioned this pull request Dec 31, 2025
@dhnaranjo
Copy link
Copy Markdown
Author

For sure, no stress. Glad it’s a useful jump off point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expose all parameters on the cli to allow unattended use

2 participants

0