Skip to content

Capture the version of Nix in addition to the nix store version#108

Merged
grahamc merged 3 commits intomainfrom
push-zqpryppkyvtv
Sep 3, 2025
Merged

Capture the version of Nix in addition to the nix store version#108
grahamc merged 3 commits intomainfrom
push-zqpryppkyvtv

Conversation

@grahamc
Copy link
Copy Markdown
Member

@grahamc grahamc commented Sep 3, 2025

Description
Checklist
  • Tested changes against a test repository
  • Added or updated relevant documentation (leave unchecked if not applicable)
  • (If this PR is for a release) Updated README to point to the new tag (leave unchecked if not applicable)

Summary by CodeRabbit

  • New Features

    • Records the installed Nix version during startup and again before shutdown; visible in logs/diagnostics.
  • Bug Fixes

    • Nix version detection is resilient: failures no longer interrupt execution and fall back to “unknown.”
  • Chores

    • Preflight checks now collect Nix version for more complete environment context.
    • Dependency versions updated for runtime and development tooling.
  • Notes

    • Public API for fact storage now accepts numeric values.

@netlify
Copy link
Copy Markdown

netlify bot commented Sep 3, 2025

Deploy Preview for detsys-ts-docs ready!

Name Link
🔨 Latest commit 12a8d93
🔍 Latest deploy log https://app.netlify.com/projects/detsys-ts-docs/deploys/68b85d4dbc51550008567c6e
😎 Deploy Preview https://deploy-preview-108--detsys-ts-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Sep 3, 2025

Walkthrough

Adds a nix_version fact and a private preflightNixVersion() that runs nix --version (silently), records the result or "unknown", invokes it during preflight and again after main for shutdown events, and updates addFact/facts storage to accept number values.

Changes

