Skip to content

generations: fix current generation flag for specialisations#519

Open
cloud-yu wants to merge 3 commits intonix-community:masterfrom
cloud-yu:fix-current
Open

generations: fix current generation flag for specialisations#519
cloud-yu wants to merge 3 commits intonix-community:masterfrom
cloud-yu:fix-current

Conversation

@cloud-yu
Copy link
Copy Markdown
Contributor

@cloud-yu cloud-yu commented Jan 4, 2026

Hi,
this pr is for #508

Sanity Checking

  • I have updated the changelog as per my changes
  • I have tested, and self-reviewed my code
  • Style and consistency
    • I ran nix fmt to format my Nix code
    • I ran cargo fmt to format my Rust code
    • I have added appropriate documentation to new code
    • My changes are consistent with the rest of the codebase
  • Correctness
    • I ran cargo clippy and fixed any new linter warnings.
  • If new changes are particularly complex:
    • My code includes comments in particularly complex areas to explain the
      logic
    • I have documented the motive for those changes in the PR body or commit
      description.
  • Tested on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin

Add a 👍 reaction to pull requests you find important.

Summary by CodeRabbit

  • New Features

    • nh os info now shows the current-generation flag when run with a specialization.
  • Bug Fixes

    • Active specialization is now marked with an asterisk (*) while other specializations are shown without per-item prefixes for clearer output.
    • Improved detection of the active generation so the info output reliably reflects which generation is current.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 4, 2026

Walkthrough

Switches current-generation detection from /run/current-system to /nix/var/nix/profiles/system, changes active specialisation identification to compare canonical paths so only the active one is prefixed with *, and updates CLI specialisation output formatting and changelog entry.

Changes

Cohort / File(s) Change Summary
Documentation
CHANGELOG.md
Adds release notes: nh os info shows current-generation flag when run with a specialisation; specialisations are prefixed with * only when active.
Generation / Specialisation Logic
src/generations.rs
Replace /run/current-system lookup with canonical comparison against /nix/var/nix/profiles/system; require canonical existence+match for current-generation detection; mark only the active specialisation with * by comparing canonical targets; change print_info() formatting to join specialisation names without per-item prefixes.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • NotAShelf

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 clearly and specifically describes the main fix: correcting the current generation flag behavior for specialisations, which aligns directly with the primary changes in both CHANGELOG.md and src/generations.rs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

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.

coderabbitai[bot]

This comment was marked as off-topic.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@NotAShelf NotAShelf changed the title fix current generation flag when running a specialisation build generations: fix current generation flag for specialisations Jan 4, 2026
Copy link
Copy Markdown
Member

@NotAShelf NotAShelf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two tiny nits, code LGTM otherwise.

Comment thread src/generations.rs Outdated
let specialisations = {
let specialisation_path = generation_dir.join("specialisation");
if specialisation_path.exists() {
// Only prefixed specialisation name by '*' when it's currently actived
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Only prefixed specialisation name by '*' when it's currently actived
// Only prefix specialisation name with '*' when it's currently active

Comment thread CHANGELOG.md Outdated
Comment on lines +55 to +57
- `nh os info` now shows the current generation flag,
when activated with a specialisation [#508](https://github.com/nix-community/nh/issues/508).
`nh os info` now only prefixes the specialisation name with '\*' when the specialisation is activated.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `nh os info` now shows the current generation flag,
when activated with a specialisation [#508](https://github.com/nix-community/nh/issues/508).
`nh os info` now only prefixes the specialisation name with '\*' when the specialisation is activated.
- `nh os info` now shows the current generation flag,
when activated with a specialisation [#508](https://github.com/nix-community/nh/issues/508).
- `nh os info` now only prefixes the specialisation name with '\*' when the specialisation is activated.

I don't quite understand the first sentence. What's the "current generation flag" ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, a prefix '' is used to every specialisation name. This is confusing, I can't recognize which specialisation i'm using. whether i'm using a specialisation or not ?
So, I changed this, only prefix '
' to the specialisation name currently activate.
image

Copy link
Copy Markdown

@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

♻️ Duplicate comments (1)
CHANGELOG.md (1)

55-57: Changelog entry looks good after typo fixes.

The previous review flagged "actived" typos which have been corrected to "activated". The wording now accurately describes the fix for issue #508.

🧹 Nitpick comments (1)
src/generations.rs (1)

260-277: Hoist fs::canonicalize("/run/current-system") outside the loop.

fs::canonicalize("/run/current-system") is called for every entry in the iterator. This filesystem operation should be computed once before the loop.

🔎 Proposed fix
     let specialisation_path = generation_dir.join("specialisation");
     if specialisation_path.exists() {
       // Only prefix specialisation name with '*' when it's currently active
+      let current_system = fs::canonicalize("/run/current-system").ok();
       let specs = fs::read_dir(specialisation_path)
         .map(|entries| {
           let mut specs_vec = entries
             .filter_map(Result::ok)
             .filter_map(|e| {
-              if fs::canonicalize(e.path()).ok()
-                == fs::canonicalize("/run/current-system").ok()
-              {
+              if fs::canonicalize(e.path()).ok() == current_system {
                 Some(format!("*{}", e.file_name().into_string().ok()?))
               } else {
                 e.file_name().into_string().ok()
               }
             })
             .collect::<Vec<String>>();
           specs_vec.sort();
           specs_vec
         })
         .unwrap_or_default();
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d961f9 and 7321d83.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/generations.rs
⏰ 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: Build NH on Linux
  • GitHub Check: Build NH on Darwin
  • GitHub Check: treewide-checks
  • GitHub Check: Test NH on Linux
  • GitHub Check: Test NH on Darwin
🔇 Additional comments (2)
src/generations.rs (2)

286-292: Current generation detection logic looks correct.

Using /nix/var/nix/profiles/system instead of /run/current-system correctly identifies the current generation even when a specialisation is active. The guard run_current_target.is_some() prevents false positives when both paths fail to canonicalize.


423-426: LGTM!

Clean formatting change that joins specialisations with spaces, correctly displaying the * prefix for active ones.

@faukah faukah linked an issue Jan 23, 2026 that may be closed by this pull request
2 tasks
@github-actions github-actions bot deleted the fix-current branch March 1, 2026 05:19
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.

nh os info silently exited when running nixos is a specialisation generation

3 participants