Skip to content

feat(system): add NixOS support and nix package manager integration#975

Open
decode2 wants to merge 3 commits into
Gentleman-Programming:mainfrom
decode2:feat/issue-110-nixos-support
Open

feat(system): add NixOS support and nix package manager integration#975
decode2 wants to merge 3 commits into
Gentleman-Programming:mainfrom
decode2:feat/issue-110-nixos-support

Conversation

@decode2

@decode2 decode2 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #110

Adds native support for NixOS Linux distribution and the nix package manager across Linux environments.

Problem

Gentle AI installer currently did not detect NixOS systems or recognize nix as a package manager, preventing users on NixOS or using nix on Linux from installing prerequisites smoothly.

Solution

  1. Distro Detection: Detected NixOS via /etc/os-release (ID=nixos or ID_LIKE=nixos). Added LinuxDistroNixOS = "nixos" constant.
  2. Package Manager: Mapped nix as the platform package manager when running on NixOS or when nix tool is detected on Linux.
  3. Dependency Hints & Commands: Added nix-env -iA nixpkgs.<package> hints and execution commands for prerequisites (git, curl, node, go).
  4. Unit Tests: Updated system detection matrix and dependency installation matrix unit tests to cover NixOS and nix.

Test Plan

  • Ran go test ./internal/system/... — all tests pass including full package manager matrix.
  • Ran go build ./... — builds cleanly across workspace.

Summary by CodeRabbit

  • New Features
    • Added NixOS recognition to Linux platform auto-detection.
    • Added Nix-based install support for common dependencies (including generated install commands and hints).
  • Bug Fixes
    • Ensure Nix-based setup is marked supported when the Nix tool is installed, with correct NixOS-like detection and package-manager precedence on Linux.
  • Tests
    • Expanded unit test coverage for NixOS detection and Nix install command generation, including precedence scenarios.

Adds detection for NixOS via /etc/os-release (ID=nixos) and support for the
nix package manager across Linux distros, resolving issue Gentleman-Programming#110.

Key changes:
- Added LinuxDistroNixOS constant and nix package manager resolution
- Added nix binary detection in system tools scan
- Added nix-env installation hints and commands for git, curl, node, and go
- Added full unit test coverage for NixOS detection and dependency installation matrix

Closes Gentleman-Programming#110
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 235c18cf-fbaa-46db-9df4-316254c72dca

📥 Commits

Reviewing files that changed from the base of the PR and between bd3a2ac and edcffd8.

📒 Files selected for processing (2)
  • internal/system/detect.go
  • internal/system/detect_test.go

📝 Walkthrough

Walkthrough

Adds NixOS support to Linux detection and dependency installation. It recognizes NixOS from /etc/os-release, treats nix as a package manager, and adds nix-env -iA nixpkgs.* hints and commands for git, curl, node, and go.

Changes

NixOS Platform Support

Layer / File(s) Summary
NixOS detection and profile resolution
internal/system/detect.go, internal/system/detect_test.go
Adds LinuxDistroNixOS, detects NixOS-like systems from ID and ID_LIKE, includes nix in tool detection, resolves Linux profiles to packageManager="nix" and Supported=true, and extends tests for NixOS and package-manager precedence.
nix-env install hints and commands
internal/system/install_deps.go, internal/system/install_deps_test.go
Adds nix branches to install hints and install command sequences for git, curl, node, and go, and extends the install command matrix with a NixOS profile.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: NixOS support plus nix package manager integration.
Linked Issues check ✅ Passed The changes cover NixOS detection, nix-as-package-manager handling, and nix-based install hints/commands required by issue #110.
Out of Scope Changes check ✅ Passed The diff stays focused on NixOS detection, install hints, and tests, with no obvious unrelated changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
internal/system/detect.go (1)

135-147: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Prefer nix before brew in the Linux resolver.

This branch still returns "brew" whenever both tools are installed, so the new "nix" path and the LinuxDistroNixOS fallback never apply on those hosts.