Cohort / File(s) Summary
Preflight and shutdown nix version capture
src/index.ts
Added FACT_NIX_VERSION; implemented preflightNixVersion() which runs nix --version, trims stdout, defaults to "unknown" on failure/empty output, records via addFact, and handles errors non-throwing; called after preflightNixStoreInfo() and again after main for shutdown refresh.
Facts API type update
src/index.ts
Changed `addFact(key: string, value: string
Dependency bumps
package.json
Bumped several dependencies and devDependencies versions (minor/patch updates) — no functional code changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Runner as Action Runner
  participant Pre as Preflight
  participant Nix as Nix CLI
  participant Facts as Facts Store

  Runner->>Pre: preflight()
  Note over Pre: existing preflight steps (e.g., preflightNixStoreInfo)
  Pre->>Nix: `nix --version` (silent)
  Nix-->>Pre: stdout (version) or error
  Pre->>Facts: addFact("nix_version", version or "unknown")
  Pre-->>Runner: preflight complete
Loading
sequenceDiagram
  autonumber
  actor Runner as Action Runner
  participant Main as Main Execution
  participant Nix as Nix CLI
  participant Facts as Facts Store

  Runner->>Main: run main()
  Main-->>Runner: main complete
  Note over Runner: before shutdown/cleanup
  Runner->>Nix: `nix --version` (silent) [preflightNixVersion]
  Nix-->>Runner: stdout (version) or error
  Runner->>Facts: addFact("nix_version", version or "unknown")
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop and listen for a line,
A tiny command, a quiet sign.
If nix replies or stays unknown,
I jot it down — the fact is shown.
Joy in logs, a rabbit's rhyme. 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch push-zqpryppkyvtv

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (3)
src/index.ts (3)

50-50: Please document the new fact

Add a short note in the README/docs explaining the new nix_version fact (format, when it’s set, possible value "unknown").

I can draft the doc blurb if you want.


517-519: Move the second nix-version probe to finally to capture error paths

If main() throws, the post-main() probe won’t run. Move it to finally (guarded by isMain) so shutdown/exception events also have the updated version.

Apply this removal near the end of the main block:

-        // Run the preflight of the nix version a second time so our "shutdown" events have updated version info.
-        await this.preflightNixVersion();

Then insert before await this.complete(); in the finally block:

      // Ensure shutdown/exception events have the latest nix version too
      if (this.isMain) {
        try {
          await this.preflightNixVersion();
        } catch {
          // ignore
        }
      }

Also applies to: 524-526


1113-1130: Normalize the captured version to just the numeric component

nix --version often returns strings like “nix (Nix) 2.24.0”. Storing only the version number makes downstream analytics/filters simpler while keeping compatibility when the command output changes slightly.

-    this.addFact(FACT_NIX_VERSION, output);
+    const match = output.match(/\b\d+(?:\.\d+)+\b/);
+    this.addFact(FACT_NIX_VERSION, match?.[0] ?? output);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e439a01 and 86ffeed.

⛔ Files ignored due to path filters (3)
  • dist/index.d.ts is excluded by !**/dist/**
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (1)
  • src/index.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/index.ts (1)
dist/index.js (2)
  • output (1588-1588)
  • output (1628-1628)
⏰ 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). (1)
  • GitHub Check: Run all checks
🔇 Additional comments (2)
src/index.ts (2)

50-50: New FACT_NIX_VERSION constant — LGTM

Consistent naming and placement with existing fact keys.


1113-1130: No rebuild needed; dist is up to date
dist/index.js already defines FACT_NIX_VERSION (line 899) and invokes nix --version (line 1632).

@grahamc grahamc merged commit c730349 into main Sep 3, 2025
5 of 6 checks passed
@grahamc grahamc deleted the push-zqpryppkyvtv branch September 3, 2025 15:28
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

🧹 Nitpick comments (2)
src/index.ts (2)

524-526: Run the “final” nix_version capture even on failure.

Right now, if main() throws, the second capture won’t run. Prefer moving this to finally so shutdown/exception events always include the latest version.

Apply this diff:

@@
       if (this.isMain) {
         await this.main();
-
-        // Run the preflight of the nix version a second time so our "shutdown" events have updated version info.
-        await this.preflightNixVersion();
       } else if (this.isPost) {
         await this.post();
       }
@@
     } finally {
+      // Ensure shutdown/exception events carry the latest Nix version.
+      await this.preflightNixVersion();
       if (this.isPost) {
         await this.collectBacktraces();
       }
 
       await this.complete();
     }

1113-1131: Also record a parsed/normalized version for easier analytics.

Keep nix_version as-is, but additionally extract a semver-like token when present. This avoids downstream parsing in analytics queries.

Apply these diffs:

@@
-const FACT_NIX_VERSION = "nix_version";
+const FACT_NIX_VERSION = "nix_version";
+const FACT_NIX_VERSION_SEMVER = "nix_version_semver";
   private async preflightNixVersion(): Promise<void> {
     let output = "unknown";
 
     try {
       ({ stdout: output } = await actionsExec.getExecOutput(
         "nix",
         ["--version"],
         {
           silent: true,
         },
       ));
       output = output.trim() || "unknown";
     } catch {
       // That's fine.
     }
 
     this.addFact(FACT_NIX_VERSION, output);
+    // Try to pull out a semver-ish token, e.g., "2.24.2" from "nix (Nix) 2.24.2".
+    const m = output.match(/\b\d+\.\d+\.\d+(?:[0-9A-Za-z.-]*)?\b/);
+    if (m?.[0]) {
+      this.addFact(FACT_NIX_VERSION_SEMVER, m[0]);
+    }
   }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bd53edf and 12a8d93.

⛔ Files ignored due to path filters (4)
  • dist/index.d.ts is excluded by !**/dist/**
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/index.ts (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/index.ts (1)
dist/index.js (2)
  • output (1588-1588)
  • output (1628-1628)
⏰ 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). (1)
  • GitHub Check: Run all checks
🔇 Additional comments (6)
package.json (2)

30-35: Deps bumps look fine.

ESM-only packages like got are consistent with "type": "module". Nothing blocking here.


38-52: Compatibility confirmed: eslint-plugin-github v6 and @typescript-eslint/eslint-plugin v8 support ESLint v9.34.0
Both plugins declare support for ESLint v9 (>= 9.0.0) and are compatible with v9.34.0—no further changes needed.

src/index.ts (4)

50-51: New fact key is well-scoped.

FACT_NIX_VERSION name is clear and consistent with existing fact keys.


245-246: Facts map now allows numbers — good future-proofing.

This aligns with potential numeric fact values without forcing stringification.


403-405: addFact signature widening is backward-compatible.

Public API remains source-compatible while supporting numeric values.


512-519: Capturing nix_version early is the right call.

Recording it alongside store info improves event context.

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