|
| 1 | +# Microsoft's official devcontainer base (Ubuntu 24.04), pinned by digest for |
| 2 | +# reproducibility. It ships a non-root `vscode` user (UID 1000) with passwordless |
| 3 | +# sudo plus the common dev tools (git, curl, sudo, ca-certificates, openssh-client), |
| 4 | +# so no manual user creation is needed here. |
| 5 | +FROM mcr.microsoft.com/devcontainers/base:ubuntu24.04@sha256:4bcb1b466771b1ba1ea110e2a27daea2f6093f9527fb75ee59703ec89b5561cb |
| 6 | + |
| 7 | +ENV DEBIAN_FRONTEND=noninteractive \ |
| 8 | + LANG=C.UTF-8 \ |
| 9 | + LC_ALL=C.UTF-8 |
| 10 | + |
| 11 | +# The base already provides git/sudo/ca-certificates/curl/openssh-client; we only |
| 12 | +# strictly need xz-utils for the Nix installer tarball. The rest are listed |
| 13 | +# defensively (apt is idempotent and skips already-present packages). |
| 14 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 15 | + git sudo ca-certificates curl less xz-utils openssh-client \ |
| 16 | + && rm -rf /var/lib/apt/lists/* |
| 17 | + |
| 18 | +# Pre-create /nix owned by the vscode user and a system-wide nix.conf. Two things to note: |
| 19 | +# - Sandboxing relies on CAP_SYS_ADMIN (sethostname etc.), which container |
| 20 | +# builds don't grant — without `sandbox = false` both the Nix self-install |
| 21 | +# and every subsequent `nix profile install` fail. |
| 22 | +# - The K Framework binary caches let `kup install k` pull prebuilt K binaries |
| 23 | +# instead of compiling from source. Single-user Nix (vscode owns /nix) honors |
| 24 | +# these substituters from the system config, so no per-user nix.conf needed. |
| 25 | +RUN mkdir -m 0755 /nix \ |
| 26 | + && chown vscode:vscode /nix \ |
| 27 | + && mkdir -p /etc/nix \ |
| 28 | + && printf '%s\n' \ |
| 29 | + 'sandbox = false' \ |
| 30 | + 'filter-syscalls = false' \ |
| 31 | + 'experimental-features = nix-command flakes' \ |
| 32 | + 'substituters = https://cache.nixos.org https://k-framework.cachix.org https://k-framework-binary.cachix.org' \ |
| 33 | + 'trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= k-framework.cachix.org-1:jeyMXB2h28gpNRjuVkehg+zLj62ma1RnyyopA/20yFE= k-framework-binary.cachix.org-1:pJedQ8iG19BW3v/DMMmiRVtwRBGO3fyMv2Ws0OpBADs=' \ |
| 34 | + > /etc/nix/nix.conf |
| 35 | + |
| 36 | +USER vscode |
| 37 | +WORKDIR /home/vscode |
| 38 | + |
| 39 | +# Single-user Nix install — pinned to a specific release for reproducibility |
| 40 | +# and supply-chain safety. Update the version when upgrading Nix. |
| 41 | +ARG NIX_VERSION=2.28.3 |
| 42 | +RUN curl -fsSL "https://releases.nixos.org/nix/nix-${NIX_VERSION}/install" -o /tmp/nix-install \ |
| 43 | + && sh /tmp/nix-install --no-daemon --no-channel-add \ |
| 44 | + && rm /tmp/nix-install |
| 45 | + |
| 46 | +ENV PATH=/home/vscode/.nix-profile/bin:/home/vscode/.npm-global/bin:$PATH |
| 47 | + |
| 48 | +# Point the `nixpkgs` flake registry at the nixos-25.05 release branch (matching |
| 49 | +# the project's flake.nix) — a stable channel, though not a frozen revision; it |
| 50 | +# only governs the container-level bootstrap tooling below, while the project |
| 51 | +# toolchain is pinned reproducibly via flake.nix/flake.lock. Then install only |
| 52 | +# that container-level bootstrap/runtime tooling via Nix: |
| 53 | +# - direnv + nix-direnv → auto-load and cache the flake's `nix develop` shell on |
| 54 | +# entry to /workspace; this is what actually provides the |
| 55 | +# project toolchain (python, uv, make, wabt, K Framework), |
| 56 | +# so those live in flake.nix's devShell, not here. |
| 57 | +# - nodejs_22 → host for the Claude Code CLI (run as `claude` from |
| 58 | +# anywhere, so it stays globally on PATH, not in the shell) |
| 59 | +RUN . /home/vscode/.nix-profile/etc/profile.d/nix.sh \ |
| 60 | + && nix registry add nixpkgs github:NixOS/nixpkgs/nixos-25.05 \ |
| 61 | + && nix profile install \ |
| 62 | + nixpkgs#direnv \ |
| 63 | + nixpkgs#nix-direnv \ |
| 64 | + nixpkgs#nodejs_22 |
| 65 | + |
| 66 | +# Claude Code CLI — installed to a per-user prefix so root isn't required. |
| 67 | +RUN . /home/vscode/.nix-profile/etc/profile.d/nix.sh \ |
| 68 | + && npm config set prefix /home/vscode/.npm-global \ |
| 69 | + && npm install -g @anthropic-ai/claude-code@2.1.175 |
| 70 | + |
| 71 | +# Wire up nix-direnv, then hook direnv into interactive shells. Order matters: |
| 72 | +# Nix must be sourced before the direnv hook so the profile PATH is in place when |
| 73 | +# direnv evaluates the flake. |
| 74 | +RUN mkdir -p /home/vscode/.config/direnv \ |
| 75 | + && echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > /home/vscode/.config/direnv/direnvrc \ |
| 76 | + && printf '%s\n' \ |
| 77 | + '. /home/vscode/.nix-profile/etc/profile.d/nix.sh' \ |
| 78 | + 'eval "$(direnv hook bash)"' \ |
| 79 | + >> /home/vscode/.bashrc |
| 80 | + |
| 81 | +WORKDIR /workspace |
0 commit comments