WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@Mic92
Copy link
Member

@Mic92 Mic92 commented Sep 29, 2025

Summary by CodeRabbit

  • Refactor

    • Consolidated remote kexec flow into a single self-contained script uploaded and executed on the remote host for improved isolation and robustness.
    • Standardized operations to run from the remote user’s home directory and added an early guard to verify it.
    • Switched to uploading and unpacking artifacts remotely rather than piping commands.
  • Bug Fixes

    • More reliable failure detection by treating missing success indicators as errors.
    • Always fetches and displays remote logs on failure via a simplified failure handler for clearer diagnostics.

@coderabbitai
Copy link

coderabbitai bot commented Sep 29, 2025

Walkthrough

Updates kexec flow in src/nixos-anywhere.sh: replaces handleKexecResult with handleKexecFailure, resolves remoteHomeDir early, uploads the kexec tarball, creates and runs a remote unpack.sh that extracts and runs kexec while tee‑ing output to a remote log, and treats missing success indicators as failures requiring log retrieval.

Changes

Cohort / File(s) Summary of changes
Kexec flow refactor and error handling
src/nixos-anywhere.sh
Renamed/changed error handler to handleKexecFailure(operation); added early remoteHomeDir resolution; uploads kexec tarball to remoteHomeDir; replaces multiple incremental SSH commands with a generated remote unpack.sh that creates dirs, extracts the tarball (strategy based on tarDecomp), runs kexec, and tees output to a remote log; success now validated by presence of the expected success marker (missing marker treated as failure); always fetches/displays remote log on failure; removed handleKexecResult and updated control flow accordingly.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant L as Local (nixos-anywhere.sh)
  participant R as Remote host
  participant S as Remote script (unpack.sh)
  participant K as kexec/installer
  participant LOG as remote log

  Note over L: prepare kexec tarball and resolve remoteHomeDir
  L->>R: scp tarball -> remoteHomeDir
  L->>R: ssh write unpack.sh into remoteHomeDir
  L->>R: ssh chmod +x unpack.sh

  rect rgb(240,250,240)
    Note over R,S: consolidated remote execution (dirs, extract, run)
    L->>R: ssh execute ./unpack.sh
    S->>LOG: tee all output to remote log
    S->>K: run kexec installer
    K-->>S: exit status + output
  end

  alt Expected success marker present
    S-->>R: exit 0 and success marker in LOG
    R-->>L: ssh exit 0
  else Missing marker or non-zero exit
    S-->>R: non-zero or missing marker
    R-->>L: ssh exit non-zero
    L->>R: scp/fetch remote LOG
    L-->>L: handleKexecFailure(operation) -> exit non-zero
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The pull request title "fix regression when installing on systems with dash" describes fixing a compatibility issue with the dash shell, but the raw summary of changes makes no mention of dash, shell compatibility issues, or any regression fixes. Instead, the summary describes a significant refactoring of the kexec error handling logic, consolidating remote command execution, renaming functions (handleKexecResult to handleKexecFailure), and changing the remote execution strategy to use a script-on-remote approach. The title appears to be unrelated to the actual changeset described, as there is no evidence in the summary that any of these modifications specifically address dash compatibility or fix a regression related to it. The title should be updated to accurately reflect the main changes in the pull request. Based on the summary, a more appropriate title would describe the refactoring of kexec error handling and remote command execution, such as "refactor kexec error handling and consolidate remote execution" or "simplify kexec failure handling with script-based remote execution". If the changes truly do fix a dash-related regression, the connection between the code modifications and the dash compatibility issue should be evident in the changeset description.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_password_prompt

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

Tip

🧪 Early access (models): enabled

We are currently testing Sonnet 4.5 code review models, which should lead to better review quality. However, this model may result in higher noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

@Mic92 Mic92 force-pushed the fix_password_prompt branch from 167fd42 to 2269a1d Compare September 29, 2025 18:17
@Mic92 Mic92 force-pushed the fix_password_prompt branch from 2269a1d to 086921a Compare September 29, 2025 18:21
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/nixos-anywhere.sh (1)

752-771: Critical: print command not available in dash/bash.

Line 763 uses print '%q' "$kexecExtraFlags" which is not available in dash or bash. The PR title mentions fixing a regression on systems with dash, but this would fail on such systems. Use printf instead.

Apply this diff:

-  TMPDIR=\"$remoteHomeDir/kexec\" ${maybeSudo} setsid --wait \"$remoteHomeDir/kexec/kexec/run\" --kexec-extra-flags $(print '%q' "$kexecExtraFlags")
+  TMPDIR=\"$remoteHomeDir/kexec\" ${maybeSudo} setsid --wait \"$remoteHomeDir/kexec/kexec/run\" --kexec-extra-flags $(printf '%q' "$kexecExtraFlags")
🧹 Nitpick comments (2)
src/nixos-anywhere.sh (2)

