Skip to content

fix(make): detect nix in Docker where profile path differs - #1217

Merged
shunkakinoki merged 1 commit into
mainfrom
fix/nix-env-docker-detection
Mar 19, 2026
Merged

fix(make): detect nix in Docker where profile path differs#1217
shunkakinoki merged 1 commit into
mainfrom
fix/nix-env-docker-detection

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Mar 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • NIX_ENV only sourced ~/.nix-profile/etc/profile.d/nix.sh, which doesn't exist in the Docker CI image where nix is pre-installed at /usr/bin
  • Add fallbacks: Determinate Systems daemon profile path (/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh) and command -v nix
  • Prevents the installer from re-running and failing with "nix is already a valid command"

Test plan

  • Docker CI build passes without make: *** [Makefile:301: nix-install] Error 1

🤖 Generated with Claude Code


Summary by cubic

Fix Nix detection in Docker/CI by adding daemon profile and command-based fallbacks, so the installer skips when nix is already available. Prevents make nix-install failures in images where nix lives at /usr/bin.

  • Bug Fixes
    • Update NIX_ENV to source ~/.nix-profile/..., or /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh, or use command -v nix as a final check.

Written for commit cb8bba4. Summary will update on new commits.

NIX_ENV sourced only ~/.nix-profile/etc/profile.d/nix.sh, which
doesn't exist in the Docker CI image where nix is pre-installed at
/usr/bin. Fall back to the Determinate Systems daemon profile path
and `command -v nix` to avoid re-running the installer when nix
is already present.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: f6b1317c5ea8
Copilot AI review requested due to automatic review settings March 19, 2026 19:45
@mesa-dot-dev

mesa-dot-dev Bot commented Mar 19, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the Makefile failed to correctly detect Nix installations in certain Docker CI environments, leading to unnecessary re-attempts to install Nix and subsequent errors. By enhancing the logic for identifying an existing Nix setup, the changes ensure smoother and more reliable execution of build processes in diverse environments.

Highlights

  • Improved Nix environment detection: The NIX_ENV variable assignment was updated to correctly detect Nix installations, especially in Docker CI environments where the default profile path might not exist.
  • Added fallback mechanisms: New fallback paths were introduced, including the Determinate Systems daemon profile path and a general command -v nix check, to ensure robust Nix detection.
  • Prevented installer re-runs: These changes prevent the Nix installer from erroneously re-running and failing with "nix is already a valid command" errors in CI.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai

coderabbitai Bot commented Mar 19, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6ed76d0-1cf9-4a64-bc10-5ba29d9da1f5

📥 Commits

Reviewing files that changed from the base of the PR and between b62c29c and cb8bba4.

📒 Files selected for processing (1)
  • Makefile

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Improved Nix environment initialization with additional fallback paths for better compatibility across different Nix installation configurations.

Walkthrough

The NIX_ENV Makefile variable has been enhanced to include multiple fallback paths for Nix profile initialization. It now attempts to source ~/.nix-profile/.../nix.sh, then the daemon profile script at /nix/var/nix/profiles/default/.../nix-daemon.sh, checks for nix on PATH, before returning not_found.

Changes

Cohort / File(s) Summary
Makefile Nix environment setup
Makefile
Updated NIX_ENV variable to include three sequential fallback paths (~/.nix-profile, daemon profile, and PATH lookup) before defaulting to not_found.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Suggested labels

bug

Poem

🐰 A clever bunny hops through the code,
Adding fallback paths along the road,
When profiles hide in the shadows deep,
Multiple routes help Nix setup succeed! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nix-env-docker-detection
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@shunkakinoki
shunkakinoki merged commit 8962b29 into main Mar 19, 2026
32 of 33 checks passed
@shunkakinoki
shunkakinoki deleted the fix/nix-env-docker-detection branch March 19, 2026 19:46

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

The pull request enhances the detection of the Nix environment within the Makefile by adding additional fallback mechanisms. This is a positive change, making the build process more robust across different environments, especially Docker CI where Nix might be installed in non-standard locations. The added checks for /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh and command -v nix are valuable for broader compatibility.

Comment thread Makefile
echo "$(shell whoami)"; \
fi)
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || echo "not_found")
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || command -v nix >/dev/null 2>&1 || echo "not_found")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The command -v nix >/dev/null 2>&1 check, while useful for detecting the nix executable, only verifies its presence in the PATH. Unlike sourcing the profile scripts (. ~/.nix-profile/... or . /nix/var/nix/profiles/...), it does not ensure that the necessary Nix environment variables (like NIX_PATH) are correctly set up. If only this check succeeds, the NIX_ENV variable will be empty, which the nix-check target interprets as a functional Nix environment. This could lead to subsequent Nix commands failing due to an incomplete environment setup, even though nix-check passes.

To make this fallback more robust, consider replacing command -v nix >/dev/null 2>&1 with a check that also verifies basic Nix functionality, such as nix --version >/dev/null 2>&1. This would ensure that if nix is found, it is also capable of executing basic commands, implying a more complete environment.

NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || nix --version >/dev/null 2>&1 || echo "not_found")

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adjusts Nix detection in the Makefile to better handle Docker/CI environments where the standard ~/.nix-profile/.../nix.sh path is absent, avoiding unnecessary (and failing) re-install attempts.

Changes:

  • Extend NIX_ENV detection to try Determinate Systems’ daemon profile script path.
  • Add a final fallback that treats nix being present on PATH as “installed”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Makefile
echo "$(shell whoami)"; \
fi)
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || echo "not_found")
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || command -v nix >/dev/null 2>&1 || echo "not_found")

Copilot AI Mar 19, 2026

Copy link

Choose a reason for hiding this comment

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

NIX_ENV is computed with :=, so it’s evaluated once when Make parses the file. If make nix-setup runs on a machine without Nix, nix-install can install Nix but nix-check will still see the original NIX_ENV=not_found and fail in the same invocation. Also, sourcing nix.sh/nix-daemon.sh inside $(shell ...) can’t actually set environment for later Make recipes (it runs in a subshell), so this variable is effectively just a presence check.

Consider moving the detection into the nix-check/nix-install recipes (e.g., command -v nix), or change NIX_ENV to a recursively-expanded variable (=) / function so it’s evaluated at use time and reflects installs done earlier in the same make run.

Suggested change
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || command -v nix >/dev/null 2>&1 || echo "not_found")
NIX_ENV = $(shell command -v nix >/dev/null 2>&1 || echo "not_found")

Copilot uses AI. Check for mistakes.
@mesa-dot-dev

mesa-dot-dev Bot commented Mar 19, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Fixed Nix environment detection in Docker CI by adding fallback profile paths, preventing installer re-runs and failures.

What changed?

  • Updated NIX_ENV sourcing logic to correctly identify Nix installations in Docker CI environments.
  • Added fallbacks to check for Nix at /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh and using command -v nix.
  • This resolves an issue where the Nix installer would re-run and fail with "nix is already a valid command" in CI.

Description generated by Mesa. Update settings

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