Skip to content

Conversation

@fidgetingbits
Copy link
Contributor

In the event that there is some systemd inhibitor in place, the use of 2>&1
from commit 4d55f9e (#577), hides the error: 'Call to Reboot failed: Access
denied'. To address that, I've added a check for inhibitors and a more explicit
warning.

In the event of an inhibitor being present, the new output is:

### Rebooting ###
Pseudo-terminal will not be allocated because stdin is not a terminal.
WARNING: Reboot is currently inhibited. Manual reboot may be required. Run 'systemd-inhibit --list' on the target details
Pseudo-terminal will not be allocated because stdin is not a terminal.
### Waiting for the machine to become unreachable due to reboot ###

If --debug is in use, then it will also print the full list of inhibitors
from systemd-inhibit --list, for example:

+ [[ 1 == 1 ]]
+ nixosReboot
+ step Rebooting
+ echo '### Rebooting ###'
### Rebooting ###
+ local inhibited
+ set +x
Pseudo-terminal will not be allocated because stdin is not a terminal.
WARNING: Reboot is currently inhibited. Manual reboot may be required. Run 'systemd-inhibit --list' on the target for further details
SSH COMMAND: ssh -t -o IdentitiesOnly=yes -i /tmp/tmp.vTDgb8CP5H/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022 root@moth.memeoid.cx sh

WHO            UID  USER  PID  COMM            WHAT                                                     WHY                                       MODE
Disk Manager   0    root  1659 udisksd         shutdown:sleep:idle                                      Unknown (mdraid-sync-job)                 block
ModemManager   0    root  1850 ModemManager    sleep                                                    ModemManager needs to reset devices       delay
NetworkManager 0    root  1119 NetworkManager  sleep                                                    NetworkManager needs to turn off networks delay
UPower         0    root  1532 upowerd         sleep                                                    Pause device polling                      delay
GNOME Shell    1001 nixos 1431 .gnome-shell-wr sleep                                                    GNOME needs to lock the screen            delay
GNOME Shell    1001 nixos 1431 .gnome-shell-wr sleep                                                    GNOME needs to save screen time data      delay
nixos          1001 nixos 1554 .gsd-media-keys handle-power-key:handle-suspend-key:handle-hibernate-key GNOME handling keypresses                 block
nixos          1001 nixos 1554 .gsd-media-keys sleep                                                    GNOME handling keypresses                 delay
nixos          1001 nixos 1556 .gsd-power-wrap sleep                                                    GNOME needs to lock the screen            delay

9 inhibitors listed.
+ runSsh sh
+ set +x

We could consider a new option that lets you to force systemctl reboot -i to
ignore inhibitors during reboot, but I haven't included that for now. Also I
don't bother exiting if an inhibitor is detected because we don't know for
certain atm the inhibitor runs long enough to actually stop the subsequent
reboot, so seems worth trying.

On example where there might be an inhibitor is if you are installing a raid
array using mdadm it can automatically trigger a multi-hour (dependent on disk
size) scan after initial configuration of the by disko.

@coderabbitai
Copy link

coderabbitai bot commented Nov 3, 2025

Walkthrough

Adds two new facts, hasGrep and hasSystemdInhibit, to the facts collection and validation. Inserts a pre-reboot inhibition check into nixosReboot: when both facts are "y", the script temporarily suppresses debug output, runs a remote systemd-inhibit --list | grep 'shutdown' check, captures and logs any inhibitor output, prints inhibitor details if debug is enabled, and then restores debug. The inhibition check is added in both copies of nixosReboot.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Add check and warning for reboot inhibitor' clearly and specifically summarizes the main change—adding inhibitor detection and warnings during reboot operations.
Description check ✅ Passed The description comprehensively explains the motivation, implementation details, and expected behavior of the reboot inhibitor check feature, with concrete examples of output in both debug and non-debug modes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 8dd264c and e2bdca4.

📒 Files selected for processing (2)
  • src/get-facts.sh (1 hunks)
  • src/nixos-anywhere.sh (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/get-facts.sh
🔇 Additional comments (4)
src/nixos-anywhere.sh (4)

60-61: Fact declarations properly integrated.

The new facts follow the existing naming convention and are correctly positioned within the facts collection.


590-590: Validation correctly enforces new fact availability.

Adding hasGrep and hasSystemdInhibit to the validation loop ensures both capabilities are detected before use in the reboot phase.


917-942: The review comment is based on a false premise and should be disregarded.

The verification confirms there is only ONE nixosReboot() function definition in the entire codebase (line 917 in src/nixos-anywhere.sh). The AI summary's claim about "both the original nixosReboot implementation and the later duplicate copy" is incorrect—no duplicate exists. The inhibitor-check logic is present once, not duplicated across multiple function copies.

Likely an incorrect or invalid review comment.


917-942: No issues found—code logic is correct and efficient.

The verification confirms:

  • Single nixosReboot definition exists at line 917 (no duplication).
  • The systemd-inhibit --list output includes a WHAT column showing operations like "shutdown", validating the grep pattern.
  • The output capture flow (grep check before fetching full list) is an efficiency optimization, not a bug.
  • Error handling via set -euo pipefail is sound.

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.

@fidgetingbits
Copy link
Contributor Author

If you want to test the new code with an inhibitor in place you can run systemd-inhibit --mode=block --what=shutdown sh -c 'sleep 10000' or similar on the target before running nixos-anywhere.

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