Skip to content

Conversation

@neunenak
Copy link
Contributor

@neunenak neunenak commented Nov 25, 2025

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

    • Search results now show clickable links to package files on the nixpkgs GitHub for easier navigation.
    • Flakes-based systems produce properly formatted, unbroken links in search results.
  • Bug Fixes / Improvements

    • Terminal hyperlink handling now adapts automatically and consistently; malformed or missing position info now emits a warning.

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

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Warning

Rate limit exceeded

@neunenak has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3e11c0c and 35d3723.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • src/search.rs (4 hunks)

Walkthrough

Updates add terminal hyperlink handling and flake-aware nixpkgs path resolution so search output prints file:// and GitHub links for package positions, with fallbacks when hyperlinks or flake resolution are unavailable. CHANGELOG documents the user-visible changes.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added changelog entries: search now shows links to package.nix on the nixpkgs GitHub and creates unbroken links on nix flakes systems.
Search feature implementation
src/search.rs
Added GITHUB_NIXPKGS_URL; introduced lazy global cache HYPERLINKS_SUPPORTED and print_hyperlink(text, link); reworked nixpkgs path resolution to try nix eval -f <nixpkgs> path then fallback to nix eval --raw {flake_ref}#path; always uses print_hyperlink for homepage and defined-at positions, prints file:// paths and GitHub links, emits warnings on malformed positions, and improved debug logging.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NH as "nh search"
    participant Hyper as "Hyperlink Support (lazy)"
    participant Resolver as "Nixpkgs Path Resolver"
    participant Formatter as "Output Formatter"

    User->>NH: run search
    NH->>Hyper: ensure HYPERLINKS_SUPPORTED (lazy init)
    Hyper-->>NH: supported? (cached)

    NH->>Resolver: resolve nixpkgs path (channel -> flake_ref)
    Resolver->>Resolver: try `nix eval -f <nixpkgs> path`
    alt path found
        Resolver-->>NH: return path
    else not found
        Resolver->>Resolver: try `nix eval --raw {flake_ref}#path`
        Resolver-->>NH: return path or empty
    end

    NH->>Formatter: format homepage + position
    Formatter->>Formatter: build `file://{nixpkgs_path}/{position}` and GitHub URL
    alt hyperlinks supported
        Formatter-->>User: render clickable hyperlinks (homepage + GitHub links)
    else not supported
        Formatter-->>User: render plain text URLs and file:// paths
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify thread-safety and correctness of lazy HYPERLINKS_SUPPORTED initialization.
  • Review flake-aware path resolution: fallback ordering, error handling, and logging.
  • Ensure print_hyperlink covers all output cases and that malformed position warnings are correct.

Suggested reviewers

  • NotAShelf

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'nh search: fix links and add github link' directly summarizes the main changes: fixing hyperlink handling and adding GitHub repository links to search output.

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.

@github-actions
Copy link

github-actions bot commented Nov 25, 2025

Performance Comparison

Total Elapsed Time: 563.64ms → 28.17s (+4897.0%) ⚠️

Profiling Mode: timing - Execution duration of functions.

+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+
| Function                           | Calls            | Avg                              | P95                              | Total                            | % Total                      |
+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+
| main                               | 1 → 1 (+0.0%)    | 562.99ms → 28.16s (+4902.7%) ⚠️  | 563.09ms → 28.17s (+4902.6%) ⚠️  | 562.99ms → 28.16s (+4902.7%) ⚠️  | 100.00% → 100.00% (+0.0%)    |
+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+
| nh::search::run                    | 1 → 1 (+0.0%)    | 512.02ms → 28.11s (+5389.8%) ⚠️  | 512.23ms → 28.12s (+5389.5%) ⚠️  | 512.02ms → 28.11s (+5389.8%) ⚠️  | 90.94% → 99.80% (+9.7%)      |
+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+
| http_request                       | 1 → 1 (+0.0%)    | 429.48ms → 1.54s (+258.5%) ⚠️    | 429.65ms → 1.54s (+258.5%) ⚠️    | 429.48ms → 1.54s (+258.5%) ⚠️    | 76.28% → 5.46% (-92.8%) 🚀   |
+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+
| json_parse                         | 1 → 1 (+0.0%)    | 77.08ms → 73.48ms (-4.7%)        | 77.14ms → 73.53ms (-4.7%)        | 77.08ms → 73.48ms (-4.7%)        | 13.69% → 0.26% (-98.1%) 🚀   |
+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+
| nh::checks::check_nix_version      | 1 → 1 (+0.0%)    | 50.37ms → 55.12ms (+9.4%)        | 50.40ms → 55.15ms (+9.4%)        | 50.37ms → 55.12ms (+9.4%)        | 8.94% → 0.19% (-97.9%) 🚀    |
+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+
| nh::checks::verify_nix_environment | 1 → 1 (+0.0%)    | 50.37ms → 55.12ms (+9.4%)        | 50.40ms → 55.15ms (+9.4%)        | 50.37ms → 55.12ms (+9.4%)        | 8.94% → 0.19% (-97.9%) 🚀    |
+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+
| nh::util::get_nix_version          | 1 → 1 (+0.0%)    | 24.01ms → 26.41ms (+10.0%)       | 24.02ms → 26.41ms (+10.0%)       | 24.01ms → 26.41ms (+10.0%)       | 4.26% → 0.09% (-97.9%) 🚀    |
+------------------------------------+------------------+----------------------------------+----------------------------------+----------------------------------+------------------------------+

