Skip to content

nixos: add --install-bootloader for explicit bootloader installation#427

Merged
NotAShelf merged 1 commit intomasterfrom
notashelf/push-wkvoytrytsxr
Oct 1, 2025
Merged

nixos: add --install-bootloader for explicit bootloader installation#427
NotAShelf merged 1 commit intomasterfrom
notashelf/push-wkvoytrytsxr

Conversation

@NotAShelf
Copy link
Member

@NotAShelf NotAShelf commented Oct 1, 2025

NH previously supported passing NIXOS_INSTALL_BOOTLOADER variable to the switch-to-configuration, which in turn forced an installation of the bootloader. This behaviour was supported, but implcit. As per #424 we now support the --install-bootloader flag that makes this behaviour explicit and documented.

Change-Id: I6a6a69643f4b16816728dcaa6a66b675f9fe0ff2

Summary by CodeRabbit

  • New Features

    • Added a --install-bootloader flag to OS rebuild commands so users can explicitly request bootloader installation during a rebuild; default behavior unchanged unless the flag is set.
  • Documentation

    • Updated changelog entry describing the new --install-bootloader option.
  • Chores

    • Minor CLI logging and developer-facing improvements around environment handling and command assembly.

@coderabbitai
Copy link

coderabbitai bot commented Oct 1, 2025

Walkthrough

Adds Command::set_env builder to set a single environment variable; adds OsRebuildArgs::install_bootloader CLI flag; updates nixos rebuild flows to optionally inject NIXOS_INSTALL_BOOTLOADER=1, run a separate bootloader activation command, and log completion/debug info.

Changes

Cohort / File(s) Summary
Command builder / env API
src/commands.rs
Adds pub fn set_env<K, V>(mut self, key: K, value: V) -> Self which inserts EnvAction::Set into the command's env_vars map, enabling single-variable setting via the builder API.
CLI interface args
src/interface.rs
Adds pub install_bootloader: bool to OsRebuildArgs annotated with #[arg(long)] and a short doc comment, exposing --install-bootloader.
NixOS rebuild wiring & logging
src/nixos.rs
Refactors Test/Switch paths to build mutable cmd instances, adds debug log messages after operations, clones elevation/host where needed, and adds flow to construct/execute a separate switch-to-configuration command that conditionally calls set_env("NIXOS_INSTALL_BOOTLOADER","1") when install_bootloader is true; errors from bootloader activation are propagated with context.
Changelog
CHANGELOG.md
Documents the new --install-bootloader flag and rewraps an existing entry for nh os info.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant ORA as OsRebuildArgs
  participant MAIN as rebuild flow
  participant CMD as Command builder
  participant BOOT as switch_to_configuration cmd
  participant SH as Shell/Exec

  U->>ORA: invoke rebuild (test/switch) with args
  ORA->>MAIN: start rebuild
  MAIN->>CMD: build primary command (variant: test/switch)
  MAIN->>CMD: preserve_envs(["NIXOS_INSTALL_BOOTLOADER"])
  alt install_bootloader == true
    MAIN->>BOOT: build switch_to_configuration command
    BOOT->>BOOT: set_env("NIXOS_INSTALL_BOOTLOADER","1")
    BOOT->>SH: execute (with required env)
    SH-->>BOOT: result / error
    alt error
      BOOT-->>MAIN: propagate "Bootloader activation failed"
    end
  end
  CMD->>SH: execute primary command
  SH-->>MAIN: result
  MAIN->>U: log Completed {variant} (out_path)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the core change by stating that a new --install-bootloader flag is being added for explicit bootloader installation in the NixOS commands, matching the pull request’s primary objective without extraneous detail. It is clear, specific, and directly related to the main feature introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch notashelf/push-wkvoytrytsxr

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1df42 and b0a7b1c.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • src/commands.rs (1 hunks)
  • src/interface.rs (1 hunks)
  • src/nixos.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/interface.rs
  • src/commands.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/nixos.rs (1)
src/commands.rs (4)
  • new (156-167)
  • new (611-619)
  • new (733-742)
  • elevate (171-174)
⏰ 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). (6)
  • GitHub Check: Build NH on Linux
  • GitHub Check: Test NH on Linux
  • GitHub Check: treewide-checks
  • GitHub Check: Build NH on Linux
  • GitHub Check: Test NH on Linux
  • GitHub Check: treewide-checks

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.

❤️ Share

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

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f3920fd and 8d1df42.

📒 Files selected for processing (3)
  • src/commands.rs (1 hunks)
  • src/interface.rs (1 hunks)
  • src/nixos.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/nixos.rs (1)
src/commands.rs (4)
  • new (156-167)
  • new (611-619)
  • new (733-742)
  • elevate (171-174)
⏰ 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: Test NH on Linux
  • GitHub Check: Build NH on Linux
  • GitHub Check: Build NH on Linux
  • GitHub Check: Test NH on Linux
🔇 Additional comments (2)
src/nixos.rs (1)

320-336: Implementation looks correct.

The conditional environment variable injection works as expected. The set_env call (line 329) will override the preserve_envs entry (line 326) when install_bootloader is true, since both insert into the same HashMap. This ensures explicit control takes precedence over environment preservation.

Note: Consider whether the Boot variant (lines 338-347) should also support the --install-bootloader flag, as the Boot command typically installs the bootloader by setting it as the default boot option. The current implementation only covers Test and Switch.

src/commands.rs (1)

238-250: LGTM! Clean builder method implementation.

The set_env method follows the established builder pattern and correctly inserts an EnvAction::Set entry. The implementation is consistent with existing methods like preserve_envs and will work correctly with the environment application logic in apply_env_to_exec and build_sudo_cmd.

NH previously supported passing `NIXOS_INSTALL_BOOTLOADER` variable to
the `switch-to-configuration`, which in turn forced an installation of
the bootloader. This behaviour was supported, but implcit. As per #424
we now support the `--install-bootloader` flag that makes this behaviour
explicit and documented.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a69643f4b16816728dcaa6a66b675f9fe0ff2
@NotAShelf NotAShelf force-pushed the notashelf/push-wkvoytrytsxr branch from 8d1df42 to b0a7b1c Compare October 1, 2025 10:11
@NotAShelf NotAShelf merged commit f625021 into master Oct 1, 2025
9 of 13 checks passed
@NotAShelf NotAShelf deleted the notashelf/push-wkvoytrytsxr branch October 1, 2025 10:38
@coderabbitai coderabbitai bot mentioned this pull request Dec 24, 2025
2 tasks
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.

2 participants