generations: fix current generation flag for specialisations#519
generations: fix current generation flag for specialisations#519cloud-yu wants to merge 3 commits intonix-community:masterfrom
Conversation
WalkthroughSwitches current-generation detection from Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
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. Comment |
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
NotAShelf
left a comment
There was a problem hiding this comment.
Two tiny nits, code LGTM otherwise.
| let specialisations = { | ||
| let specialisation_path = generation_dir.join("specialisation"); | ||
| if specialisation_path.exists() { | ||
| // Only prefixed specialisation name by '*' when it's currently actived |
There was a problem hiding this comment.
| // Only prefixed specialisation name by '*' when it's currently actived | |
| // Only prefix specialisation name with '*' when it's currently active |
| - `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. |
There was a problem hiding this comment.
| - `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" ?
There was a problem hiding this comment.
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: Hoistfs::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
📒 Files selected for processing (2)
CHANGELOG.mdsrc/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/systeminstead of/run/current-systemcorrectly identifies the current generation even when a specialisation is active. The guardrun_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.

Hi,
this pr is for #508
Sanity Checking
nix fmtto format my Nix codecargo fmtto format my Rust codecargo clippyand fixed any new linter warnings.logic
description.
x86_64-linuxaarch64-linuxx86_64-darwinaarch64-darwinAdd a 👍 reaction to pull requests you find important.
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.