Generated with hotpath-rs

📊 View Raw JSON Metrics

PR Metrics

{
  "hotpath_profiling_mode": "timing",
  "total_elapsed": 28165303508,
  "description": "Execution duration of functions.",
  "caller_name": "main",
  "output": {
    "http_request": {
      "calls": 1,
      "avg": 1539561423,
      "p95": 1540358143,
      "total": 1539561423,
      "percent_total": 546
    },
    "json_parse": {
      "calls": 1,
      "avg": 73482331,
      "p95": 73531391,
      "total": 73482331,
      "percent_total": 26
    },
    "main": {
      "calls": 1,
      "avg": 28164588607,
      "p95": 28168945663,
      "total": 28164588607,
      "percent_total": 10000
    },
    "nh::checks::check_nix_version": {
      "calls": 1,
      "avg": 55116945,
      "p95": 55148543,
      "total": 55116945,
      "percent_total": 19
    },
    "nh::checks::verify_nix_environment": {
      "calls": 1,
      "avg": 55122476,
      "p95": 55148543,
      "total": 55122476,
      "percent_total": 19
    },
    "nh::util::get_nix_version": {
      "calls": 1,
      "avg": 26408066,
      "p95": 26411007,
      "total": 26408066,
      "percent_total": 9
    },
    "nh::search::run": {
      "calls": 1,
      "avg": 28108826654,
      "p95": 28118614015,
      "total": 28108826654,
      "percent_total": 9980
    }
  }
}

Main Branch Metrics

{
  "hotpath_profiling_mode": "timing",
  "total_elapsed": 563644744,
  "description": "Execution duration of functions.",
  "caller_name": "main",
  "output": {
    "json_parse": {
      "calls": 1,
      "avg": 77084519,
      "p95": 77135871,
      "total": 77084519,
      "percent_total": 1369
    },
    "nh::search::run": {
      "calls": 1,
      "avg": 512018840,
      "p95": 512229375,
      "total": 512018840,
      "percent_total": 9094
    },
    "nh::util::get_nix_version": {
      "calls": 1,
      "avg": 24014083,
      "p95": 24018943,
      "total": 24014083,
      "percent_total": 426
    },
    "http_request": {
      "calls": 1,
      "avg": 429477127,
      "p95": 429654015,
      "total": 429477127,
      "percent_total": 7628
    },
    "nh::checks::verify_nix_environment": {
      "calls": 1,
      "avg": 50371366,
      "p95": 50397183,
      "total": 50371366,
      "percent_total": 894
    },
    "main": {
      "calls": 1,
      "avg": 562989608,
      "p95": 563085311,
      "total": 562989608,
      "percent_total": 10000
    },
    "nh::checks::check_nix_version": {
      "calls": 1,
      "avg": 50365736,
      "p95": 50397183,
      "total": 50365736,
      "percent_total": 894
    }
  }
}

@neunenak neunenak force-pushed the fix-links-github-link branch 2 times, most recently from e0fe1c0 to 3e11c0c Compare November 27, 2025 09:48
@neunenak neunenak marked this pull request as ready for review November 27, 2025 09:48
@neunenak neunenak changed the title Fix links and add github link nh search: fix links and add github link Nov 27, 2025
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: 2

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