Suggested fix
-		// Check if brew is available on Linux
-		if brew, ok := tools["brew"]; ok && brew.Installed {
-			profile.PackageManager = "brew"
-			profile.Supported = true
-			return profile
-		}
-
 		// Check if nix is available on Linux
 		if nix, ok := tools["nix"]; ok && nix.Installed {
 			profile.PackageManager = "nix"
 			profile.Supported = true
 			return profile
 		}
+
+		// Check if brew is available on Linux
+		if brew, ok := tools["brew"]; ok && brew.Installed {
+			profile.PackageManager = "brew"
+			profile.Supported = true
+			return profile
+		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/system/detect.go` around lines 135 - 147, In the Linux resolver
inside the detection logic, the current tool-preference order still returns brew
first, which prevents the nix path and LinuxDistroNixOS fallback from being used
on hosts where both are installed. Update the checks in the Linux branch of the
detection flow so nix is evaluated before brew, keeping the
profile.PackageManager and profile.Supported assignment behavior the same; use
the existing tools map and profile handling in the resolver to preserve the rest
of the detection logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/system/detect_test.go`:
- Around line 93-108: The current NixOS test coverage only exercises the
ID=nixos case in TestDetectFromInputsMarksNixOSSupported, so the new detection
helper and precedence paths can still regress. Add tests alongside this one for
Linux inputs with ID_LIKE=nixos and for cases where nix is found on PATH, using
detectFromInputs to verify the resulting LinuxDistro, PackageManager, and
Supported values. Keep the assertions aligned with the existing detection
behavior so the new Nix path logic is covered without relying on line-specific
checks.

---

Outside diff comments:
In `@internal/system/detect.go`:
- Around line 135-147: In the Linux resolver inside the detection logic, the
current tool-preference order still returns brew first, which prevents the nix
path and LinuxDistroNixOS fallback from being used on hosts where both are
installed. Update the checks in the Linux branch of the detection flow so nix is
evaluated before brew, keeping the profile.PackageManager and profile.Supported
assignment behavior the same; use the existing tools map and profile handling in
the resolver to preserve the rest of the detection logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 646c5cd9-088a-4fba-894d-9c8436b7106a

📥 Commits

Reviewing files that changed from the base of the PR and between 8df34cd and ff664d8.

📒 Files selected for processing (4)
  • internal/system/detect.go
  • internal/system/detect_test.go
  • internal/system/install_deps.go
  • internal/system/install_deps_test.go

Comment thread internal/system/detect_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/system/detect_test.go`:
- Around line 123-133: The Linux detection logic in detectFromInputs still
prefers brew before the LinuxDistroNixOS fallback, which can misclassify NixOS
hosts that also have Homebrew on PATH. Update the Linux branch so the
NixOS-specific path wins before any brew-based selection, and add a regression
test alongside TestDetectFromInputsPrefersNixOverBrewOnLinux covering a NixOS +
Homebrew case with no nix tool entry to verify the package manager resolves to
NixOS rather than brew.

In `@internal/system/detect.go`:
- Around line 135-145: The Linux detection in detect.go lets the Homebrew
fast-path in the system profile logic override the NixOS case, causing NixOS to
be labeled as "brew" when Homebrew is installed. Update the branching around the
profile selection in the Linux path so LinuxDistroNixOS always wins over the
brew check, either by moving the NixOS-specific case before the brew fast-path
or by guarding the brew branch to exclude NixOS. Make sure the logic in
detectSystemProfile (and the Linux distro handling near it) preserves the
contract that NixOS always maps to "nix".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8aa61234-e9d2-46bd-a544-3fc56f34c173

📥 Commits

Reviewing files that changed from the base of the PR and between ff664d8 and bd3a2ac.

📒 Files selected for processing (2)
  • internal/system/detect.go
  • internal/system/detect_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/system/detect_test.go`:
- Around line 123-133: The Linux detection logic in detectFromInputs still
prefers brew before the LinuxDistroNixOS fallback, which can misclassify NixOS
hosts that also have Homebrew on PATH. Update the Linux branch so the
NixOS-specific path wins before any brew-based selection, and add a regression
test alongside TestDetectFromInputsPrefersNixOverBrewOnLinux covering a NixOS +
Homebrew case with no nix tool entry to verify the package manager resolves to
NixOS rather than brew.

In `@internal/system/detect.go`:
- Around line 135-145: The Linux detection in detect.go lets the Homebrew
fast-path in the system profile logic override the NixOS case, causing NixOS to
be labeled as "brew" when Homebrew is installed. Update the branching around the
profile selection in the Linux path so LinuxDistroNixOS always wins over the
brew check, either by moving the NixOS-specific case before the brew fast-path
or by guarding the brew branch to exclude NixOS. Make sure the logic in
detectSystemProfile (and the Linux distro handling near it) preserves the
contract that NixOS always maps to "nix".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8aa61234-e9d2-46bd-a544-3fc56f34c173

📥 Commits

Reviewing files that changed from the base of the PR and between ff664d8 and bd3a2ac.

📒 Files selected for processing (2)
  • internal/system/detect.go
  • internal/system/detect_test.go
🛑 Comments failed to post (2)
internal/system/detect_test.go (1)

123-133: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
fd detect_test.go . -x sed -n '1,220p' {}
fd detect.go . -x sed -n '118,170p' {}

Repository: Gentleman-Programming/gentle-ai

Length of output: 9980


Add a NixOS + Homebrew regression case. The Linux branch still falls through to brew before the LinuxDistroNixOS fallback, so a NixOS host with Homebrew on PATH and no nix entry would resolve to the wrong package manager.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/system/detect_test.go` around lines 123 - 133, The Linux detection
logic in detectFromInputs still prefers brew before the LinuxDistroNixOS
fallback, which can misclassify NixOS hosts that also have Homebrew on PATH.
Update the Linux branch so the NixOS-specific path wins before any brew-based
selection, and add a regression test alongside
TestDetectFromInputsPrefersNixOverBrewOnLinux covering a NixOS + Homebrew case
with no nix tool entry to verify the package manager resolves to NixOS rather
than brew.
internal/system/detect.go (1)

135-145: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Don't let the Homebrew fast-path override NixOS.

On NixOS, this returns "brew" whenever Homebrew is installed but tools["nix"] is missing/false, because the early brew branch runs before the LinuxDistroNixOS case at Line 159. That breaks the PR contract (NixOS => "nix") and downstream install_deps will emit Homebrew commands instead of nix-env commands.

Proposed fix
-		// Check if brew is available on Linux
-		if brew, ok := tools["brew"]; ok && brew.Installed {
+		// NixOS should always resolve to nix, even if Homebrew is also installed.
+		if distro == LinuxDistroNixOS {
+			profile.PackageManager = "nix"
+			profile.Supported = true
+			return profile
+		}
+
+		// Check if brew is available on Linux
+		if brew, ok := tools["brew"]; ok && brew.Installed {
 			profile.PackageManager = "brew"
 			profile.Supported = true
 			return profile
 		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

		// Check if nix is available on Linux
		if nix, ok := tools["nix"]; ok && nix.Installed {
			profile.PackageManager = "nix"
			profile.Supported = true
			return profile
		}

		// NixOS should always resolve to nix, even if Homebrew is also installed.
		if distro == LinuxDistroNixOS {
			profile.PackageManager = "nix"
			profile.Supported = true
			return profile
		}

		// Check if brew is available on Linux
		if brew, ok := tools["brew"]; ok && brew.Installed {
			profile.PackageManager = "brew"
			profile.Supported = true
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/system/detect.go` around lines 135 - 145, The Linux detection in
detect.go lets the Homebrew fast-path in the system profile logic override the
NixOS case, causing NixOS to be labeled as "brew" when Homebrew is installed.
Update the branching around the profile selection in the Linux path so
LinuxDistroNixOS always wins over the brew check, either by moving the
NixOS-specific case before the brew fast-path or by guarding the brew branch to
exclude NixOS. Make sure the logic in detectSystemProfile (and the Linux distro
handling near it) preserves the contract that NixOS always maps to "nix".

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.

feat(nixos): add NixOS support

1 participant