746-749: Redundant validation check.

The remoteHomeDir variable is already validated in importFacts() at lines 589-593, which is called before runKexec() in the execution flow. This check at line 747 will never trigger because the script would have already aborted earlier if remoteHomeDir were empty.

Consider removing this redundant check:

-  # Extract directly to the user's home directory
-  if [[ -z $remoteHomeDir ]]; then
-    abort "Could not determine home directory for user $sshUser"
-  fi
-

800-810: Consider cleanup of uploaded tarball.

When uploading the kexec tarball to $remoteHomeDir/kexec-tarball.tar.gz (line 807), the file is left on the remote system after extraction. While not critical, adding cleanup would save disk space.

Consider adding cleanup to the remote script template by appending to line 762:

   # Execute tar command
   %TAR_COMMAND%
+  rm -f \"$remoteHomeDir\"/kexec-tarball.tar.gz
   TMPDIR=\"$remoteHomeDir/kexec\" ${maybeSudo} setsid --wait \"$remoteHomeDir/kexec/kexec/run\" --kexec-extra-flags $(printf '%q' "$kexecExtraFlags")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 167fd42 and 2269a1d.

📒 Files selected for processing (1)
  • src/nixos-anywhere.sh (2 hunks)
🔇 Additional comments (2)
src/nixos-anywhere.sh (2)

729-744: LGTM! Cleaner failure handling.

The refactored function simplifies the signature by removing the exit code parameter and always treating calls as failures. The log retrieval with debug suppression is well done.


812-819: LGTM! Clean script generation and execution.

The approach of generating a complete script remotely and then executing it improves robustness and makes debugging easier. The error handling with handleKexecFailure is appropriate.

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: 0

🧹 Nitpick comments (2)
src/nixos-anywhere.sh (2)

746-749: Clarify error message variable.

The error message references $sshUser, but this variable represents the SSH connection user. Consider whether this is the most appropriate variable name in this context, or if a more descriptive message would be clearer.

Apply this diff to improve clarity:

-  if [[ -z $remoteHomeDir ]]; then
-    abort "Could not determine home directory for user $sshUser"
-  fi
+  if [[ -z $remoteHomeDir ]]; then
+    abort "Could not determine remote home directory"
+  fi

800-810: Review tar command construction and upload logic.

The logic correctly handles both local and remote download scenarios:

  • Remote download: constructs a command that downloads and extracts in one pipe
  • Local upload: uploads the tarball first, then extracts from the uploaded file

One minor observation: when uploading locally (line 807), the file is always named kexec-tarball.tar.gz regardless of the actual compression format. While this doesn't affect functionality (since the tarDecomp flag explicitly specifies the format), it could be slightly confusing.

Consider using a more accurate filename:

-    "${localUploadCommand[@]}" | runSsh "cat > \"$remoteHomeDir\"/kexec-tarball.tar.gz"
+    local tarballName="kexec-tarball.tar${kexecUrl##*.tar}"
+    "${localUploadCommand[@]}" | runSsh "cat > \"$remoteHomeDir\"/\"$tarballName\""
     # Use local file for extraction
-    tarCommand="cat \"$remoteHomeDir\"/kexec-tarball.tar.gz | tar -xv ${tarDecomp}"
+    tarCommand="cat \"$remoteHomeDir\"/\"$tarballName\" | tar -xv ${tarDecomp}"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2269a1d and 086921a.

📒 Files selected for processing (1)
  • src/nixos-anywhere.sh (2 hunks)
🔇 Additional comments (3)
src/nixos-anywhere.sh (3)

729-744: LGTM!

The simplified handleKexecFailure function correctly attempts to fetch and display the remote log before exiting. The error suppression when fetching the log is appropriate for handling cases where the log file doesn't exist.


754-771: Verify the remote command template logic.

The template wraps kexec execution in a subshell with error handling. A few observations:

  1. Line 764 uses || true to prevent the script from exiting immediately, allowing the log to be captured even on failure.
  2. Lines 767-770 check for the absence of the success message and treat it as failure - this inverts the typical success-checking pattern.

While this approach should work, ensure that the success message "machine will boot into nixos" is reliably written to the log before the kexec disconnects the SSH session.


816-819: LGTM! Bash execution ensures compatibility.

The script creation and execution correctly:

  1. Creates the remote unpack.sh script via heredoc
  2. Executes it explicitly with bash (not sh), ensuring bash-specific features in the template work correctly
  3. Handles failures by calling handleKexecFailure

This approach addresses the regression mentioned in the PR title by ensuring bash (not dash or another POSIX shell) interprets the script.

@Mic92 Mic92 added this pull request to the merge queue Sep 29, 2025
Merged via the queue into main with commit 3f514df Sep 29, 2025
5 checks passed
@Mic92 Mic92 deleted the fix_password_prompt branch September 29, 2025 18:29
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