298-322: GitHub link could be shown even without local nixpkgs path.

The GitHub link generation doesn't depend on nixpkgs_path, but it's nested inside the !nixpkgs_path.is_empty() check. Users without a resolvable local nixpkgs path won't see the GitHub link, even though it would still be valid and useful.

Consider restructuring to always show the GitHub link when the position is available:

       if let Some(package_position) = &elem.package_position {
         match package_position.split(':').next() {
           Some(position) => {
-            // Position from search.nixos.org is already a relative path
-            // like "pkgs/by-name/..."
             if !nixpkgs_path.is_empty() {
               print!("  Defined at: ");
               print_hyperlink(
                 position,
                 &format!("file://{nixpkgs_path}/{position}"),
               );
-
-              print!("  Github link: ");
-              let url = format!("{GITHUB_NIXPKGS_URL}/{position}");
-              print_hyperlink(&url, &url);
             }
+
+            print!("  Github link: ");
+            let url = format!("{GITHUB_NIXPKGS_URL}/{position}");
+            print_hyperlink(&url, &url);
           },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47374db and 3e11c0c.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • src/search.rs (5 hunks)
🔇 Additional comments (5)
src/search.rs (5)

49-66: LGTM!

Good use of OnceLock to cache the hyperlink support check. The OSC 8 escape sequence implementation for terminal hyperlinks is correct.


93-100: LGTM!

The flake reference mapping logic handles the common cases appropriately, with a sensible fallback to the registry default.


252-268: LGTM!

The graceful error handling with Option chaining ensures the program doesn't crash if nixpkgs path resolution fails, defaulting to an empty string which is properly checked before use.


289-292: LGTM!

Clean refactoring to use the new print_hyperlink helper for homepage URLs.


102-119: Verify whether nixpkgs exposes a path attribute and whether the flake defines a path output.

The commands nix eval -f '<nixpkgs>' path and nix eval --raw '{flake_ref}#path' reference non-standard attributes/outputs that do not exist in typical nixpkgs or flake setups. Based on nix documentation:

  • Standard nixpkgs does not expose a top-level path attribute (though .outPath is available on derivations).
  • Standard flakes do not expose a top-level path output (templates have nested templates.*.path, but not outputs.path).

These commands will likely fail on most systems unless the target has been heavily customized. More reliable alternatives exist (e.g., builtins.findFile builtins.nixPath "nixpkgs" or evaluating .outPath).

Confirm whether this custom path attribute/output is intentional to the project, or if the commands should be replaced with standard nix expressions.

@neunenak neunenak force-pushed the fix-links-github-link branch 2 times, most recently from eae5174 to 1d5d161 Compare November 27, 2025 10:36
when you run a nh search <packagename> command, the output previously
looked like:

```
$ nh search fluffychat
Querying search.nixos.org, with channel nixos-unstable...
warning: Nix search path entry '/home/greg/.nix-defexpr/channels' does not exist, ignoring
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
Took 120ms
Most relevant results at the end

fluffychat-web (2.0.0)
  Chat with your friends (matrix client)
  Homepage: https://fluffychat.im/
  Defined at: pkgs/by-name/fl/fluffychat/package.nix

fluffychat (2.0.0)
  Chat with your friends (matrix client)
  Homepage: https://fluffychat.im/
  Defined at: pkgs/by-name/fl/fluffychat/package.nix
```

And the "Defined at" links were broken on nix flake systems - they
pointed at a nonexistant file.

This commit fixes that broken link and also adds an additional link to
the file on the nixpkgs github repository:

```
$ cargo run -- search fluffychat
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/nh search fluffychat`
Querying search.nixos.org, with channel nixos-unstable...
Took 160ms
Most relevant results at the end

fluffychat-web (2.2.0)
  Chat with your friends (matrix client)
  Homepage: https://fluffychat.im/
  Defined at: pkgs/by-name/fl/fluffychat/package.nix
  Github link: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/fl/fluffychat/package.nix

fluffychat (2.2.0)
  Chat with your friends (matrix client)
  Homepage: https://fluffychat.im/
  Defined at: pkgs/by-name/fl/fluffychat/package.nix
  Github link: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/fl/fluffychat/package.nix
```
@neunenak neunenak force-pushed the fix-links-github-link branch from 1d5d161 to 35d3723 Compare November 27, 2025 10:41
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.

1 participant