Skip to content

fix: make Nix survive home volume mount in devops image#17

Merged
megheaiulian merged 2 commits into
mainfrom
fix/devops-nix-runtime
Feb 26, 2026
Merged

fix: make Nix survive home volume mount in devops image#17
megheaiulian merged 2 commits into
mainfrom
fix/devops-nix-runtime

Conversation

@megheaiulian

Copy link
Copy Markdown
Contributor

Summary

Fixes the Nix installation in the devops image so it works at runtime when Coder mounts a persistent volume over /home/coder.

Problem

PR #15 installed Nix correctly at build time, but two things broke at runtime:

  • ~/.config/nix/nix.conf (flakes config) — wiped by the home volume mount
  • ~/.nix-profile/bin (added to PATH via ENV) — the symlink doesn't exist on the mounted volume, so nix is not found

Fix

  • Move nix.conf to /etc/nix/nix.conf — system-wide config, outside the home directory
  • Symlink nix binaries to /usr/local/bin/ — at build time, resolve ~/.nix-profile/bin/nix* through to the real /nix/store/… paths (which persist outside the home volume) and create symlinks in /usr/local/bin/ which is already on $PATH
  • Remove ENV PATH — no longer needed since /usr/local/bin is already on the default PATH
  • Remove ~/.config/nix creation — replaced by the system-wide config

Why this works

  • /nix/ (store + var) is outside the home volume and survives workspace restarts
  • /etc/nix/nix.conf is outside the home volume
  • /usr/local/bin/ is outside the home volume
  • The symlinks use readlink -f to resolve to absolute /nix/store/… paths, so they don't depend on ~/.nix-profile existing at runtime

Move nix.conf to /etc/nix/ (system-wide, outside the home volume) and
symlink nix binaries from /usr/local/bin to their resolved /nix/store
paths. This avoids relying on ~/.nix-profile or ~/.config which are
wiped when Coder mounts a persistent volume over /home/coder.
Multiple nix-* binaries (nix-build, nix-env, etc.) resolve to the same
/nix/store/.../bin/nix target. Using 'ln -s target /usr/local/bin/'
takes the basename from the target, causing all links to collide on
/usr/local/bin/nix. Fix by explicitly naming each link with basename
of the original profile binary.
@megheaiulian megheaiulian merged commit c4c5dab into main Feb 26, 2026
3 checks passed
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