mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
feat(tools): dotnet, the .NET SDK, as a shared toolchain (#7)
Adds `dotnet`, the .NET SDK, as a fifth shared toolchain next to node, python, rust and go. `--tools dotnet`, `devvm tools add dotnet` and the picker offer it, and a folder with `*.sln`, `*.slnx`, `*.csproj`, `*.fsproj` or `global.json` at its top level suggests it in the new VM's summary, the way `package.json` suggests node. Refs #2. Thanks to @jsskeen-utah for the detailed request. Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
da804f0568
commit
8d8da01037
44 files changed
+1068
-109
No files matched your search
@@ -63,7 +63,7 @@ Use these terms on every page and in every message.
|
||||
- **Feature** on user pages means only base image features (omb, fzf, cli-tools) and devcontainer features. Backend features, which are native, emulated or none, appear only on the How it works pages. devvm doctor prints backend features as "features", so say so where a user page compares backends.
|
||||
- **Image** means devvm's images, such as base or foo+bar. Say "container image" for the images that `--from` and a `devcontainer.json` start from.
|
||||
- **Layer** means devvm's layers. Say "Docker's image layers" when you mean Docker's.
|
||||
- **Shared tool** means node, python, rust, go, claude, codex or opencode.
|
||||
- **Shared tool** means node, python, rust, go, dotnet, claude, codex or opencode.
|
||||
|
||||
## Workflow
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: Toolchain request
|
||||
description: A language or runtime you'd like devvm to build in, such as .NET, Java, PHP, Ruby or Elixir.
|
||||
description: A language or runtime you'd like devvm to build in, such as Java, PHP, Ruby or Elixir.
|
||||
labels: ["enhancement", "toolchain", "triage"]
|
||||
body:
|
||||
- type: markdown
|
||||
@@ -18,7 +18,7 @@ body:
|
||||
attributes:
|
||||
label: The toolchain
|
||||
description: Its usual name, and its mise tool name if you know it (what `mise registry NAME` prints).
|
||||
placeholder: .NET (mise's dotnet)
|
||||
placeholder: Ruby (mise's ruby)
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -26,7 +26,7 @@ body:
|
||||
attributes:
|
||||
label: Files that should pick it
|
||||
description: The project files that tell devvm a folder needs this toolchain.
|
||||
placeholder: "*.csproj, *.sln, global.json"
|
||||
placeholder: "Gemfile, .ruby-version"
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -41,25 +41,25 @@ body:
|
||||
attributes:
|
||||
label: Versions
|
||||
description: Whether the latest is enough or you need several major versions, and which.
|
||||
placeholder: The latest LTS, and 8 for older projects
|
||||
placeholder: The latest, and 3.3 for older projects
|
||||
- type: input
|
||||
id: source
|
||||
attributes:
|
||||
label: Official install source
|
||||
description: Where the toolchain's own builds come from.
|
||||
placeholder: https://dotnet.microsoft.com/download
|
||||
placeholder: https://www.ruby-lang.org/en/downloads/
|
||||
- type: textarea
|
||||
id: registries
|
||||
attributes:
|
||||
label: Package managers and their hosts
|
||||
description: The package managers people use with it and the hosts they download from, which the toolchain's network policy lets through.
|
||||
placeholder: "NuGet: api.nuget.org, globalcdn.nuget.org"
|
||||
placeholder: "RubyGems: rubygems.org, index.rubygems.org"
|
||||
- type: textarea
|
||||
id: writes
|
||||
attributes:
|
||||
label: What it writes into its own folder
|
||||
description: Global installs, plugins or self-updates that write into the toolchain's install folder, which devvm has to send somewhere else because shared tools are read-only in VMs.
|
||||
placeholder: "`dotnet tool install -g` writes to ~/.dotnet/tools"
|
||||
placeholder: "`gem install` writes into Ruby's own gems folder"
|
||||
- type: dropdown
|
||||
id: builds
|
||||
attributes:
|
||||
|
||||
@@ -114,7 +114,7 @@ devvm: one isolated VM per project folder, cloned from a base image, with toolch
|
||||
|
||||
- **Unit tests** are Go table tests next to the code; **CLI tests** are testscript against the built binary in a `/tmp` sandbox in names mode, stubs first on `PATH` (`stub_calls`, `stub_reset`), with `project`, `vm_name`, `catg`, `vm_state`, `json_set` and `$DATA`/`$VMS`/`$RUN`/`$CFG`; the binary has `assets/` embedded (no override: scripts read `$DEVVM_REPO/assets/`; rebuild before a manual run after editing them). New logic needs a test. Neither touches the Keychain, real VMs or the user's folders; state-writing tests point the XDG folders at `t.TempDir()`. Go tests never run up: scripts do.
|
||||
- **Never touch VMs, images or containers devvm's tests didn't make:** your own stay as they are. Manual runs: `DEVVM_LIMA_HOME=~/.lt LIMA_HOME=~/.lt XDG_DATA_HOME=/tmp/x/data XDG_CONFIG_HOME=/tmp/x/config DEVVM_SECRET_SERVICE=devvm-sandbox-test` (devvm's Lima home is `$XDG_DATA_HOME/devvm/lima` unless `DEVVM_LIMA_HOME`; `LIMA_HOME` is for your `limactl`). Add a `config.toml` with `features = []` and pass `--network TIER` so nothing prompts. Delete test Keychain items. Never use your own tokens or logins: a network-policy VM reads its agent's login file from `HOME`, so give it its own (the Keychain needs the real `HOME`: test it apart).
|
||||
- **End-to-end:** `mise run e2e -- FLAGS` (`--only`, `--from`, `--clean`, `--slots`, `--golden`…) builds devvm from the checkout and drives real VMs in its sandbox (`~/.lt-e2e-go`, `/tmp/devvm-go-e2e`, service `devvm-go-e2e`), deleting only what it made; images stay cached (`--clean`). `--slots N` spreads the sections over N sandboxes at once (slot K's paths end `-K`, its ports +100·K, its images cloned from slot 0's). Only `tools` resolves the newest tool versions; the rest use the pinned lock, and `--from` images go by pinned digest but one tag (`scripts/bump.sh e2e-tools e2e-from`). Run it in the background. Sections: `images`, `project`, `clone` (a throwaway repo, its own `HOME`), `gc` (an `img-*` folder's VM, a stale fixture), `tools` (a node VM), `network` (a VM with Claude Code, Codex and opencode), `desktop` (a base VM refused, then the desktop layer, devvm desktop), `nix` (a node VM with the nix layer and a flake), `from` (Debian 12, Alpine and Ubuntu bases, a docker that isn't running), `link` (two targets and a client, then the three in a group, the design note's threat check). Tiers: none (all but `desktop` and `from`, no features); `--from` (everything, every feature; before merging `assets/` or `--from` changes); `--only a,b` (with `from`: every feature). Hosted CI can't run it on macOS.
|
||||
- **End-to-end:** `mise run e2e -- FLAGS` (`--only`, `--from`, `--clean`, `--slots`, `--golden`…) builds devvm from the checkout and drives real VMs in its sandbox (`~/.lt-e2e-go`, `/tmp/devvm-go-e2e`, service `devvm-go-e2e`), deleting only what it made; images stay cached (`--clean`). `--slots N` spreads the sections over N sandboxes at once (slot K's paths end `-K`, its ports +100·K, its images cloned from slot 0's). Only `tools` resolves the newest tool versions; the rest use the pinned lock, and `--from` images go by pinned digest but one tag (`scripts/bump.sh e2e-tools e2e-from`). Run it in the background. Sections: `images`, `project`, `clone` (a throwaway repo, its own `HOME`), `gc` (an `img-*` folder's VM, a stale fixture), `tools` (a node VM, a .NET one), `network` (a VM with Claude Code, Codex and opencode), `desktop` (a base VM refused, then the desktop layer, devvm desktop), `nix` (a node VM with the nix layer and a flake), `from` (Debian 12, Alpine and Ubuntu bases, a docker that isn't running), `link` (two targets and a client, then the three in a group, the design note's threat check). Tiers: none (all but `desktop` and `from`, no features); `--from` (everything, every feature; before merging `assets/` or `--from` changes); `--only a,b` (with `from`: every feature). Hosted CI can't run it on macOS.
|
||||
- **Linux hosts:** `LIMA_HOME=~/.lt-linux-go`, VM `linuxhost` (nested virtualization, the repo read-only, copied to `~/devvm`), set up as [testing.md](docs/content/docs/contributing/testing.md) says, apart from any Lima home of your own.
|
||||
- **Unreviewed emulations** are checked through `DEVVM_UNREVIEWED=backend:feature`, which only test builds (e2e's, the CLI tests', by ldflags) read.
|
||||
- **Delete test VMs and temp files afterwards.** Long builds run in the background. Tests that `chflags` real files unlock them (`chflags -R nouchg`), only in their own temp folders.
|
||||
|
||||
@@ -58,7 +58,7 @@ devvm
|
||||
|
||||
## What's supported
|
||||
|
||||
- **Toolchains:** devvm detects them from the project's files, so a folder with `package.json` gets node ([toolchains](https://devvm.dev/docs/using/toolchains/)).
|
||||
- **Toolchains:** node, python, rust, go and dotnet. devvm detects them from the project's files, so a folder with `package.json` gets node ([toolchains](https://devvm.dev/docs/using/toolchains/)).
|
||||
- **Coding agents:** Claude Code, Codex and opencode run in the VM, with your settings, skills and MCP servers. devvm keeps their settings and logins in a store of its own, and `devvm agent import` copies them in from an agent you already use on your machine ([coding agents](https://devvm.dev/docs/using/coding-agents/)).
|
||||
- **Layers:** the built-in `docker`, `nix` and `desktop` layers, and your own from `devvm layer new` ([layers](https://devvm.dev/docs/using/images/#layers)).
|
||||
- **Backend:** devvm runs its VMs on [Lima](https://lima-vm.io) ([backends](https://devvm.dev/docs/backends/)).
|
||||
|
||||
+73
-9
@@ -1,28 +1,92 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Every VM's shells get the tools' environment from base's
|
||||
// /etc/profile.d/devvm-tools.sh, which turns off the agents'
|
||||
// self-updates: their installs are read-only shared tools, and mise pins
|
||||
// their versions.
|
||||
func TestToolsEnvironment(t *testing.T) {
|
||||
// heredoc is the body of the heredoc that base.sh starts with this line,
|
||||
// up to its end marker.
|
||||
func heredoc(t *testing.T, start, end string) string {
|
||||
t.Helper()
|
||||
b, err := fs.ReadFile(FS, "layers/base.sh")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, rest, ok := strings.Cut(string(b), "/etc/profile.d/devvm-tools.sh >/dev/null <<'SH'\n")
|
||||
block, _, closed := strings.Cut(rest, "\nSH\n")
|
||||
_, rest, ok := strings.Cut(string(b), start+"\n")
|
||||
block, _, closed := strings.Cut(rest, "\n"+end+"\n")
|
||||
if !ok || !closed {
|
||||
t.Fatal("base.sh writes no /etc/profile.d/devvm-tools.sh")
|
||||
t.Fatalf("base.sh has no %q", start)
|
||||
}
|
||||
for _, line := range []string{"export DISABLE_AUTOUPDATER=1", "export OPENCODE_DISABLE_AUTOUPDATE=1"} {
|
||||
return block
|
||||
}
|
||||
|
||||
// Every VM's shells get the tools' environment from base's
|
||||
// /etc/profile.d/devvm-tools.sh, which turns off the agents'
|
||||
// self-updates: their installs are read-only shared tools, and mise pins
|
||||
// their versions. It turns off .NET's telemetry, first-run banner, profile
|
||||
// edit and workload update check too, and puts its global tools on the
|
||||
// PATH.
|
||||
func TestToolsEnvironment(t *testing.T) {
|
||||
block := heredoc(t, "sudo tee /etc/profile.d/devvm-tools.sh >/dev/null <<'SH'", "SH")
|
||||
for _, line := range []string{
|
||||
"export DISABLE_AUTOUPDATER=1", "export OPENCODE_DISABLE_AUTOUPDATE=1",
|
||||
"export DOTNET_CLI_TELEMETRY_OPTOUT=1", "export DOTNET_NOLOGO=1",
|
||||
"export DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=false", "export DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE=true",
|
||||
} {
|
||||
if !strings.Contains("\n"+block+"\n", "\n"+line+"\n") {
|
||||
t.Errorf("devvm-tools.sh lacks %q", line)
|
||||
}
|
||||
}
|
||||
for _, dir := range []string{"$HOME/.npm-global/bin:", "$HOME/go/bin:", "$HOME/.cargo/bin:", "$HOME/.dotnet/tools:", "$HOME/.local/bin:"} {
|
||||
if !strings.Contains(block, `export PATH="`) || !strings.Contains(block, dir) {
|
||||
t.Errorf("devvm-tools.sh's PATH lacks %s", dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// base.sh's devvm-fetch keeps a download only when its checksum is the
|
||||
// one given: a SHA-256, or a SHA-512 by its length.
|
||||
func TestDevvmFetch(t *testing.T) {
|
||||
for _, c := range []string{"sh", "curl", "sha256sum", "sha512sum", "cut"} {
|
||||
if _, err := exec.LookPath(c); err != nil {
|
||||
t.Skip("no " + c)
|
||||
}
|
||||
}
|
||||
dir := t.TempDir()
|
||||
script := filepath.Join(dir, "devvm-fetch")
|
||||
if err := os.WriteFile(script, []byte(heredoc(t, "sudo tee /usr/local/bin/devvm-fetch >/dev/null <<'SH'", "SH")+"\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
src := filepath.Join(dir, "src")
|
||||
body := []byte("an archive\n")
|
||||
if err := os.WriteFile(src, body, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s256, s512 := sha256.Sum256(body), sha512.Sum512(body)
|
||||
for _, tc := range []struct {
|
||||
name, sum string
|
||||
ok bool
|
||||
}{
|
||||
{"its SHA-256", hex.EncodeToString(s256[:]), true},
|
||||
{"its SHA-512", hex.EncodeToString(s512[:]), true},
|
||||
{"another SHA-256", strings.Repeat("0", 64), false},
|
||||
{"another SHA-512", strings.Repeat("0", 128), false},
|
||||
{"its SHA-256 twice", strings.Repeat(hex.EncodeToString(s256[:]), 2), false},
|
||||
} {
|
||||
out := filepath.Join(dir, "out")
|
||||
err := exec.CommandContext(t.Context(), "sh", script, "file://"+src, tc.sum, out).Run() //nolint:gosec // base.sh's devvm-fetch, on the test's own files
|
||||
_, kept := os.Stat(out)
|
||||
if (err == nil) != tc.ok || (kept == nil) != tc.ok {
|
||||
t.Errorf("%s: %v, kept %v", tc.name, err, kept == nil)
|
||||
}
|
||||
_ = os.Remove(out)
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ The VM doesn't record its tier, and the user sees it with devvm network on the h
|
||||
|
||||
## Tools and installs
|
||||
|
||||
- The toolchains (node, python, rust, go) and the coding agents are shared tools, mounted read-only from images that every VM shares. They can't update themselves, and global installs go into your home: `npm i -g` installs into `~/.npm-global`, and Python's packages go into a virtual environment or `~/.local/bin`.
|
||||
- The toolchains, such as node ([the list](https://devvm.dev/docs/using/toolchains/)), and the coding agents are shared tools, mounted read-only from images that every VM shares. They can't update themselves, and global installs go into your home: `npm i -g` installs into `~/.npm-global`, Python's packages go into a virtual environment or `~/.local/bin`, and `dotnet tool install -g` installs into `~/.dotnet/tools`.
|
||||
- mise runs the shared tools. A project that asks for another version, in `.tool-versions`, `mise.toml` or its own toolchain file, gets it from mise, which installs it in your home on first use.
|
||||
- `sudo` needs no password, and `apt install` (`apk add` on Alpine) goes through the proxy, whose allowlist for every VM has Ubuntu's, Debian's and Alpine's package hosts. What it installs is lost when the VM is made again.
|
||||
- `devvm-fetch URL SHA256 OUT` downloads a file and fails when its checksum doesn't match.
|
||||
|
||||
+16
-2
@@ -92,13 +92,16 @@ experimental = true
|
||||
shared_install_dirs = ["/opt/devvm/tools"]
|
||||
# A project's version files choose versions, as their own tools would; a version that isn't shared
|
||||
# installs into the VM on first use. Not go: go.mod's go line is a minimum, and Go's own GOTOOLCHAIN
|
||||
# reads its toolchain line.
|
||||
idiomatic_version_file_enable_tools = ["node", "python", "bun", "pnpm"]
|
||||
# reads its toolchain line. dotnet's is global.json's sdk.version, which mise installs as it is.
|
||||
idiomatic_version_file_enable_tools = ["node", "python", "bun", "pnpm", "dotnet"]
|
||||
auto_install = true
|
||||
not_found_auto_install = true
|
||||
python.compile = false
|
||||
# mise points GOBIN into Go's install, which is read-only: go install goes to ~/go/bin.
|
||||
go_set_gobin = false
|
||||
# Each .NET SDK in a folder of its own, the shared one's its image: mise would otherwise run every SDK
|
||||
# from one folder of the VM's, which the shared one isn't in.
|
||||
dotnet.isolated = true
|
||||
# The project folder is the user's own: trust its mise.toml without asking.
|
||||
trusted_config_paths = ["/"]
|
||||
T
|
||||
@@ -124,6 +127,17 @@ go=$(awk '$2 == "go" { print $3 }' "$s/tools")
|
||||
if [[ -n $go && "$(cat ~/.config/go/telemetry/mode 2>/dev/null)" != off* ]]; then
|
||||
/opt/devvm/tools/go/"$go"/bin/go telemetry off
|
||||
fi
|
||||
# .NET's global tools (~/.dotnet/tools) find the shared runtime in every shell through
|
||||
# /etc/dotnet/install_location, where .NET's programs look for an installed one: mise sets
|
||||
# DOTNET_ROOT only in the shells it activates.
|
||||
dotnet=$(awk '$2 == "dotnet" { print $3 }' "$s/tools")
|
||||
loc=$(cat /etc/dotnet/install_location 2>/dev/null || true)
|
||||
if [[ -n $dotnet && $loc != "/opt/devvm/tools/dotnet/$dotnet" ]]; then
|
||||
sudo mkdir -p /etc/dotnet
|
||||
echo "/opt/devvm/tools/dotnet/$dotnet" | sudo tee /etc/dotnet/install_location >/dev/null
|
||||
elif [[ -z $dotnet && $loc == /opt/devvm/tools/* ]]; then
|
||||
sudo rm -f /etc/dotnet/install_location
|
||||
fi
|
||||
# Claude Code checks for itself at ~/.local/bin/claude.
|
||||
claude=$(awk '$2 == "claude" { print $3 }' "$s/tools")
|
||||
if [[ -n $claude ]]; then mkdir -p ~/.local/bin; ln -sfn /opt/devvm/tools/claude/"$claude"/claude ~/.local/bin/claude; fi
|
||||
|
||||
+25
-12
@@ -15,26 +15,33 @@ export DEBIAN_FRONTEND=noninteractive
|
||||
# which have no snapshots: they aren't pinned.
|
||||
if [[ $devvm_libc == musl ]]; then
|
||||
# GNU tar: devvm's launch sends files with it (busybox's lacks options it uses). sqlite: an export
|
||||
# of agents' history copies opencode's database without its logins with it.
|
||||
# of agents' history copies opencode's database without its logins with it. icu-libs: the dotnet
|
||||
# shared tool's .NET needs ICU.
|
||||
sudo apk add --no-cache git curl wget ca-certificates build-base unzip jq ripgrep bash coreutils tar \
|
||||
util-linux util-linux-misc losetup findmnt erofs-utils sqlite
|
||||
util-linux util-linux-misc losetup findmnt erofs-utils sqlite icu-libs
|
||||
echo "devvm: Alpine's packages aren't pinned" >&2
|
||||
else
|
||||
# The package lists are apt.sh begin's: base's packages are recorded at its first build and replayed
|
||||
# from devvm's cache after (layers/apt.sh), and a --from image's come from its own sources, unpinned.
|
||||
# erofs-utils: the shared tools' builds make their images with it, in a VM cloned from base. sqlite3:
|
||||
# an export of agents' history copies opencode's database without its logins with it.
|
||||
sudo apt-get install -y git curl wget ca-certificates build-essential unzip jq ripgrep erofs-utils sqlite3
|
||||
# an export of agents' history copies opencode's database without its logins with it. ICU: the dotnet
|
||||
# shared tool's .NET needs it, and its package's name has its version (libicu76), so it's the newest
|
||||
# libicuN the package lists have (a replay's lists have only the one recorded).
|
||||
icu=$(apt-cache pkgnames libicu | grep -E '^libicu[0-9]+$' | sort -V | tail -1 || true)
|
||||
sudo apt-get install -y git curl wget ca-certificates build-essential unzip jq ripgrep erofs-utils sqlite3 ${icu:+"$icu"}
|
||||
fi
|
||||
|
||||
# devvm-fetch URL SHA256 OUT: every layer downloads through this, so an image only ever contains
|
||||
# files whose checksums are pinned in devvm's scripts.
|
||||
# files whose checksums are pinned in devvm's scripts. A SHA-512 (128 hex digits) is checked as one:
|
||||
# the shared tools' build gets the .NET SDK's from the tools lock.
|
||||
sudo tee /usr/local/bin/devvm-fetch >/dev/null <<'SH'
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
url=$1 want=$2 out=$3
|
||||
curl -fsSL --retry 3 -o "$out" "$url"
|
||||
got=$(sha256sum "$out" | cut -d' ' -f1)
|
||||
sum=sha256sum
|
||||
[ "${#want}" -ne 128 ] || sum=sha512sum
|
||||
got=$("$sum" "$out" | cut -d' ' -f1)
|
||||
if [ "$got" != "$want" ]; then
|
||||
rm -f "$out"
|
||||
printf 'devvm-fetch: checksum mismatch for %s\n expected %s\n got %s\n' "$url" "$want" "$got" >&2
|
||||
@@ -70,7 +77,7 @@ fi
|
||||
mkdir -p ~/.bashrc.d
|
||||
grep -qs bashrc.d ~/.bashrc || echo 'for f in ~/.bashrc.d/*.sh; do [ -r "$f" ] && . "$f"; done' >> ~/.bashrc
|
||||
|
||||
# mise runs the shared tools (node, python, go, rust, agents), read-only images mounted at
|
||||
# mise runs the shared tools (node, python, go, rust, dotnet, agents), read-only images mounted at
|
||||
# /opt/devvm/tools by devvm-tools (guest/tools.sh). Each VM's tools and versions are in
|
||||
# /etc/mise/config.toml (written by guest/sync.sh); the user's own mise config and a project's version
|
||||
# files (.nvmrc, .python-version, ...) come first, and versions that aren't shared install into the VM.
|
||||
@@ -82,15 +89,21 @@ rm /tmp/mise
|
||||
# Every shell finds the tools: login shells through profile.d, interactive ones through mise activate
|
||||
# (it follows `cd` into projects with other versions), and the rest (`bash -c` from agents, editors
|
||||
# over SSH) through BASH_ENV and mise's shims. Read-only installs can't take global packages or update
|
||||
# themselves: npm installs globals into ~/.npm-global, and Claude Code's and opencode's auto-updates
|
||||
# are off.
|
||||
# themselves: npm installs globals into ~/.npm-global, Claude Code's and opencode's auto-updates are
|
||||
# off, and dotnet tool install -g installs into ~/.dotnet/tools, which is on the PATH, so the SDK
|
||||
# doesn't add it to a shell's profile on its first run. .NET's telemetry, its first-run banner and
|
||||
# its background check for workload updates are off.
|
||||
sudo tee /etc/profile.d/devvm-tools.sh >/dev/null <<'SH'
|
||||
case ":$PATH:" in *":$HOME/.local/share/mise/shims:"*) ;; *)
|
||||
export PATH="$HOME/.npm-global/bin:$HOME/go/bin:$HOME/.cargo/bin:$HOME/.local/bin:$HOME/.local/share/mise/shims:$PATH" ;;
|
||||
export PATH="$HOME/.npm-global/bin:$HOME/go/bin:$HOME/.cargo/bin:$HOME/.dotnet/tools:$HOME/.local/bin:$HOME/.local/share/mise/shims:$PATH" ;;
|
||||
esac
|
||||
export NPM_CONFIG_PREFIX="$HOME/.npm-global"
|
||||
export DISABLE_AUTOUPDATER=1
|
||||
export OPENCODE_DISABLE_AUTOUPDATE=1
|
||||
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||
export DOTNET_NOLOGO=1
|
||||
export DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=false
|
||||
export DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE=true
|
||||
SH
|
||||
grep -qs devvm-tools /etc/environment || echo 'BASH_ENV=/etc/profile.d/devvm-tools.sh' | sudo tee -a /etc/environment >/dev/null
|
||||
echo 'eval "$(mise activate bash)"' > ~/.bashrc.d/mise.sh
|
||||
@@ -129,7 +142,8 @@ SH
|
||||
sudo chmod 755 /usr/local/bin/xdg-open
|
||||
echo 'export BROWSER=xdg-open' | sudo tee /etc/profile.d/devvm-browser.sh >/dev/null
|
||||
|
||||
# Telemetry off for every tool that has a switch (installed by devvm or commonly by projects).
|
||||
# Telemetry off for every tool that has a switch (installed by devvm or commonly by projects), but
|
||||
# .NET's, which devvm-tools.sh turns off in every shell.
|
||||
sudo tee /etc/profile.d/devvm-telemetry.sh >/dev/null <<'SH'
|
||||
export DO_NOT_TRACK=1 # generic opt-out (bun and others)
|
||||
export DISABLE_TELEMETRY=1 # Claude Code
|
||||
@@ -141,7 +155,6 @@ export NUXT_TELEMETRY_DISABLED=1
|
||||
export GATSBY_TELEMETRY_DISABLED=1
|
||||
export STORYBOOK_DISABLE_TELEMETRY=1
|
||||
export YARN_ENABLE_TELEMETRY=0
|
||||
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||
SH
|
||||
# Ubuntu: no news fetched for the login banner or apt output.
|
||||
sudo sed -i 's/^ENABLED=1/ENABLED=0/' /etc/default/motd-news 2>/dev/null || true
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# (~/.local/share/devvm/mise.lock) in its .build folder. Each tool gets a VM and a folder of its own,
|
||||
# so nothing one tool's installer does, as root or not, reaches another tool's image.
|
||||
# build.sh TOOL VERSION FILE
|
||||
# build.sh dotnet VERSION FILE URL SHA512
|
||||
# The tool is installed at exactly the locked version (checked against the lock's checksums), then
|
||||
# packed into one compressed read-only EROFS image, FILE in that folder; devvm moves it into the share
|
||||
# and records its hash. Project VMs mount it at /opt/devvm/tools/<tool>/<version>, where mise finds it
|
||||
@@ -57,7 +58,8 @@ glibc_needs() {
|
||||
rm -f "$files" "$elf"
|
||||
}
|
||||
[[ $devvm_libc != gnu ]] || command -v readelf >/dev/null || { echo "build.sh: base has no readelf (binutils)" >&2; exit 1; }
|
||||
(( $# == 3 )) || { echo "build.sh: wants TOOL VERSION FILE, got $# arguments" >&2; exit 2; }
|
||||
(( $# == 3 )) || [[ $# == 5 && $1 == dotnet ]] ||
|
||||
{ echo "build.sh: wants TOOL VERSION FILE (dotnet: and URL SHA512), got $# arguments" >&2; exit 2; }
|
||||
tool=$1 version=$2 file=$3
|
||||
|
||||
wait_share
|
||||
@@ -75,6 +77,22 @@ if [[ $tool == rust ]]; then
|
||||
RUSTUP_HOME=$work/rustup CARGO_HOME=$work/cargo "$dir/rustup-init" -y -q --no-modify-path \
|
||||
--profile default --default-toolchain "$version" -c rust-src -c rust-analyzer
|
||||
mv "$work/rustup/toolchains/$version-$triple" "$dir/toolchain"
|
||||
elif [[ $tool == dotnet ]]; then
|
||||
# Microsoft's SDK archive, the lock's download for this platform, which devvm passes with the
|
||||
# SHA-512 the lock records for it: mise's own installer runs Microsoft's install script, which
|
||||
# checks nothing.
|
||||
[[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ && $# == 5 ]] || { echo "build.sh: dotnet wants a release's VERSION, URL and SHA512" >&2; exit 2; }
|
||||
dir=$work/dotnet/$version; mkdir -p "$dir"
|
||||
devvm-fetch "$4" "$5" /tmp/dotnet-sdk.tar.gz
|
||||
tar -xzf /tmp/dotnet-sdk.tar.gz -C "$dir"
|
||||
rm /tmp/dotnet-sdk.tar.gz
|
||||
sdks=$("$dir/dotnet" --list-sdks)
|
||||
[[ $sdks == "$version "* ]] || { echo "build.sh: the archive has another SDK than $version: $sdks" >&2; exit 1; }
|
||||
# Workloads install into the user's ~/.dotnet, which the SDK does when its folder has this marker
|
||||
# for its feature band (10.0.400 for 10.0.403): the SDK's own folder is read-only in VMs.
|
||||
band=${version%.*}.$(( ${version##*.} / 100 * 100 ))
|
||||
mkdir -p "$dir/metadata/workloads/$band"
|
||||
touch "$dir/metadata/workloads/$band/userlocal"
|
||||
else
|
||||
# By name: mise resolves mise.toml's version through the lock (an explicit tool@version isn't
|
||||
# matched to the lock's entry).
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# dotnet: NuGet's packages and tools, and the revocation lists of DigiCert, which issues NuGet's
|
||||
# signing certificates, that NuGet checks each package's signatures against; the SDKs mise installs
|
||||
# for a global.json's version (the install script at dot.net, the SDK's archive). Microsoft's
|
||||
# telemetry is left out.
|
||||
api.nuget.org
|
||||
crl3.digicert.com:80
|
||||
dot.net
|
||||
builds.dotnet.microsoft.com
|
||||
@@ -20,6 +20,7 @@ python = "latest"
|
||||
uv = "latest"
|
||||
go = "latest"
|
||||
rust = "latest" # installed with the rustup pinned in build.sh; rustup checks the toolchain
|
||||
dotnet = "latest" # the SDK; devvm adds its downloads and their SHA-512 from Microsoft's releases
|
||||
claude = "latest"
|
||||
codex = "latest"
|
||||
opencode = "2" # upstream marks its 1.x releases as GitHub's latest, which "latest" resolves to
|
||||
|
||||
@@ -57,7 +57,7 @@ Claude Code needs your Claude login before its first start, which `devvm agent l
|
||||
|
||||
{{< feature title="Toolchains" icon="code" level="3" art="toolchains" >}}
|
||||
|
||||
`devvm` chooses the toolchains your project's files call for, and you can choose more when you customize a new VM or name them with `--tools` ([toolchains](docs/using/toolchains.md)).
|
||||
`devvm` has toolchains for node, python, rust, go and dotnet. It chooses the ones your project's files call for, and you can choose more when you customize a new VM or name them with `--tools` ([toolchains](docs/using/toolchains.md)).
|
||||
|
||||
{{< /feature >}}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Add shared tools to this folder's VM, then open a shell in it
|
||||
|
||||
## Synopsis
|
||||
|
||||
Add shared tools to this folder's VM, then open a shell in it. TOOL is node, python, rust, go, claude, codex or opencode, each a separate word. devvm builds any of them that aren't built, and for a new agent in a running VM it asks before restarting the VM.
|
||||
Add shared tools to this folder's VM, then open a shell in it. TOOL is a toolchain, such as node, or a coding agent, such as claude, each a separate word. devvm builds any of them that aren't built, and for a new agent in a running VM it asks before restarting the VM.
|
||||
|
||||
```text
|
||||
devvm tools add TOOL... [flags]
|
||||
|
||||
@@ -142,7 +142,7 @@ forbidigo matches only the function a call names, so the checks that look at a c
|
||||
|
||||
The structure test also finds a copy of an owner's code by its text, in `literals`. A string literal outside tests that holds `'\''`, the escaped quote a shell quoter writes, belongs in `internal/shell`, and one that holds `[0-9a-f]{14}`, the hash at the end of a project VM's name, belongs in `internal/vmname`. A quote written as a rune, such as `'\''` in Go, isn't a string literal, so it doesn't count. In the same way, `separators` finds a copy of a parser by what it splits on: a call to any function of package `strings` with `+` as an argument, as a literal or as a constant, splits or joins an image's layers, so it belongs in `internal/image`. A call with another argument that holds a `+`, such as `strings.ContainsAny(arg, "+,")`, doesn't count.
|
||||
|
||||
The shared tools have one owner too, the table `image.SharedTools` in `internal/image/tool.go`. Each entry, an `image.ToolDef`, holds a tool's name, its kind (a toolchain or an agent), its members (the tools in the lock that its name stands for, such as pnpm and bun for node), the files in a project folder that call for it, and its installer, which is mise for every tool but rust, which rustup installs. `image.Toolchains`, `image.Agents`, `image.GroupTools`, the files that make devvm choose a toolchain for a new VM, the lock's check for downloads (`image.NoDownload`) and the `devcontainer.json` features that devvm maps to a toolchain all come from it. To add a shared tool, you add its entry, its members to `assets/shared-tools/mise.toml`, its policy as `assets/shared-tools/<name>.policy`, and a section to its user page, `using/toolchains.md` or `using/coding-agents.md`. The [agreement tests](#agreement-tests) fail until the table and those files match.
|
||||
The shared tools have one owner too, the table `image.SharedTools` in `internal/image/tool.go`. Each entry, an `image.ToolDef`, holds a tool's name, its kind (a toolchain or an agent), its members (the tools in the lock that its name stands for, such as pnpm and bun for node), the files in a project folder that call for it, and its installer, which is mise for every tool but rust, which rustup installs, and dotnet, which `assets/shared-tools/build.sh` unpacks from Microsoft's SDK archive. mise locks dotnet's version without a download, because its own installer runs Microsoft's install script, which checks nothing, so devvm adds each platform's archive and its SHA-512 from Microsoft's release metadata to the lock (`withSDKDownloads` in `internal/tools/dotnet.go`), and `Share.Build` passes them to build.sh (`image.OwnDownload`), which checks the archive with `devvm-fetch`. `image.Toolchains`, `image.Agents`, `image.GroupTools`, the files that make devvm choose a toolchain for a new VM, the lock's check for downloads (`image.NoDownload`) and the `devcontainer.json` features that devvm maps to a toolchain all come from it. To add a shared tool, you add its entry, its members to `assets/shared-tools/mise.toml`, its policy as `assets/shared-tools/<name>.policy`, and a section to its user page, `using/toolchains.md` or `using/coding-agents.md`. The [agreement tests](#agreement-tests) fail until the table and those files match.
|
||||
|
||||
The scripts that devvm's builds run with bash have one owner for the machine they run on, `assets/prelude.sh`, whose `$devvm_arch`, `$devvm_libc` and `devvm_sha` give each script its architecture, its C library and its pinned checksum for each download ([the scripts' prelude](../internals/images.md#the-scripts-prelude)). A script reads them rather than run `uname -m` or look for `apk` itself, and checks that the prelude came first with `: "${devvm_arch:?}"` for each variable it reads, which also tells shellcheck that the variable is set. Go reads each of those scripts through `image.OwnScript`, which puts the prelude before it, so a recipe, a tool image's key and the conversion's copy of `oci/build.sh` all hold the two together. `TestPreludeUsers` in `internal/image` fails when a script that doesn't get the prelude, such as `assets/oci/bootify.sh` or `assets/guest/`'s, uses it, or when a script reads a variable without that check. `testdata/script/prelude.txtar` checks which pin `devvm_sha` picks from each script's pins on arm64 and amd64, with glibc and with musl. A CLI test or a Go test that sources one of these scripts sources `assets/prelude.sh` first.
|
||||
|
||||
@@ -379,10 +379,10 @@ The sections so far:
|
||||
- `images`: building base and fixture layers, rebuilds, a failed script and Ctrl+C during a build, then base's recorded packages, each in the cache under its SHA-256, and base built again under the same key with `ubuntu-mirror` set to an address nothing answers on, whose apt reads only the build's own folder of packages.
|
||||
- `project`: devvm in a new project folder (under `/tmp/devvm-go-e2e/p`) makes a VM from base and opens a shell there, which reads its commands from devvm's input. The folder and the shared tools are mounted and nothing else is, there's no SSH agent, no Docker (no docker layer) and the hostname is the folder's. The ssh config lists it as `devvm-web` with its host keys pinned; through an `~/.ssh/config` of the run's own that includes it under a `Host *` forwarding the agent, `ssh devvm-web` works, forwards no agent (a throwaway one), and refuses a changed host key. `.git` is locked (macOS) and git in the VM can still commit. `devvm stop` stops it and drops its entry, and on macOS reports and locks a submodule git folder the VM added. `TestE2EExecQuoting` in `internal/backend/registry`, which runs only there (`DEVVM_E2E_VM` names the VM), checks that arguments with spaces, quotes, `$`, newlines and globs, a folder and input reach the guest as given, through the `Exec` of the backend the VM's state records, so one test covers every backend. Then a VM from a `devcontainer.json`, with no ports by default: its `forwardPorts` said and not forwarded, none reaching this machine, its `containerEnv` in the shell and its commands, its `postCreateCommand` run once in the folder, its `postStartCommand` at each start (again after `devvm restart`), nothing written to the folder, and a changed file warned about without changing the VM. Then a claude VM with a fake agent config, history, git identity and token in a home of its own: `devvm agent import` copies the agent's settings into the sandbox's agent store without the history or the links out of its folder, the store's folder is mounted read-only and linked into the VM's home, and the home folder's isn't mounted, its settings are copied and its history isn't, the VM gets the git identity, the timezone and its hostname, and, open as it is, the token's placeholder and never the token. `devvm agent save` without a terminal shows the VM's changed `settings.json` as a diff and its new `commands` folder's file, then refuses and saves nothing, and after a yes it saves both into the store, but neither the VM's fake login beside them nor the folder's link out of it. Then SSH agents, with a home of their own and throwaway keys: a `--ssh-agent` VM uses a throwaway agent standing for yours; after `devvm ssh-agent add` and `devvm ssh-agent devvm` it keeps yours, in its shell and by name, until a restart, then uses only devvm's own agent's key, in its shells and by name; after `devvm ssh-agent off`, none.
|
||||
- `gc`: a VM from a folder named `img-keep`, which is named like an image, and a fixture layer edited after its build: `devvm gc` deletes the stale image and its record and an old tool image no VM lists (once there's a tools lock), and keeps base and the VM.
|
||||
- `tools`: first, the shared tools resolve to upstream's newest versions, with devvm's pinned mise (downloaded once), each download with its checksum. This section is the only one that uses the newest versions, and no other step checks for them (`DEVVM_NO_TOOL_CHECK`). At the section's end, e2e puts the pinned lock back. Then a node project's VM: node, npm, pnpm, bun and yarn at the locked versions, each a read-only EROFS image, the share read-only even for root, `npm i -g` into the VM's home, a non-login shell over SSH, an `.nvmrc`'s own version, the tools mounted at boot without devvm, and a second node VM that builds nothing.
|
||||
- `tools`: first, the shared tools resolve to upstream's newest versions, with devvm's pinned mise (downloaded once), each download with its checksum. This section is the only one that uses the newest versions, and no other step checks for them (`DEVVM_NO_TOOL_CHECK`). At the section's end, e2e puts the pinned lock back. Then a node project's VM: node, npm, pnpm, bun and yarn at the locked versions, each a read-only EROFS image, the share read-only even for root, `npm i -g` into the VM's home, a non-login shell over SSH, an `.nvmrc`'s own version, the tools mounted at boot without devvm, and a second node VM that builds nothing. Last, a .NET project's VM on the allowlist tier, chosen by its solution file: the shared SDK at the locked version from the share, a console project that restores a package from NuGet, builds and runs, `dotnet tool install -g` into `~/.dotnet/tools` with the tool run from a non-login shell, a workload installed into `~/.dotnet`, nothing of it blocked, and a `global.json`'s own SDK installed into the VM.
|
||||
- `network`: a VM with Claude Code, Codex and opencode and `--network allowlist`, a fake token in devvm's environment and a fake `~/.claude.json` and Codex login in a home of its own, which `devvm agent import` copies into the sandbox's agent store, only yours to read. Its proxy runs and the self-check passed; its password was in no host process's arguments while devvm launched it (`ps`, sampled), and the guest has it; `ssh devvm-net` reaches it; direct connections fail, even as root, to an address and to other ports; an allowed host works and others, or other ports, are blocked; a line in the VM's policy file that reads as a deny but isn't a rule makes the running proxy refuse an allowed host, with no allow command in `devvm network log --blocked`, `devvm network rm` warns of it, and the host works again once it's gone; DNS fails at once; the host's loopback services are out of reach, directly or through the proxy; the proxy refuses requests without the VM's password; the token is nowhere in the VM, which has its own CA and the next one, its own placeholder and logins' copies with placeholders only; the proxy puts the token in for its host (for the VM's own placeholder only), an MCP server's header and Codex's key for theirs, over TLS the VM verifies; a second allowlist VM has CAs of its own, each VM trusts only its own and has no key, each proxy serves and presents only its own VM's CAs, and `devvm rm` deletes one VM's CAs and leaves the other's; the home folder's and the store's login files are unchanged. `devvm agent save` saves the VM's changed `~/.claude.json` with the store's MCP header in place of its placeholder, and once the VM changes that server's URL it leaves the file out, so the store keeps the server as it was. `devvm secret set github --stdin` saves a fake token (in the Keychain on macOS, under the run's service, found through a link to `~/Library/Keychains` in the VM's home), read from a file so it's in no process's arguments, and `devvm secret` lists it saved, while asking `devvm secret` for a `get` subcommand is refused without printing it; `secret use github` binds it to the running proxy at once, and on the next launch the VM has its own placeholder in `GH_TOKEN`, never the token, which the proxy puts in for `api.github.com`; `secret unuse` and `rm` take the binding and the token away. `TestE2ESelfCheck` in `internal/netpolicy` runs the self-check on the VM: it passes, then, once the VM is started outside devvm, it fails and stops the VM. `devvm stop` stops the VM and its proxy at once. `devvm network open` makes its next start direct, its proxy set in the guest and answering, and the open VM holds no real secret either: the token is nowhere in it, its environment and Codex's login hold only its placeholders, its proxy puts the token in over TLS the VM verifies with its own CA, and a request that goes around the proxy carries only the placeholder and gets a 401 from the token's host. Then `devvm network internet` and `devvm network none` change its tier at once, the VM running on. Restarted behind the run's company proxy on this machine's loopback, named in the shell's `HTTPS_PROXY` with a fake password that the check reads from a file, the guest has the proxy and reaches GitHub through it, while devvm's run logs hold the password only as `<password>` and Lima's `ha.stderr.log` only as stars. `devvm network allowlist` while it runs open shows it `unenforced` until `devvm restart` starts it confined; `devvm network open` while it runs confined keeps it on its proxy until it next starts. Behind a company proxy of the run's own that fakes OpenAI's token endpoint with a certificate from the run's CA, a login made in the VM is captured: the store gets the fake tokens and API key, and the VM gets placeholders. Then `devvm agent login codex` runs the real Codex's login in the VM, curl on this machine opens its callback with the state Codex's address names, through the forward of `localhost:1455`, devvm names the account the store saved, the VM's Codex holds only placeholders, and the forward is gone once the login ends, and gone too after an interrupted login. `devvm agent login opencode --device-code` runs the real opencode 2's Codex device code login in the VM, which the fake endpoint answers too, devvm says the store saved the login, and `opencode auth export` in the VM shows only placeholders. A second VM with opencode has `OPENCODE_DISABLE_AUTOUPDATE=1` in its login shell, makes its database and imports a credential of its own, then `devvm agent login opencode --api-key --provider openrouter --stdin` saves a fake key from the first VM, and at the second VM's next launch its opencode has devvm's entry with the key's placeholder, never the key, beside its own credential, and once its database is deleted and made again, the next launch gives it the key's placeholder again. The same company proxy fakes Claude's token endpoint and Anthropic's API, which logs the token each request brings: `cLine truncated
|
||||
- `nix`: the nix layer. A copy of `assets/layers/nix.sh` as a layer of the run's own, built behind a company proxy of the run's own, reaches Nix's releases through it and leaves no proxy settings for `nix-daemon` (and not the company proxy's password) anywhere on its image's disk. Then a folder with `package.json`, `flake.nix` and `.envrc` gets a VM with node on the nix layer (`--layers nix`) on the allowlist tier: Nix and direnv at their pins, a store that's root's, `sandbox` on with no fallback, `trusted-users` root alone and an untrusted user's `--option substituters` ignored, `nix-daemon` with the VM's own proxy in devvm's drop-in alone, `nix run nixpkgs#hello` from Nix's cache, a build in Nix's sandbox, `sudo nix` and `nix` over ssh, the flake's dev shell (nixpkgs at a pinned revision) loaded by direnv in an interactive shell, its `node` ahead of the shared node prompt after prompt and gone outside the folder, nix-direnv's cache in the VM's home with no `.direnv` in the folder, a fixed-output download from a host that isn't allowed refused with `403` and named by `devvm-why`, and after `devvm network open` and `devvm restart`, no drop-in and no proxy for the daemon.
|
||||
- `from`: run with a `docker` that isn't running, so nothing comes from Docker. Its container images go by their pinned digests, as `node:24@sha256:…`, so devvm looks them up nowhere, except the company proxy's `alpine:3.21`, which keeps its tag so that devvm's registry lookup is checked too. A VM from `node:24` with node, python and Claude Code on the docker and nix layers (Debian 12, in a home of its own) boots, with its base keyed by the pinned digest, its node, python and claude at the locked versions, GNU `tar` as its commands find it, its tool images built in a clone of devvm's own Ubuntu base when the run builds them, the docker layer's Docker from Docker's Debian repository, and the nix layer's Nix under systemd running `nix run nixpkgs#hello` and a build in Nix's sandbox; a VM from `alpine:3` with node on the docker, nix and desktop layers runs node and pnpm from musl tool images, built in its own base and keyed and recorded by its digest, the docker layer's Docker on OpenRC, the desktop layer's programs from Alpine's packages, with no crashed services, and the nix layer's Nix as an OpenRC service, with `nix run nixpkgs#hello` and a sandboxed build, then after `devvm network allowlist` and `devvm restart` a download only its daemon makes from a host that isn't allowed refused with the proxy's `403`, and with GNU `tar` as its commands find it, `devvm history import` puts an export into it, while an export with a path outside the agents' history imports nothing there; base builds from `ubuntu:26.04`; and the build VM and its temporary folders are gone.
|
||||
- `from`: run with a `docker` that isn't running, so nothing comes from Docker. Its container images go by their pinned digests, as `node:24@sha256:…`, so devvm looks them up nowhere, except the company proxy's `alpine:3.21`, which keeps its tag so that devvm's registry lookup is checked too. A VM from `node:24` with node, python and Claude Code on the docker and nix layers (Debian 12, in a home of its own) boots, with its base keyed by the pinned digest, its node, python and claude at the locked versions, GNU `tar` as its commands find it, its tool images built in a clone of devvm's own Ubuntu base when the run builds them, the docker layer's Docker from Docker's Debian repository, and the nix layer's Nix under systemd running `nix run nixpkgs#hello` and a build in Nix's sandbox; a VM from `alpine:3` with node and dotnet, which its `package.json` and `global.json` call for, on the docker, nix and desktop layers runs node and pnpm from musl tool images, and dotnet's musl SDK with ICU, which makes and runs a console project, built in its own base and keyed and recorded by its digest, the docker layer's Docker on OpenRC, the desktop layer's programs from Alpine's packages, with no crashed services, and the nix layer's Nix as an OpenRC service, with `nix run nixpkgs#hello` and a sandboxed build, then after `devvm network allowlist` and `devvm restart` a download only its daemon makes from a host that isn't allowed refused with the proxy's `403`, and with GNU `tar` as its commands find it, `devvm history import` puts an export into it, while an export with a path outside the agents' history imports nothing there; base builds from `ubuntu:26.04`; and the build VM and its temporary folders are gone.
|
||||
|
||||
- `link`: links between VMs, each check the end-to-end proof of a row of the threat check in [the design note](../internals/design.md#links-between-vms). It runs devvm with a soft limit of 256 open files, macOS's default, as the link sessions it starts get that limit too, and it makes two small open targets, each forwarding no port and running servers on its own `127.0.0.1` (`/var/tmp/e2e-link.pl`, in perl, which every base has), and a client that forwards every port. Each of the three reserves the link checks' ports (`ip_local_reserved_ports`), so Linux never gives one to a connection's own end, where a connection that just ended would hold it for a minute and a later server or `ssh -R` couldn't bind it. `sshd -T` in each VM shows remote forwards allowed on `127.77.*:*` alone, at the address the host asks for, and the client's own Lima rules ignore every port. A port the target doesn't publish is refused by `devvm link add`, and once a port is published, `devvm link add` on the running client reaches it within seconds as `NAME:PORT` and `NAME.devvm.internal:PORT`, by curl and by a raw TCP client (bash's `/dev/tcp`), while with `--as NAME` the target's folder name doesn't resolve. Two targets on one port are each reached by their own name, port 80 is linked on port 80, `devvm link` and `devvm link publish` list what they hold with `"version": 1` in their `--json`, and `devvm network allowlist` is refused for the client while it links to open targets. A published port that isn't linked has nothing listening for it, `devvm link unpublish` refuses the link's next connection, logs it and names the client, and `devvm link rm` takes the listener away within seconds. In the client, sshd listens only on its own port and the links' addresses, and nothing from a link listens on `127.0.0.1`, `::1` or every address, so this machine gets no forward of a link, while a server of the client's own on `127.0.0.1` with a link's port is forwarded as usual. Each link's socket is mode 600 in the run folder of mode 700, and the link session and every process it starts listen on no TCP port and connect only to the VMs' ssh ports. `ssh -R` into the client binds nothing outside `127.77.0.0/16` (`rfwd_links`). A program in the client that holds a link's address first fails that link alone with `link_port_taken`, 256 connections at once, past the socket's backlog of 128 on macOS, are all carried, and a 257th is refused and logged as `link_limit`. Root in the client then loosens its sshd and the link session connects again: with `PermitListen any` the client binds only the links' addresses, because the host asks for nothing else, and with `GatewayPorts yes` too, the link session still listens on no TCP port of this machine and connects only to the VMs' sshd. `devvm network log` shows the links' connections and refusals. A stopped target refuses the connection, logs `link_target_stopped` and stays stopped, and the client's launch warns of it. Once it's restarted, the link works again. `devvm rm` of the target removes the client's link, names the client and removes its sockets, and a VM made again in that folder isn't linked. Then the client and one target get the allowlist tier, the target while it runs. Until the target restarts, `devvm ls` shows it `unenforced`, the client's next connection is refused and logged as `unenforced` while the target's server runs, and `devvm link add` and the client's launch warn of it (`link_target_unenforced`). Once both have restarted, the client reaches its link by curl through its proxy settings and by a raw TCP client while a direct connection fails. A link added while the client runs is reached at once by curl through its proxy, by `GET` and `CONNECT`, with no link name in `NO_PROXY` and the client's boot and host keys unchanged, and the client's proxy refuses names, ports and addresses that aren't on its own list, while the target's proxy refuses the client's link name. `devvm link add` refuses an open target, `devvm network open` is refused for the target, and with the rule broken by hand in the target's state the next connection is refused and the client's launch warns and runs without the link until the rule holds again. In the `--from` tier, an Alpine client reaches its link to port 80. `devvm rm` of the client leaves no link session, socket, pid file, log or link state.
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ A new VM gets what the project's `devcontainer.json` says, as far as devvm does
|
||||
|
||||
- **Reading:** only in the folder, through `os.Root` (a link out of it isn't followed, `..` included), opened without blocking (a FIFO the VM made in its place opens at once and is refused) and checked as a regular file on the open descriptor, at most 1 MiB. It's read once, at `plan`; what the VM is made from is the parsed plan, recorded in its state, never the file read again. Later launches only hash it and warn.
|
||||
- **Parsing:** comments and trailing commas are blanked at the same offsets, strings untouched, then `encoding/json`; values of the wrong kind, a NUL, an environment variable's name that isn't one, and every variable devvm doesn't fill in are refused before anything's made, `${localEnv:…}`/`${env:…}` above all. Nothing is filled in from this machine: `${containerWorkspaceFolder}` is the folder's path (the same in the VM), `${containerEnv:X}` the VM's own `X`, left to its shell.
|
||||
- **Mapped, or refused, or ignored:** `build`/Dockerfiles/Compose are refused; `initializeCommand` never runs; `mounts`, `runArgs`, `privileged`, `capAdd`, `securityOpt`, `workspaceMount` and the rest are ignored, named. Features map only to devvm's own layers (docker-in-docker to the docker layer, four toolchains); no feature's script is fetched, `docker-outside-of-docker` is refused, everything else too.
|
||||
- **Mapped, or refused, or ignored:** `build`/Dockerfiles/Compose are refused; `initializeCommand` never runs; `mounts`, `runArgs`, `privileged`, `capAdd`, `securityOpt`, `workspaceMount` and the rest are ignored, named. Features map only to devvm's own layers (docker-in-docker to the docker layer, five toolchains); no feature's script is fetched, `docker-outside-of-docker` is refused, everything else too.
|
||||
- **The image:** `--from`'s path, but only an image its registry gives anyone: asked anonymously (`from.Lookup.Public`, never Docker's store), pinned to that digest, which the build pulls by. A registry named `localhost` or by an address that isn't the internet's is refused by name, and the lookup's client (`from.NewPublicRegistry`) connects only to the internet's addresses, whatever a name resolves to, its token service's included; offline, only a registry digest recorded for that reference stands in.
|
||||
- **The docker layer:** the backend's own rules for it, as when it's named; the file never changes the VM's tier.
|
||||
- **The environment:** each variable's value is built as a shell word (single-quoted text, `"${X}"` for the VM's own), stored as JSON in the VM's state, and written as `export NAME=word` into the VM's environment file before devvm's own (which win); a name is checked again when it's written.
|
||||
|
||||
@@ -195,10 +195,18 @@ Before a build, devvm reads the record of the base it's about to clone and refus
|
||||
|
||||
A glibc build also measures the newest glibc version that each tool needs, because each upstream download is built against a glibc of its own and doesn't run on an older one. After installing the tool, the build script reads the version needs of every ELF program and library in it with `readelf`, which base's `build-essential` installs, and writes the newest `GLIBC_` version they name into `<image>.glibc`, or nothing when none needs one. It leaves out folders named `testdata`, because Go's has ELF files from other systems that nothing runs. devvm takes that file only as a plain file holding one version (`tool_bad_output`) and keeps the version in the image's record (`glibc`). Before it gives a VM its tools, devvm compares each image's version with the glibc of the VM's `--from` base, and an older base refuses the tool, naming it and both versions (`tool_needs_glibc`). It checks the same way when `devvm tools add`, `devvm tools update` or `devvm update` gives an existing VM tools, against the glibc its state recorded when it was made. A base from Ubuntu's cloud image has no glibc version in its record, so its tools aren't checked, and a musl base gets musl builds, which need no glibc. Only one build at a time writes to the share, because each holds the share's lock, `~/.local/share/devvm/tools.lock`, outside the share that VMs mount. Another devvm waits for it, saying so (`share_waiting`) after 3 seconds, until the build ends or you press Ctrl+C. The lock is an OS lock on an open file, so the system releases it when its devvm ends, however it ends, and a devvm that crashed or that you killed never leaves another one waiting.
|
||||
|
||||
Each tool image is named `<tool>-<version>-<key>.erofs`. Its key hashes the tool's entry in the tools lock (its version, its downloads and their checksums), `assets/shared-tools/build.sh` with [the prelude](#the-scripts-prelude) before it, the `[settings]` table of `assets/shared-tools/mise.toml`, the version of mise that `assets/layers/base.sh` pins, the C library the image is built for, the base it builds in (devvm's own for glibc, and for musl the digest of the `--from` base), and the backend's format. The build VM is made from base, so base's mise is the one that installs the tool, and a new mise builds every tool image it installs again. Rust is the exception, because rustup installs it, so mise's version isn't in its key. The tests check that `base.sh` pins the same mise as the one devvm runs on the host, with the same Linux checksums. devvm reads the lock as TOML and hashes what the tool's entry says, the entry of the version the image installs, so a mise that writes the same lock in another order, with other spacing or quoting, leaves every key as it is. The settings are in the key because they change what mise installs, such as `python.compile`, and the key reads what they say in the same way, so a comment or another way of writing the same settings leaves it as it is. Lima's format is `build.sh`'s own, compressed EROFS, which adds nothing to the key. A new version, a new download, an edited build script or a changed setting builds the image again, and a base with a different C library, such as Alpine's musl, gets an image of its own, and so would a VM on another backend. Every glibc image's key names devvm's own base, because glibc images build only there, so a VM on Ubuntu's base and one on a `--from` Debian image share them. A musl image's key has its base's digest, so when the container image's tag moves to a new image, its VMs' next tools build again in the new base. When the lock has no download of a tool for the VM's platform, devvm doesn't build it and says to try again later (`tool_unbuilt`).
|
||||
Each tool image is named `<tool>-<version>-<key>.erofs`. Its key hashes the tool's entry in the tools lock (its version, its downloads and their checksums), `assets/shared-tools/build.sh` with [the prelude](#the-scripts-prelude) before it, the `[settings]` table of `assets/shared-tools/mise.toml`, the version of mise that `assets/layers/base.sh` pins, the C library the image is built for, the base it builds in (devvm's own for glibc, and for musl the digest of the `--from` base), and the backend's format. The build VM is made from base, so base's mise is the one that installs the tool, and a new mise builds every tool image it installs again. A tool that `build.sh` installs itself, without mise, doesn't have mise's version in its key, because mise doesn't install it: rustup installs rust, and dotnet comes from Microsoft's own archive ([dotnet's download](#dotnets-download)). The tests check that `base.sh` pins the same mise as the one devvm runs on the host, with the same Linux checksums. devvm reads the lock as TOML and hashes what the tool's entry says, the entry of the version the image installs, so a mise that writes the same lock in another order, with other spacing or quoting, leaves every key as it is. The settings are in the key because they change what mise installs, such as `python.compile`, and the key reads what they say in the same way, so a comment or another way of writing the same settings leaves it as it is. Lima's format is `build.sh`'s own, compressed EROFS, which adds nothing to the key. A new version, a new download, an edited build script or a changed setting builds the image again, and a base with a different C library, such as Alpine's musl, gets an image of its own, and so would a VM on another backend. Every glibc image's key names devvm's own base, because glibc images build only there, so a VM on Ubuntu's base and one on a `--from` Debian image share them. A musl image's key has its base's digest, so when the container image's tag moves to a new image, its VMs' next tools build again in the new base. When the lock has no download of a tool for the VM's platform, devvm doesn't build it and says to try again later (`tool_unbuilt`).
|
||||
|
||||
An image is base and its layers alone, and a VM's shared tools are a list in its state (the `tools` section's `names`) beside its image. `build.Names` refuses a shared tool's name in an image name (`tool_not_layer`), so `devvm build`, `devvm rebuild` and `devvm images rm` refuse one, because shared tools aren't images and their versions come from the lock.
|
||||
|
||||
### dotnet's download
|
||||
|
||||
mise resolves dotnet's version like any tool's, but it locks the version alone, without a download, because its installer runs Microsoft's install script, which nothing pins. So devvm adds each platform's SDK archive to the lock itself (`withSDKDownloads` in `internal/tools/dotnet.go`). For each dotnet entry that lacks a platform's download, it fetches the channel's list of releases, `https://builds.dotnet.microsoft.com/dotnet/release-metadata/<channel>/releases.json`, over HTTPS and capped at 32 MB, and it records that platform's `dotnet-sdk-<rid>.tar.gz` with its SHA-512. It keeps a file only when its URL is under `https://builds.dotnet.microsoft.com/dotnet/` and its hash is 128 hex digits, and a version that Microsoft doesn't list gets no download, so devvm doesn't build it. The image's key hashes that lock entry, its URLs and checksums included, as it does every tool's.
|
||||
|
||||
`build.sh` gets the URL and the SHA-512 from devvm and downloads the archive with `devvm-fetch`, which checks a 128-character checksum as a SHA-512 and any other as a SHA-256, and which deletes the file and fails when the sum differs. The script unpacks the archive and checks that `dotnet --list-sdks` names the locked version. The SDK's folder is read-only in VMs, so the script puts a `userlocal` marker in its `metadata/workloads/<band>` folder, for its feature band (10.0.400 for 10.0.403), which makes `dotnet workload install` install into `~/.dotnet` in the VM. In the VM, `sync.sh` writes the shared SDK's folder into `/etc/dotnet/install_location`, where .NET's programs look for an installed runtime, so global tools find it in every shell and not only those that mise activates, and it sets mise's `dotnet.isolated`, which gives each SDK a folder of its own, so the shared one runs from its image.
|
||||
|
||||
The trust root is Microsoft's `releases.json`, read over HTTPS, which is the same model as the upstream checksums that mise locks for the other tools. An SDK that a project's `global.json` asks for is different: mise installs it in the VM with Microsoft's install script, which checks only HTTPS and the download's size, and it stays in that VM's home, so no image or other VM gets it.
|
||||
|
||||
## A company's CA in builds
|
||||
|
||||
Build VMs trust the CA certificates in `~/.config/devvm/ca` ([a company's CA](../using/settings.md#a-companys-ca)) while they build, and images never keep them. [Network tiers](network.md#a-companys-ca) describes how devvm reads them and how `assets/guest/ca.sh` installs them.
|
||||
|
||||
@@ -6,7 +6,7 @@ weight: 20
|
||||
These pages cover what you change as you work, such as the images VMs are made from, their ports and size, your coding agents, and the editors you connect with.
|
||||
|
||||
- [Coding agents](coding-agents.md): the supported agents, which are Claude Code, Codex and opencode, the config they get in a VM, their logins, and their history.
|
||||
- [Toolchains](toolchains.md): node, python, rust and go, with what each brings, the files that choose it, its version files, its global installs and its allowlist.
|
||||
- [Toolchains](toolchains.md): the list of toolchains, with what each brings, the files that choose it, its version files, its global installs and its allowlist.
|
||||
- [SSH and editors](ssh.md): reaching VMs by name from ssh and VS Code, and forwarding your SSH agent.
|
||||
- [Ports and size](ports-size.md): the ports a VM forwards to your machine, and its CPUs, memory and disk.
|
||||
- [Managing VMs](vms.md): restarting, stopping, deleting and listing VMs, and what devvm does in a subfolder or when a project folder is made again, moved, deleted or on a disk that isn't connected.
|
||||
|
||||
@@ -60,7 +60,7 @@ When the file is gone, devvm makes the VM again without it, so what the file gav
|
||||
| Property | What devvm does |
|
||||
| --- | --- |
|
||||
| `image` | The VM's base starts from it, as with [`--from`](from.md). devvm uses only an image that its registry gives anyone who asks anonymously, pinned to that digest. It never uses an image only Docker has, one only your registry login reaches, or one on this machine or its network, which is `localhost` or a registry whose address is loopback, private or link-local, by name or as it resolves. |
|
||||
| `features` | `ghcr.io/devcontainers/features/docker-in-docker` is devvm's [docker layer](images.md#built-in-layers). `node`, `python`, `rust` and `go` under `ghcr.io/devcontainers/features/` are the [shared toolchains](images.md#shared-tools). devvm ignores their options and says so in one line. It refuses `docker-outside-of-docker`, which is this machine's Docker, and every other feature. devvm never fetches or runs a feature's script. |
|
||||
| `features` | `ghcr.io/devcontainers/features/docker-in-docker` is devvm's [docker layer](images.md#built-in-layers). A feature under `ghcr.io/devcontainers/features/` named after one of devvm's [toolchains](toolchains.md), such as `ghcr.io/devcontainers/features/node`, is that shared toolchain. devvm ignores their options and says so in one line. It refuses `docker-outside-of-docker`, which is this machine's Docker, and every other feature. devvm never fetches or runs a feature's script. |
|
||||
| `forwardPorts` | devvm forwards numbers, `localhost:N` and `127.0.0.1:N` to this machine's `localhost` alone, adding them to your ports as `devvm ports add` does ([ports](ports-size.md#ports)). With every port forwarded, which is the default, they're among them already. `devvm ports rm` takes one out, as for any port. It ignores other hosts' ports and says so in one line. |
|
||||
| `containerEnv`, `remoteEnv` | The VM's environment, which login shells and the commands below get. `remoteEnv` wins over `containerEnv`, and devvm's own variables, such as `LANG` and secrets, win over both. A `remoteEnv` of `null` sets nothing. |
|
||||
| `onCreateCommand`, `updateContentCommand`, `postCreateCommand` | They run once, in that order, once the VM is made and set up ([commands](#commands)). |
|
||||
|
||||
@@ -41,7 +41,7 @@ If the image's tag moves to another image while devvm builds, for example becaus
|
||||
- **Alpine** uses OpenRC and musl, so its VMs get musl builds of the shared tools, built on that image and kept apart for it. Its base also gets GNU `tar` from Alpine's packages in place of busybox's, because devvm sends the VM's setup and [imports agents' history](coding-agents.md#importing-history) with it.
|
||||
- **Unpinned packages.** While `base` builds, its packages come from the container image's own sources as they are then, apt's or Alpine's, and so do the [desktop layer](images.md#desktop)'s, the [docker layer](images.md#docker)'s on Alpine and the [nix layer](images.md#nix)'s. devvm keeps no copy of them, unlike base from Ubuntu's image, so building the same base again installs the sources' packages of that day, and it needs the network for them.
|
||||
- **A glibc new enough for your shared tools.** A Debian or Ubuntu image's glibc must be at least as new as each shared tool needs, which [shared tools and glibc](#shared-tools-and-glibc) covers.
|
||||
- **Tested.** The end-to-end tests make VMs from `node:24` (Debian 12, with node, python, claude and the docker and nix layers) and `alpine:3` (with node and the docker, nix and desktop layers), and build `base` from `ubuntu:26.04`.
|
||||
- **Tested.** The end-to-end tests make VMs from `node:24` (Debian 12, with node, python, claude and the docker and nix layers) and `alpine:3` (with node, dotnet and the docker, nix and desktop layers), and build `base` from `ubuntu:26.04`.
|
||||
|
||||
## Shared tools and glibc
|
||||
|
||||
|
||||
@@ -103,12 +103,12 @@ The VM keeps what [a VM made again keeps](#what-a-vm-made-again-keeps), its home
|
||||
|
||||
## Shared tools
|
||||
|
||||
The toolchains and coding agents are shared tools, not image layers. A VM of any image can have them, in any mix, such as node, python and Claude Code on base, or go and Codex on `foo`. A VM's state lists its shared tools apart from its image. [Toolchains](toolchains.md) lists node, python, rust and go, with what each brings, and [supported agents](coding-agents.md#supported-agents) lists claude, codex and opencode.
|
||||
The toolchains and coding agents are shared tools, not image layers. A VM of any image can have them, in any mix, such as node and Claude Code on base, or go and Codex on `foo`. A VM's state lists its shared tools apart from its image. [Toolchains](toolchains.md) lists the toolchains, with what each brings, and [supported agents](coding-agents.md#supported-agents) lists claude, codex and opencode.
|
||||
|
||||
devvm builds each tool version once and mounts it read-only into every VM that has it, so any mix of tools works without building anything new, and ten VMs with node share one copy of it. The builds are in `~/.local/share/devvm/tools`. Each C library gets a build of its own, so when an Alpine VM and an Ubuntu VM both have node 24, `devvm images` lists two builds of that version ([what devvm keeps](space.md#shared-tools)). An Alpine VM's builds are only ever shared with VMs on the same container image, as [shared tools and glibc](from.md#shared-tools-and-glibc) explains. [mise](https://mise.jdx.dev) runs the tools:
|
||||
|
||||
- **They work as usual.** `node`, `npm i -g` (into `~/.npm-global`), `pnpm`, `yarn`, `pip` and `uv`, `go install` (into `~/go/bin`) and `cargo` work from any shell, including `bash -c` from agents and from editors over SSH.
|
||||
- **A project's own version files win.** `.nvmrc`, `.node-version`, `.python-version`, `rust-toolchain.toml` and the `toolchain` line in `go.mod` pick their version, which installs into the VM the first time it's used. mise also reads a `mise.toml` in the project folder, and devvm trusts it without asking, because the folder is yours.
|
||||
- **They work as usual.** Each toolchain's commands, such as `npm i -g` (into `~/.npm-global`) or `go install` (into `~/go/bin`), work from any shell, including `bash -c` from agents and from editors over SSH. Global installs go into your home, as [each toolchain's section](toolchains.md) says.
|
||||
- **A project's own version files win.** `.nvmrc`, `.node-version`, `.python-version`, `rust-toolchain.toml`, the `toolchain` line in `go.mod` and the SDK version in `global.json` pick their version, which installs into the VM the first time it's used. mise also reads a `mise.toml` in the project folder, and devvm trusts it without asking, because the folder is yours.
|
||||
- **They're read-only.** A VM can't change the shared tools, even as root. The tools can't update themselves, and `rustup component add` can't change the shared toolchain.
|
||||
- **They're mounted, or the launch stops.** When one of a VM's tools is missing or the VM can't mount it, devvm stops the launch and names the tool, and the VM never downloads its own copy in its place ([a shared tool doesn't mount](troubleshooting.md#a-shared-tool-doesnt-mount)). Only the versions that a project's own version files pick install into the VM.
|
||||
|
||||
@@ -244,7 +244,7 @@ The second table lists the [shared tools](#shared-tools) that devvm has built, b
|
||||
|
||||
| Column | |
|
||||
| --- | --- |
|
||||
| `NAME` | `node`, `python`, `rust`, `go`, `claude`, `codex` or `opencode` |
|
||||
| `NAME` | a [toolchain](toolchains.md)'s name, such as `node`, or an agent's, such as `claude` |
|
||||
| `TOOL`, `VERSION` | the tool and its version |
|
||||
| `LIBC` | the C library (`gnu`, or `musl` for an Alpine base) that this build is for, because each gets a build of its own, or `-` when devvm can't tell |
|
||||
| `SIZE` | the disk it takes |
|
||||
|
||||
@@ -3,7 +3,17 @@ title: Toolchains
|
||||
weight: 2
|
||||
---
|
||||
|
||||
devvm has four toolchains: node, python, rust and go. A new VM gets the ones its folder's files call for, which the summary of the new VM shows, unless you customize the VM and check others in the list or give others with `--tools`, as in `devvm --tools node,python` ([what a new VM gets](images.md#what-a-new-vm-gets)). Each section below says what the toolchain brings and which files make devvm choose it. A project that gets its toolchain from Nix uses the `nix` layer, which [Nix projects](#nix-projects) covers.
|
||||
devvm has these toolchains:
|
||||
|
||||
| Toolchain | What it brings |
|
||||
| --- | --- |
|
||||
| [node](#node) | Node 24, with npm, pnpm, yarn and bun |
|
||||
| [python](#python) | CPython, with pip and uv |
|
||||
| [rust](#rust) | rustup, cargo and the stable toolchain |
|
||||
| [go](#go) | Go |
|
||||
| [dotnet](#dotnet) | the .NET SDK and its runtimes |
|
||||
|
||||
A new VM gets the ones its folder's files call for, which the summary of the new VM shows, unless you customize the VM and check others in the list or give others with `--tools`, as in `devvm --tools node,python` ([what a new VM gets](images.md#what-a-new-vm-gets)). Each section below says what the toolchain brings and which files make devvm choose it. A project that gets its toolchain from Nix uses the `nix` layer, which [Nix projects](#nix-projects) covers.
|
||||
|
||||
## node
|
||||
|
||||
@@ -41,6 +51,15 @@ go brings the newest Go release, and devvm turns Go's telemetry off in the VM.
|
||||
- **Global installs.** `go install` installs into `~/go/bin` in the VM, which is on the `PATH`.
|
||||
- **Allowlist.** On the allowlist tier, the VM can reach Go's module proxy, its checksum database and Go's downloads, which are `proxy.golang.org`, `sum.golang.org`, `go.dev` and `dl.google.com`.
|
||||
|
||||
## dotnet
|
||||
|
||||
dotnet brings the newest release of the .NET SDK, with the .NET and ASP.NET Core runtimes that come with it, and devvm turns off .NET's telemetry and its first-run banner in the VM.
|
||||
|
||||
- **Files.** devvm chooses dotnet for a folder with a solution (`*.sln` or `*.slnx`), a C# or F# project (`*.csproj` or `*.fsproj`) or `global.json` at its top level.
|
||||
- **Versions.** The `sdk.version` in a project's `global.json` picks its SDK, which installs into the VM the first time it's used. mise installs exactly that version and doesn't follow `rollForward`, so a `global.json` that allows a newer SDK still gets the one it names, and a `global.json` without an SDK version keeps the shared one. mise installs that SDK with Microsoft's install script, which checks only the download's size, while devvm checks the shared SDK against the SHA-512 that Microsoft publishes for it.
|
||||
- **Global installs.** `dotnet tool install -g` installs into `~/.dotnet/tools` in the VM, which is on the `PATH`, and NuGet keeps its packages in `~/.nuget/packages`. The shared SDK is read-only, so `dotnet workload install` installs workloads into `~/.dotnet` in the VM instead of the SDK's folder.
|
||||
- **Allowlist.** On the allowlist tier, the VM can reach NuGet, the revocation lists that NuGet checks packages' signatures against, and the SDK downloads that a `global.json` asks for, which are `api.nuget.org`, `crl3.digicert.com` on port 80, `dot.net` and `builds.dotnet.microsoft.com`. Microsoft's telemetry isn't on the allowlist.
|
||||
|
||||
## Nix projects
|
||||
|
||||
A project whose toolchain comes from Nix gets the [`nix` layer](images.md#nix), which brings Nix, direnv and nix-direnv into its VM. For a folder with `flake.nix`, `shell.nix` or `devenv.nix` at its top level, or with a `default.nix` that makes a shell with `mkShell`, the list devvm shows when you customize a new VM names that file in the `nix` row, and you choose it there. A layer isn't chosen by default, so a VM made as its summary shows, or without a terminal, gets it only with `--layers nix`, as in `devvm --layers nix` in a folder with `package.json` and `flake.nix`, which gives node on the `nix` layer.
|
||||
@@ -89,13 +108,13 @@ What this doesn't cover:
|
||||
|
||||
## How toolchains are shared and updated
|
||||
|
||||
The toolchains are [shared tools](images.md#shared-tools), like the [coding agents](coding-agents.md#supported-agents), so they aren't part of any image. devvm builds each version once and mounts it read-only into every VM that has it, and [mise](https://mise.jdx.dev) runs it, so `node`, `python`, `cargo` and `go` work from any shell in the VM, including `bash -c` from agents and from editors over SSH. Because the shared copy is read-only, a toolchain can't update itself, and anything you install globally goes into your home in the VM, as each section above says.
|
||||
The toolchains are [shared tools](images.md#shared-tools), like the [coding agents](coding-agents.md#supported-agents), so they aren't part of any image. devvm builds each version once and mounts it read-only into every VM that has it, and [mise](https://mise.jdx.dev) runs it, so `node`, `python`, `cargo`, `go` and `dotnet` work from any shell in the VM, including `bash -c` from agents and from editors over SSH. Because the shared copy is read-only, a toolchain can't update itself, and anything you install globally goes into your home in the VM, as each section above says.
|
||||
|
||||
devvm follows each toolchain's newest release, and Node 24 for node. [Which bases they run on](#which-bases-they-run-on) says what each one needs from a VM's base. [Adding and removing tools](#adding-and-removing-tools) explains how `devvm update` and `devvm tools update` move a VM to newer versions, how `devvm tools add` adds a toolchain to an existing VM, and how `devvm tools rm` takes one out. [What a new VM gets](images.md#what-a-new-vm-gets) explains what happens when a folder calls for more than one toolchain.
|
||||
|
||||
## Which bases they run on
|
||||
|
||||
Every toolchain runs on `base` from Ubuntu's own image, and on an Alpine-based image with [`--from`](from.md), which gets musl builds of the tools. On a Debian- or Ubuntu-based image, each tool needs at least the glibc version that its prebuilt release was built against. devvm measures that version from the tool's files whenever it builds a new version, and it refuses a tool whose version is newer than the image's glibc ([shared tools and glibc](from.md#shared-tools-and-glibc)). Today the shared tools need these glibc versions, so Debian 10 and Ubuntu 20.04 and newer images run all of them:
|
||||
Every toolchain runs on `base` from Ubuntu's own image, and on an Alpine-based image with [`--from`](from.md), which gets musl builds of the tools. dotnet also needs ICU, the Unicode library that .NET's globalization uses, so devvm installs ICU in `base`, whether it's made from Ubuntu's image or `--from` a container image. On a Debian- or Ubuntu-based image, each tool needs at least the glibc version that its prebuilt release was built against. devvm measures that version from the tool's files whenever it builds a new version, and it refuses a tool whose version is newer than the image's glibc ([shared tools and glibc](from.md#shared-tools-and-glibc)). Today the shared tools need these glibc versions, so Debian 10 and Ubuntu 20.04 and newer images run all of them:
|
||||
|
||||
| Shared tool | arm64 | amd64 |
|
||||
| --- | --- | --- |
|
||||
@@ -105,6 +124,7 @@ Every toolchain runs on `base` from Ubuntu's own image, and on an Alpine-based i
|
||||
| uv, with python | 2.28 | 2.17 |
|
||||
| rust, with rustup | 2.17 | 2.17 |
|
||||
| go | none, because its programs need no glibc | none |
|
||||
| dotnet | 2.27 | 2.27 |
|
||||
| claude and opencode | 2.17 | 2.17 |
|
||||
| codex | 2.28, for its voice helper | 2.28 |
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestCompleteParts(t *testing.T) {
|
||||
flag, in string
|
||||
want []string
|
||||
}{
|
||||
{"tools", "", []string{"node", "python", "rust", "go", "none"}},
|
||||
{"tools", "", []string{"node", "python", "rust", "go", "dotnet", "none"}},
|
||||
{"tools", "node,p", []string{"node,python"}},
|
||||
{"agents", "c", []string{"claude", "codex"}},
|
||||
{"agents", "n", []string{"none"}},
|
||||
@@ -58,7 +58,7 @@ func TestCompleteToolNames(t *testing.T) {
|
||||
}{
|
||||
{nil, "c", []string{"claude", "codex"}},
|
||||
{[]string{"claude"}, "c", []string{"codex"}},
|
||||
{[]string{"node"}, "", []string{"python", "rust", "go", "claude", "codex", "opencode"}},
|
||||
{[]string{"node"}, "", []string{"python", "rust", "go", "dotnet", "claude", "codex", "opencode"}},
|
||||
{nil, "node+", nil},
|
||||
} {
|
||||
if got, _ := completeToolNames(nil, tc.args, tc.in); !slices.Equal(got, tc.want) {
|
||||
|
||||
@@ -182,7 +182,7 @@ func TestPartFlags(t *testing.T) {
|
||||
{"tools", "none", ""},
|
||||
{"tools", "claude", "part_other_flag flag=--tools given=claude other=--agents"},
|
||||
{"tools", "node,mine", "part_other_flag flag=--tools given=mine other=--layers"},
|
||||
{"tools", "java", "unknown_part flag=--tools given=java names=node python rust go"},
|
||||
{"tools", "java", "unknown_part flag=--tools given=java names=node python rust go dotnet"},
|
||||
{"tools", "pyhton", "unknown_part_like flag=--tools given=pyhton like=python"},
|
||||
{"tools", "node,none", "part_none_alone flag=--tools"},
|
||||
{"tools", ",", "part_none_alone flag=--tools"},
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/devvmhq/devvm/internal/image"
|
||||
)
|
||||
|
||||
// listedToolchains are the files that may list every toolchain: the
|
||||
// toolchains page, which owns the list, and the two home pages, where it
|
||||
// helps a visitor decide. A list about something else, such as what an
|
||||
// e2e image holds, gets its file here with why.
|
||||
func listedToolchains() []string {
|
||||
return []string{
|
||||
"docs/content/docs/using/toolchains.md",
|
||||
"docs/content/_index.md",
|
||||
"README.md",
|
||||
// the e2e images' contents and the e2e sections' tools, not the
|
||||
// toolchains' list
|
||||
"docs/content/docs/using/from.md",
|
||||
"docs/content/docs/contributing/_index.md",
|
||||
// design notes on the shared tools' mechanisms
|
||||
"docs/content/docs/internals/design.md",
|
||||
}
|
||||
}
|
||||
|
||||
// sentencesOf is text's sentences: each line's, split at sentenceEnd.
|
||||
func sentencesOf(text string) []string {
|
||||
var out []string
|
||||
for line := range strings.SplitSeq(text, "\n") {
|
||||
out = append(out, sentenceEnd.Split(line, -1)...)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// The toolchains are listed once, on the toolchains page (and the home
|
||||
// pages): a sentence elsewhere in the docs, the in-VM guide, the messages
|
||||
// or the issue forms that names three or more of image.Toolchains links to
|
||||
// that page instead, so a new toolchain changes one list.
|
||||
func TestToolchainsListedOnce(t *testing.T) {
|
||||
var files []string
|
||||
for _, dir := range []string{"docs/content", "assets/guest", ".github/ISSUE_TEMPLATE"} {
|
||||
err := filepath.WalkDir(filepath.Join(repoRoot, dir), func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() && d.Name() == "cli" {
|
||||
return filepath.SkipDir // generated from the help
|
||||
}
|
||||
if !d.IsDir() && (strings.HasSuffix(path, ".md") || strings.HasSuffix(path, ".yml")) {
|
||||
files = append(files, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
files = append(files, filepath.Join(repoRoot, "locales", "en.toml"))
|
||||
names := make([]*regexp.Regexp, len(image.Toolchains))
|
||||
for i, n := range image.Toolchains {
|
||||
// the name as a word, not part of a file's name such as
|
||||
// .node-version, go.mod or rust-toolchain.toml
|
||||
names[i] = regexp.MustCompile(`(?:^|[^\w./-])` + regexp.QuoteMeta(n) + `(?:$|[^\w./-]|\.\s|\.$)`)
|
||||
}
|
||||
for _, path := range files {
|
||||
rel, _ := filepath.Rel(repoRoot, path)
|
||||
if slices.Contains(listedToolchains(), filepath.ToSlash(rel)) {
|
||||
continue
|
||||
}
|
||||
data, err := os.ReadFile(path) //nolint:gosec // G304 the repo's own files
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, s := range sentencesOf(string(data)) {
|
||||
n := 0
|
||||
for _, re := range names {
|
||||
if re.MatchString(s) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n >= 3 {
|
||||
t.Errorf("%s lists the toolchains (%q): link the toolchains page instead, or give one example", rel, strings.TrimSpace(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func newToolsAddCmd(a *app) *cobra.Command {
|
||||
Use: "add TOOL...",
|
||||
Short: "Add shared tools to this folder's VM, then open a shell in it",
|
||||
Long: "Add shared tools to this folder's VM, then open a shell in it. " +
|
||||
"TOOL is node, python, rust, go, claude, codex or opencode, each a separate word. " +
|
||||
"TOOL is a toolchain, such as node, or a coding agent, such as claude, each a separate word. " +
|
||||
"devvm builds any of them that aren't built, and for a new agent in a running VM it asks before restarting the VM.",
|
||||
Example: examples(
|
||||
"devvm tools add claude", "add Claude Code to the VM",
|
||||
|
||||
+16
-3
@@ -42,6 +42,11 @@ const (
|
||||
// Rustup installs it: rustup, pinned in build.sh, checks the toolchain
|
||||
// against its own signed manifest, so the lock has no download for it.
|
||||
Rustup
|
||||
// DotnetSDK installs it: build.sh unpacks Microsoft's SDK archive, the
|
||||
// lock's download, checked against the SHA-512 that devvm adds to the
|
||||
// lock from Microsoft's release metadata. mise's own installer for it
|
||||
// runs Microsoft's install script, which nothing pins or checks.
|
||||
DotnetSDK
|
||||
)
|
||||
|
||||
// ToolDef is a shared tool as devvm offers it: what a VM is given by its
|
||||
@@ -55,7 +60,9 @@ type ToolDef struct {
|
||||
// that its name stands for, itself first: node is node, pnpm and bun.
|
||||
Members []string
|
||||
// Detect are the files in a project folder's top level that call for
|
||||
// it, in the order they're looked for: the first found is named.
|
||||
// it, in the order they're looked for: the first found is named. A
|
||||
// name with a * is a pattern (path.Match's), which names the first
|
||||
// file it matches, in the folder's name order.
|
||||
Detect []string
|
||||
// Installer is what installs it.
|
||||
Installer Installer
|
||||
@@ -70,6 +77,7 @@ var SharedTools = []ToolDef{
|
||||
{Name: "python", Kind: Toolchain, Members: []string{"python", "uv"}, Detect: []string{"pyproject.toml", "requirements.txt", "uv.lock", "setup.py", "Pipfile"}},
|
||||
{Name: "rust", Kind: Toolchain, Members: []string{"rust"}, Detect: []string{"Cargo.toml"}, Installer: Rustup},
|
||||
{Name: "go", Kind: Toolchain, Members: []string{"go"}, Detect: []string{"go.mod"}},
|
||||
{Name: "dotnet", Kind: Toolchain, Members: []string{"dotnet"}, Detect: []string{"*.sln", "*.slnx", "*.csproj", "*.fsproj", "global.json"}, Installer: DotnetSDK},
|
||||
{Name: "claude", Kind: Agent, Members: []string{"claude"}},
|
||||
{Name: "codex", Kind: Agent, Members: []string{"codex"}},
|
||||
{Name: "opencode", Kind: Agent, Members: []string{"opencode"}},
|
||||
@@ -152,7 +160,12 @@ func GroupTools(name string) []string {
|
||||
|
||||
// NoDownload reports whether a tool in the lock needs no download there,
|
||||
// as its shared tool's installer fetches it: rust, which rustup installs.
|
||||
func NoDownload(tool string) bool { return installerOf(tool) != Mise }
|
||||
func NoDownload(tool string) bool { return installerOf(tool) == Rustup }
|
||||
|
||||
// OwnDownload reports whether shared-tools/build.sh fetches a tool's
|
||||
// download from the lock itself, rather than mise or rustup: dotnet,
|
||||
// whose download and checksum devvm adds to the lock.
|
||||
func OwnDownload(tool string) bool { return installerOf(tool) == DotnetSDK }
|
||||
|
||||
// installerOf is what installs a tool in the lock: its shared tool's
|
||||
// Installer, mise for a tool no shared tool has.
|
||||
@@ -226,7 +239,7 @@ func ToolVersion(s string) bool { return toolVersion.MatchString(s) }
|
||||
// shared-tools/build.sh (in assets, devvm's own files) as its build runs
|
||||
// it, after the prelude (OwnScript), the [settings] of
|
||||
// devvm's shared-tools/mise.toml, which change what mise installs, the
|
||||
// version of mise that installs it (MiseVersion; not for a tool rustup
|
||||
// version of mise that installs it (MiseVersion; only for a tool mise
|
||||
// installs), the libc, the base it builds in (devvm's own for gnu, for
|
||||
// musl its digest) and, unless it's build.sh's own, the format.
|
||||
func ToolFile(assets fs.FS, t Tool) (string, error) {
|
||||
|
||||
+21
-12
@@ -134,17 +134,21 @@ func TestToolFile(t *testing.T) {
|
||||
if got := toolFile(t, withBase(root, baseScript+"# edit\nnode_version=1\n"), node()); got != f {
|
||||
t.Errorf("the rest of base.sh: %q, want %q", got, f)
|
||||
}
|
||||
// rustup installs rust: mise's version doesn't count, and base.sh's
|
||||
// pin isn't read.
|
||||
rust := Tool{Name: "rust", Version: "1.99.1", LockEntry: []byte("[[tools.rust]]\n"), Libc: "gnu"}
|
||||
r := toolFile(t, root, rust)
|
||||
if got := toolFile(t, withBase(root, "mise_version=2026.2.0\n"), rust); got != r {
|
||||
t.Errorf("rust with another mise: %q, want %q", got, r)
|
||||
}
|
||||
// rustup installs rust, and build.sh dotnet: mise's version doesn't
|
||||
// count, and base.sh's pin isn't read.
|
||||
noBase := maps.Clone(root)
|
||||
delete(noBase, "layers/base.sh")
|
||||
if got := toolFile(t, noBase, rust); got != r {
|
||||
t.Errorf("rust without base.sh: %q, want %q", got, r)
|
||||
for _, tool := range []Tool{
|
||||
{Name: "rust", Version: "1.99.1", LockEntry: []byte("[[tools.rust]]\n"), Libc: "gnu"},
|
||||
{Name: "dotnet", Version: "10.0.403", LockEntry: []byte("[[tools.dotnet]]\n"), Libc: "gnu"},
|
||||
} {
|
||||
r := toolFile(t, root, tool)
|
||||
if got := toolFile(t, withBase(root, "mise_version=2026.2.0\n"), tool); got != r {
|
||||
t.Errorf("%s with another mise: %q, want %q", tool.Name, got, r)
|
||||
}
|
||||
if got := toolFile(t, noBase, tool); got != r {
|
||||
t.Errorf("%s without base.sh: %q, want %q", tool.Name, got, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,19 +279,24 @@ func TestSortToolsAndGroups(t *testing.T) {
|
||||
}
|
||||
|
||||
// The table's views: the toolchains, then the agents; rust alone needs
|
||||
// no download in the lock.
|
||||
// no download in the lock, and dotnet alone has build.sh fetch its own.
|
||||
func TestSharedTools(t *testing.T) {
|
||||
if want := []string{"node", "python", "rust", "go"}; !slices.Equal(Toolchains, want) {
|
||||
if want := []string{"node", "python", "rust", "go", "dotnet"}; !slices.Equal(Toolchains, want) {
|
||||
t.Errorf("Toolchains = %q, want %q", Toolchains, want)
|
||||
}
|
||||
if want := []string{"claude", "codex", "opencode"}; !slices.Equal(Agents, want) {
|
||||
t.Errorf("Agents = %q, want %q", Agents, want)
|
||||
}
|
||||
for tool, want := range map[string]bool{"rust": true, "node": false, "pnpm": false, "claude": false, "nix": false} {
|
||||
for tool, want := range map[string]bool{"rust": true, "dotnet": false, "node": false, "pnpm": false, "claude": false, "nix": false} {
|
||||
if got := NoDownload(tool); got != want {
|
||||
t.Errorf("NoDownload(%s) = %v, want %v", tool, got, want)
|
||||
}
|
||||
}
|
||||
for tool, want := range map[string]bool{"dotnet": true, "rust": false, "node": false, "claude": false, "nix": false} {
|
||||
if got := OwnDownload(tool); got != want {
|
||||
t.Errorf("OwnDownload(%s) = %v, want %v", tool, got, want)
|
||||
}
|
||||
}
|
||||
if _, ok := Def("pnpm"); ok {
|
||||
t.Error("Def(pnpm): a member isn't a shared tool")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"maps"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/devvmhq/devvm/internal/fetch"
|
||||
"github.com/devvmhq/devvm/internal/image"
|
||||
)
|
||||
|
||||
// The .NET SDK's downloads. mise locks dotnet's version alone, without a
|
||||
// download, as its installer runs Microsoft's install script, which
|
||||
// nothing pins and which checks nothing. So devvm adds each platform's SDK
|
||||
// archive and its SHA-512 to the lock's dotnet entries from Microsoft's
|
||||
// release metadata, as mise does for the other tools from their releases'
|
||||
// checksums, and shared-tools/build.sh checks the archive against the lock.
|
||||
|
||||
// dotnetReleases is where Microsoft lists a .NET channel's releases, each
|
||||
// SDK with its files and their SHA-512: a format taking the channel, such
|
||||
// as 10.0.
|
||||
const dotnetReleases = "https://builds.dotnet.microsoft.com/dotnet/release-metadata/%s/releases.json"
|
||||
|
||||
// dotnetFiles is where every SDK archive the lock records comes from.
|
||||
const dotnetFiles = "https://builds.dotnet.microsoft.com/dotnet/"
|
||||
|
||||
// releasesCap caps a channel's release list, which is a few MB.
|
||||
const releasesCap = 32 << 20
|
||||
|
||||
var (
|
||||
dotnetVersion = regexp.MustCompile(`^([0-9]+\.[0-9]+)\.[0-9]+$`)
|
||||
sha512Hex = regexp.MustCompile(`^[0-9a-f]{128}$`)
|
||||
)
|
||||
|
||||
// dotnetRID is Microsoft's name for a lock's platform: linux-x64-musl is
|
||||
// linux-musl-x64.
|
||||
func dotnetRID(platform string) string {
|
||||
arch, musl := strings.CutSuffix(strings.TrimPrefix(platform, "linux-"), "-musl")
|
||||
if musl {
|
||||
return "linux-musl-" + arch
|
||||
}
|
||||
return "linux-" + arch
|
||||
}
|
||||
|
||||
// dotnetSDK is an SDK release as a channel's releases.json has it.
|
||||
type dotnetSDK struct {
|
||||
Version string `json:"version"`
|
||||
Files []struct {
|
||||
Name string `json:"name"`
|
||||
RID string `json:"rid"`
|
||||
URL string `json:"url"`
|
||||
Hash string `json:"hash"`
|
||||
} `json:"files"`
|
||||
}
|
||||
|
||||
// download is the SDK's archive for a lock's platform and its SHA-512, in
|
||||
// hex: false when Microsoft lists none, or one that isn't an https URL of
|
||||
// its own downloads with a SHA-512.
|
||||
func (s dotnetSDK) download(platform string) (url, sha512 string, ok bool) {
|
||||
rid := dotnetRID(platform)
|
||||
for _, f := range s.Files {
|
||||
h := strings.ToLower(f.Hash)
|
||||
if f.RID == rid && f.Name == "dotnet-sdk-"+rid+".tar.gz" && strings.HasPrefix(f.URL, dotnetFiles) &&
|
||||
strings.HasSuffix(f.URL, ".tar.gz") && sha512Hex.MatchString(h) {
|
||||
return f.URL, h, true
|
||||
}
|
||||
}
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
// dotnetSDKs reads a channel's releases.json: its SDKs, each release's
|
||||
// own and the others it lists.
|
||||
func dotnetSDKs(data []byte) ([]dotnetSDK, error) {
|
||||
var doc struct {
|
||||
Releases []struct {
|
||||
SDK *dotnetSDK `json:"sdk"`
|
||||
SDKs []dotnetSDK `json:"sdks"`
|
||||
} `json:"releases"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &doc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []dotnetSDK
|
||||
for _, r := range doc.Releases {
|
||||
if r.SDK != nil {
|
||||
out = append(out, *r.SDK)
|
||||
}
|
||||
out = append(out, r.SDKs...)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// withSDKDownloads returns the lock with Microsoft's downloads added to
|
||||
// each entry of a tool build.sh fetches itself (image.OwnDownload) that
|
||||
// lacks one for some platform: the SDK's archive, for each platform
|
||||
// Microsoft has one for, and its SHA-512. Entries with all of them stay as
|
||||
// they are, and so does a lock where all have them. A version Microsoft
|
||||
// doesn't list keeps none, which the step back sees; a channel's list it
|
||||
// can't get fails.
|
||||
func (t Versions) withSDKDownloads(ctx context.Context, lock Lock) (Lock, error) {
|
||||
channels := map[string][]dotnetSDK{}
|
||||
for _, d := range image.SharedTools {
|
||||
for _, tool := range d.Members {
|
||||
if !image.OwnDownload(tool) {
|
||||
continue
|
||||
}
|
||||
es := slices.Clone(lock.entries(tool))
|
||||
changed := false
|
||||
for i, e := range es {
|
||||
if hasDownload(e, t.platforms()) {
|
||||
continue
|
||||
}
|
||||
sdk, err := t.dotnetSDK(ctx, channels, str(e, "version"))
|
||||
if err != nil {
|
||||
return Lock{}, err
|
||||
}
|
||||
e = maps.Clone(e)
|
||||
for _, p := range t.platforms() {
|
||||
if url, sum, ok := sdk.download(p); ok {
|
||||
e["platforms."+p] = map[string]any{"checksum": "sha512:" + sum, "url": url}
|
||||
es[i], changed = e, true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
continue
|
||||
}
|
||||
var err error
|
||||
if lock, err = lock.withEntries(tool, es); err != nil {
|
||||
return Lock{}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return lock, nil
|
||||
}
|
||||
|
||||
// dotnetSDK returns the SDK of a version from its channel's releases.json,
|
||||
// which it gets once per channel (channels): an empty one when the
|
||||
// version isn't shaped like an SDK's or the channel doesn't list it.
|
||||
func (t Versions) dotnetSDK(ctx context.Context, channels map[string][]dotnetSDK, version string) (dotnetSDK, error) {
|
||||
m := dotnetVersion.FindStringSubmatch(version)
|
||||
if m == nil {
|
||||
return dotnetSDK{}, nil
|
||||
}
|
||||
sdks, ok := channels[m[1]]
|
||||
if !ok {
|
||||
url := fmt.Sprintf(t.dotnetURL, m[1])
|
||||
var data []byte
|
||||
err := fetch.Retry(ctx, downloadRetries, t.RetryDelay, func() (bool, error) {
|
||||
var err error
|
||||
data, err = fetch.Get(ctx, t.Client, url, releasesCap)
|
||||
return fetch.Transient(err), err
|
||||
})
|
||||
if err == nil {
|
||||
sdks, err = dotnetSDKs(data)
|
||||
}
|
||||
if err != nil {
|
||||
return dotnetSDK{}, fmt.Errorf("dotnet's releases: %w", err)
|
||||
}
|
||||
channels[m[1]] = sdks
|
||||
}
|
||||
for _, s := range sdks {
|
||||
if s.Version == version {
|
||||
return s, nil
|
||||
}
|
||||
}
|
||||
return dotnetSDK{}, nil
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/devvmhq/devvm/internal/backend"
|
||||
"github.com/devvmhq/devvm/internal/msg"
|
||||
)
|
||||
|
||||
func TestDotnetRID(t *testing.T) {
|
||||
for platform, want := range map[string]string{
|
||||
"linux-arm64": "linux-arm64", "linux-x64": "linux-x64",
|
||||
"linux-arm64-musl": "linux-musl-arm64", "linux-x64-musl": "linux-musl-x64",
|
||||
} {
|
||||
if got := dotnetRID(platform); got != want {
|
||||
t.Errorf("dotnetRID(%s) = %s, want %s", platform, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sha512Of is a made-up SHA-512 in hex, one per letter.
|
||||
func sha512Of(c string) string { return strings.Repeat(c, 128) }
|
||||
|
||||
// dotnetChannel is a channel's releases.json as Microsoft writes it, with
|
||||
// 10.0.402 as a release's SDK and 10.0.110 among its others; 10.0.402's
|
||||
// files: good ones for arm64 and musl arm64 (an uppercase hash), and for
|
||||
// x64 one off Microsoft's downloads and one without a SHA-512.
|
||||
const dotnetChannel = `{"channel-version": "10.0", "releases": [
|
||||
{"release-version": "10.0.4", "sdk": {"version": "10.0.402", "files": [
|
||||
{"name": "dotnet-sdk-linux-arm64.tar.gz", "rid": "linux-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-arm64.tar.gz", "hash": "` + "aaaa" + `"},
|
||||
{"name": "dotnet-sdk-linux-arm64.zip", "rid": "linux-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-arm64.zip", "hash": "HASH_B"},
|
||||
{"name": "dotnet-sdk-linux-arm64.tar.gz", "rid": "linux-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-arm64.tar.gz", "hash": "HASH_A"},
|
||||
{"name": "dotnet-sdk-linux-musl-arm64.tar.gz", "rid": "linux-musl-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-musl-arm64.tar.gz", "hash": "HASH_C_UPPER"},
|
||||
{"name": "dotnet-sdk-linux-x64.tar.gz", "rid": "linux-x64", "url": "https://example.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-x64.tar.gz", "hash": "HASH_D"},
|
||||
{"name": "dotnet-sdk-linux-musl-x64.tar.gz", "rid": "linux-musl-x64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-musl-x64.tar.gz", "hash": "abc"}
|
||||
]}, "sdks": [{"version": "10.0.402", "files": []}, {"version": "10.0.110", "files": [
|
||||
{"name": "dotnet-sdk-linux-arm64.tar.gz", "rid": "linux-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.110/dotnet-sdk-10.0.110-linux-arm64.tar.gz", "hash": "HASH_E"}
|
||||
]}]},
|
||||
{"release-version": "10.0.0-rc.1", "sdk": null}
|
||||
]}`
|
||||
|
||||
// channelJSON is dotnetChannel with its made-up hashes.
|
||||
func channelJSON() string {
|
||||
return strings.NewReplacer("HASH_A", sha512Of("a"), "HASH_B", sha512Of("b"), "HASH_C_UPPER", strings.ToUpper(sha512Of("c")),
|
||||
"HASH_D", sha512Of("d"), "HASH_E", sha512Of("e")).Replace(dotnetChannel)
|
||||
}
|
||||
|
||||
// dotnetServer serves channel 10.0's releases.json, counting its requests;
|
||||
// any other channel is missing.
|
||||
func dotnetServer(t *testing.T, e env) *atomic.Int32 {
|
||||
t.Helper()
|
||||
var n atomic.Int32
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
n.Add(1)
|
||||
if r.URL.Path != "/10.0/releases.json" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(channelJSON()))
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
e.dotnetURL = srv.URL + "/%s/releases.json"
|
||||
return &n
|
||||
}
|
||||
|
||||
// dotnetLock is the fixture with dotnet's entries as mise locks them,
|
||||
// versions without downloads.
|
||||
func dotnetLock(t *testing.T, versions ...string) []byte {
|
||||
t.Helper()
|
||||
var b bytes.Buffer
|
||||
in := false
|
||||
for _, line := range lines(fixture(t)) {
|
||||
if strings.HasPrefix(line, "[") {
|
||||
in = strings.HasPrefix(line, "[[tools.dotnet]]") || strings.HasPrefix(line, "[tools.dotnet.")
|
||||
}
|
||||
if !in {
|
||||
b.WriteString(line + "\n")
|
||||
}
|
||||
}
|
||||
for _, v := range versions {
|
||||
b.WriteString("\n[[tools.dotnet]]\nversion = \"" + v + "\"\nbackend = \"core:dotnet\"\nspecifiers = [\"latest\"]\n")
|
||||
}
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
// Microsoft's archive and its SHA-512 for each of the VMs' platforms join
|
||||
// each dotnet entry that has none: from its channel's releases.json, read
|
||||
// once for all of them, a release's SDK or one of its others; a file off
|
||||
// Microsoft's downloads, without a SHA-512 or not a tar.gz isn't taken. A
|
||||
// lock that has them all stays as it is, and so does a version Microsoft
|
||||
// doesn't list.
|
||||
func TestWithSDKDownloads(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
n := dotnetServer(t, e)
|
||||
lock, err := e.withSDKDownloads(t.Context(), parsed(t, dotnetLock(t, "10.0.402", "10.0.110", "10.0.499", "10.x")))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := n.Load(); got != 1 {
|
||||
t.Errorf("%d requests, want 1", got)
|
||||
}
|
||||
want := map[string][2]string{
|
||||
"10.0.402 linux-arm64": {"https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-arm64.tar.gz", "sha512:" + sha512Of("a")},
|
||||
"10.0.402 linux-arm64-musl": {"https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-musl-arm64.tar.gz", "sha512:" + sha512Of("c")},
|
||||
"10.0.110 linux-arm64": {"https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.110/dotnet-sdk-10.0.110-linux-arm64.tar.gz", "sha512:" + sha512Of("e")},
|
||||
}
|
||||
for _, v := range []string{"10.0.402", "10.0.110", "10.0.499", "10.x"} {
|
||||
for _, p := range []string{"linux-arm64", "linux-arm64-musl", "linux-x64", "linux-x64-musl"} {
|
||||
table, _ := lock.versionEntry("dotnet", v)["platforms."+p].(map[string]any)
|
||||
got := [2]string{str(table, "url"), str(table, "checksum")}
|
||||
if got != want[v+" "+p] {
|
||||
t.Errorf("%s on %s: %q, want %q", v, p, got, want[v+" "+p])
|
||||
}
|
||||
}
|
||||
}
|
||||
if url, sum := lock.Download("dotnet", "linux-arm64"); url != want["10.0.402 linux-arm64"][0] || sum != want["10.0.402 linux-arm64"][1] {
|
||||
t.Errorf("Download = %s %s", url, sum)
|
||||
}
|
||||
if !slices.Equal(lockTools(t, lock.Bytes()), lockTools(t, fixture(t))) || !bytes.Equal(entryOf(t, lock.Bytes(), "node"), entryOf(t, fixture(t), "node")) {
|
||||
t.Error("the other tools changed")
|
||||
}
|
||||
for _, have := range [][]byte{fixture(t), dotnetLock(t)} {
|
||||
again, err := e.withSDKDownloads(t.Context(), parsed(t, have))
|
||||
if err != nil || !bytes.Equal(again.Bytes(), have) {
|
||||
t.Errorf("a lock with every download changed: %v", err)
|
||||
}
|
||||
}
|
||||
if got := n.Load(); got != 1 {
|
||||
t.Errorf("%d requests for locks with every download", got)
|
||||
}
|
||||
// x64's: one off Microsoft's downloads, and one without a SHA-512.
|
||||
sdks, err := dotnetSDKs([]byte(channelJSON()))
|
||||
if err != nil || len(sdks) != 3 {
|
||||
t.Fatalf("dotnetSDKs = %d, %v", len(sdks), err)
|
||||
}
|
||||
for _, p := range []string{"linux-x64", "linux-x64-musl"} {
|
||||
if url, _, ok := sdks[0].download(p); ok {
|
||||
t.Errorf("%s: %s", p, url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A channel Microsoft doesn't answer for fails, and so does Resolve, with
|
||||
// nothing written; with its downloads, Resolve writes them.
|
||||
func TestResolveSDKDownloads(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
e.locked(t, fixture(t))
|
||||
n := dotnetServer(t, e)
|
||||
e.stubLocks(t, dotnetLock(t, "9.0.300"), nil, "")
|
||||
if err := e.Refresh(t.Context()); msg.NamesOf(err) != "tools_resolve_failed" {
|
||||
t.Errorf("Refresh with a channel that isn't there = %v", msg.NamesOf(err))
|
||||
}
|
||||
if !bytes.Equal(read(t, e.Dirs.ToolLock()), fixture(t)) {
|
||||
t.Error("the lock changed")
|
||||
}
|
||||
if got := n.Load(); got != 1 {
|
||||
t.Errorf("%d requests for a 404, want 1", got)
|
||||
}
|
||||
e.stubLocks(t, dotnetLock(t, "10.0.402"), nil, "")
|
||||
if err := e.Refresh(t.Context()); err != nil {
|
||||
t.Fatal(msg.NamesOf(err))
|
||||
}
|
||||
lock := parsed(t, read(t, e.Dirs.ToolLock()))
|
||||
if lock.Version("dotnet") != "10.0.402" || !lock.HasDownload("dotnet", e.platforms()) {
|
||||
t.Errorf("dotnet = %s, with downloads %v", lock.Version("dotnet"), lock.HasDownload("dotnet", e.platforms()))
|
||||
}
|
||||
if url, _ := lock.Download("dotnet", "linux-arm64-musl"); !strings.HasSuffix(url, "-linux-musl-arm64.tar.gz") {
|
||||
t.Errorf("musl's download = %s", url)
|
||||
}
|
||||
}
|
||||
|
||||
// The newest SDK without a download for a platform steps back, to an
|
||||
// older one whose downloads devvm added too.
|
||||
func TestSDKStepsBack(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
e.locked(t, fixture(t))
|
||||
dotnetServer(t, e)
|
||||
e.stubLocks(t, dotnetLock(t, "10.0.499"), dotnetLock(t, "10.0.402"), "10.0.300 10.0.402 10.0.499")
|
||||
if err := e.Refresh(t.Context()); err != nil {
|
||||
t.Fatal(msg.NamesOf(err))
|
||||
}
|
||||
if !slices.Contains(*e.said, "devvm: tool_stepped_back older=10.0.402 tool=dotnet version=10.0.499") {
|
||||
t.Errorf("said %q", *e.said)
|
||||
}
|
||||
if lock := parsed(t, read(t, e.Dirs.ToolLock())); lock.Version("dotnet") != "10.0.402" || !lock.HasDownload("dotnet", e.platforms()) {
|
||||
t.Errorf("dotnet = %s", lock.Version("dotnet"))
|
||||
}
|
||||
}
|
||||
|
||||
// build.sh gets dotnet's download for the VM's platform and its SHA-512,
|
||||
// in hex, after its tool, version and file; a download without a SHA-512
|
||||
// isn't built.
|
||||
func TestBuildDotnet(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
e.locked(t, fixture(t))
|
||||
lock := parsed(t, fixture(t))
|
||||
for _, tg := range []struct {
|
||||
target Target
|
||||
base string
|
||||
platform string
|
||||
}{{gnuT, baseKey, "linux-arm64"}, {muslT, muslKey, "linux-arm64-musl"}} {
|
||||
f := fake()
|
||||
file, err := e.File(lock, "dotnet", tg.target)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := e.Build(t.Context(), backend.Review{}, f, tg.base, tg.target, []string{file}); err != nil {
|
||||
t.Fatal(msg.NamesOf(err))
|
||||
}
|
||||
url, sum := lock.Download("dotnet", tg.platform)
|
||||
spec, _ := f.Calls()[0].Args[0].(backend.ToolsSpec)
|
||||
if want := []string{"dotnet", "10.0.401", file, url, strings.TrimPrefix(sum, "sha512:")}; !slices.Equal(spec.Args, want) {
|
||||
t.Errorf("%s: build.sh's arguments %q, want %q", tg.platform, spec.Args, want)
|
||||
}
|
||||
}
|
||||
e = newEnv(t)
|
||||
sha256 := bytes.ReplaceAll(fixture(t), []byte(`checksum = "sha512:`), []byte(`checksum = "sha256:`))
|
||||
e.locked(t, sha256)
|
||||
file, err := e.File(parsed(t, sha256), "dotnet", gnuT)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f := fake()
|
||||
if err := e.Build(t.Context(), backend.Review{}, f, baseKey, gnuT, []string{file}); msg.NamesOf(err) != "tool_unbuilt tool=dotnet version=10.0.401" {
|
||||
t.Errorf("a download without a SHA-512 = %v", msg.NamesOf(err))
|
||||
}
|
||||
if len(f.Calls()) != 0 {
|
||||
t.Errorf("built: %q", f.Methods())
|
||||
}
|
||||
e.noLeftovers(t)
|
||||
}
|
||||
+17
-4
@@ -112,9 +112,9 @@ func (l Lock) Entry(tool string) ([]byte, error) {
|
||||
}
|
||||
|
||||
// HasDownload reports whether a tool's first entry has a download (a URL
|
||||
// and its checksum, which mise checks it against, not a build from
|
||||
// source) for every one of the platforms. A tool whose
|
||||
// installer isn't mise needs none (image.NoDownload): rustup installs rust.
|
||||
// and its checksum, which mise or build.sh checks it against, not a build
|
||||
// from source) for every one of the platforms. A tool whose installer
|
||||
// fetches it needs none (image.NoDownload): rustup installs rust.
|
||||
func (l Lock) HasDownload(tool string, platforms []string) bool {
|
||||
if image.NoDownload(tool) {
|
||||
return true
|
||||
@@ -146,15 +146,28 @@ func (l Lock) versionEntry(tool, version string) lockEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Download returns the URL and checksum of a tool's first entry's
|
||||
// download for a platform: "" for none.
|
||||
func (l Lock) Download(tool, platform string) (url, checksum string) {
|
||||
table, _ := l.first(tool)["platforms."+platform].(map[string]any)
|
||||
return str(table, "url"), str(table, "checksum")
|
||||
}
|
||||
|
||||
// withEntry returns the lock with a tool's entries replaced by e alone,
|
||||
// written again as TOML.
|
||||
func (l Lock) withEntry(tool string, e lockEntry) (Lock, error) {
|
||||
return l.withEntries(tool, []lockEntry{e})
|
||||
}
|
||||
|
||||
// withEntries returns the lock with a tool's entries replaced by es,
|
||||
// written again as TOML.
|
||||
func (l Lock) withEntries(tool string, es []lockEntry) (Lock, error) {
|
||||
doc, ts := map[string]any{}, map[string]any{}
|
||||
maps.Copy(doc, l.doc)
|
||||
if old, ok := l.doc["tools"].(map[string]any); ok {
|
||||
maps.Copy(ts, old)
|
||||
}
|
||||
ts[tool] = []map[string]any{e}
|
||||
ts[tool] = es
|
||||
doc["tools"] = ts
|
||||
var b bytes.Buffer
|
||||
if err := toml.NewEncoder(&b).Encode(doc); err != nil {
|
||||
|
||||
@@ -241,6 +241,10 @@ func (t Versions) Resolve(ctx context.Context, out string) (Lock, error) {
|
||||
if err != nil {
|
||||
return Lock{}, t.resolveFailed(ctx, tmp)
|
||||
}
|
||||
if lock, err = t.withSDKDownloads(ctx, lock); err != nil {
|
||||
_, _ = fmt.Fprintln(t.LogWriter(), err)
|
||||
return Lock{}, t.resolveFailed(ctx, tmp)
|
||||
}
|
||||
names, specs := configTools(config)
|
||||
for _, n := range names {
|
||||
if !lock.Has(n) {
|
||||
@@ -385,5 +389,8 @@ func (t Versions) lockVersions(ctx context.Context, mise, tool, backendName stri
|
||||
}
|
||||
_ = t.LoggedCmd(ctx, msg.ResolvingTools(), cmd) // what it locked is checked below
|
||||
l, err := parseLockFile(filepath.Join(dir, "mise.lock"))
|
||||
if err == nil {
|
||||
l, err = t.withSDKDownloads(ctx, l)
|
||||
}
|
||||
return l, err == nil
|
||||
}
|
||||
+11
-1
@@ -207,8 +207,18 @@ func (t Share) buildOne(ctx context.Context, b backend.Backend, base string, tg
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args := []string{tool, version, file}
|
||||
if image.OwnDownload(tool) {
|
||||
// build.sh fetches it itself, from the lock's download for this
|
||||
// VM's platform, checked against the lock's checksum.
|
||||
url, sum := lock.Download(tool, t.platform(tg.Libc))
|
||||
if !strings.HasPrefix(url, "https://") || !strings.HasPrefix(sum, "sha512:") {
|
||||
return msg.ToolUnbuilt(tool, version)
|
||||
}
|
||||
args = append(args, url, strings.TrimPrefix(sum, "sha512:"))
|
||||
}
|
||||
spec := backend.ToolsSpec{
|
||||
Name: Label([]string{file}), Base: base, Out: out, OutAt: ShareAt, Args: []string{tool, version, file}, Format: tg.Format,
|
||||
Name: Label([]string{file}), Base: base, Out: out, OutAt: ShareAt, Args: args, Format: tg.Format,
|
||||
Net: backend.NetInternet, Script: backend.Script{Name: "build.sh", Data: script}, Trust: ca,
|
||||
}
|
||||
if err := b.BuildTools(ctx, spec); err != nil {
|
||||
|
||||
@@ -96,6 +96,9 @@ type Env struct {
|
||||
// and platform) and checksums, by platform.
|
||||
miseURL string
|
||||
miseSums map[string]string
|
||||
// dotnetURL is a .NET channel's releases.json (a format taking the
|
||||
// channel), which the lock's dotnet downloads come from.
|
||||
dotnetURL string
|
||||
}
|
||||
|
||||
// Versions is the tools lock: resolving it with the host's mise, the daily
|
||||
@@ -129,7 +132,7 @@ func New(d paths.Dirs, assets fs.FS, version string, r msg.Reporter, host platfo
|
||||
t := &Env{
|
||||
Dirs: d, Assets: assets, Self: self, Version: version, OS: runtime.GOOS, Arch: runtime.GOARCH,
|
||||
Getenv: os.Getenv, Client: newClient(), RetryDelay: time.Second, Now: time.Now, Detach: daemon.Detach,
|
||||
ShareNote: 3 * time.Second, miseURL: miseURL, miseSums: miseSHA256,
|
||||
ShareNote: 3 * time.Second, miseURL: miseURL, miseSums: miseSHA256, dotnetURL: dotnetReleases,
|
||||
Reporter: r, FreeSpace: host.FreeSpace,
|
||||
}
|
||||
// The environment it reads is Getenv's, and the Proxy the one at each
|
||||
|
||||
@@ -158,6 +158,8 @@ func newEnv(t *testing.T) env {
|
||||
tl.Arch = "arm64"
|
||||
tl.Getenv = func(string) string { return "" }
|
||||
tl.Mise = stubtest.Command(t, "mise")
|
||||
// Never Microsoft's: a test that needs dotnet's releases serves them.
|
||||
tl.dotnetURL = "http://127.0.0.1:0/%s/releases.json"
|
||||
tl.ShareNote = time.Millisecond
|
||||
tl.RetryDelay = time.Millisecond
|
||||
tl.FreeSpace = func(string) (uint64, error) { return 1 << 40, nil }
|
||||
@@ -1231,6 +1233,7 @@ func TestList(t *testing.T) {
|
||||
"go go 1.27.2 true 0 current",
|
||||
"go go 1.20.0 true 2 in use",
|
||||
"go go 1.9.0 true 0 unused",
|
||||
"dotnet false 0 not installed",
|
||||
"claude claude 2.1.295 true 1 current",
|
||||
"codex false 0 not installed",
|
||||
"opencode false 0 not installed",
|
||||
|
||||
+38
-7
@@ -3,6 +3,7 @@ package vm
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -60,14 +61,9 @@ type detected struct{ Name, File string }
|
||||
// default parts (defaults) start from them.
|
||||
func detectFiles(dir string) []detected {
|
||||
var found []detected
|
||||
f := folder{dir: dir}
|
||||
for _, m := range markers() {
|
||||
file := ""
|
||||
for _, f := range m.files {
|
||||
if _, err := os.Lstat(filepath.Join(dir, f)); err == nil {
|
||||
file = f
|
||||
break
|
||||
}
|
||||
}
|
||||
file := f.first(m.files)
|
||||
if file == "" && m.part == image.NixLayer && nixShell(dir) {
|
||||
file = "default.nix"
|
||||
}
|
||||
@@ -77,3 +73,38 @@ func detectFiles(dir string) []detected {
|
||||
}
|
||||
return found
|
||||
}
|
||||
|
||||
// folder is a project folder's top level, as detectFiles looks in it:
|
||||
// its names are read once, for the first pattern that needs them.
|
||||
type folder struct {
|
||||
dir string
|
||||
names []string
|
||||
read bool
|
||||
}
|
||||
|
||||
// first is the first of a marker's files in the folder: a name that's
|
||||
// there, or the first name a pattern matches (path.Match's), in name
|
||||
// order; "" when none is.
|
||||
func (f *folder) first(files []string) string {
|
||||
for _, file := range files {
|
||||
if !strings.Contains(file, "*") {
|
||||
if _, err := os.Lstat(filepath.Join(f.dir, file)); err == nil {
|
||||
return file
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !f.read {
|
||||
entries, _ := os.ReadDir(f.dir) // sorted by name; none when it can't be read
|
||||
for _, e := range entries {
|
||||
f.names = append(f.names, e.Name())
|
||||
}
|
||||
f.read = true
|
||||
}
|
||||
for _, n := range f.names {
|
||||
if ok, _ := path.Match(file, n); ok {
|
||||
return n
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -39,6 +39,11 @@ func TestDetect(t *testing.T) {
|
||||
{"Pipfile", "python"},
|
||||
{"Cargo.toml", "rust"},
|
||||
{"go.mod", "go"},
|
||||
{"App.sln", "dotnet"},
|
||||
{"App.slnx", "dotnet"},
|
||||
{"App.csproj", "dotnet"},
|
||||
{"Lib.fsproj", "dotnet"},
|
||||
{"global.json", "dotnet"},
|
||||
{"flake.nix", "nix"},
|
||||
{"shell.nix", "nix"},
|
||||
{"devenv.nix", "nix"},
|
||||
@@ -72,6 +77,31 @@ func TestDetect(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A pattern names the file it matched: the first, in name order, of the
|
||||
// first pattern that matches, before the names after it; only the top
|
||||
// level counts, and a name that only looks like it doesn't.
|
||||
func TestDetectPatterns(t *testing.T) {
|
||||
d := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(d, "src"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
touchAll(t, filepath.Join(d, "src", "App.csproj"), filepath.Join(d, "App.csproj.user"), filepath.Join(d, "global.json.bak"))
|
||||
if got := detect(d); got != nil {
|
||||
t.Errorf("detect with src/App.csproj, App.csproj.user and global.json.bak = %v", got)
|
||||
}
|
||||
touchAll(t, filepath.Join(d, "global.json"), filepath.Join(d, "Web.csproj"), filepath.Join(d, "Api.csproj"))
|
||||
if got, want := detectFiles(d), []detected{{"dotnet", "Api.csproj"}}; !slices.Equal(got, want) {
|
||||
t.Errorf("detectFiles = %v, want %v", got, want)
|
||||
}
|
||||
touchAll(t, filepath.Join(d, "Shop.sln"))
|
||||
if got, want := detectFiles(d), []detected{{"dotnet", "Shop.sln"}}; !slices.Equal(got, want) {
|
||||
t.Errorf("detectFiles with Shop.sln = %v, want %v", got, want)
|
||||
}
|
||||
if got := detectFiles(filepath.Join(d, "none")); got != nil {
|
||||
t.Errorf("detectFiles of a missing folder = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A default.nix calls for nix only when it makes a shell, and only as a
|
||||
// regular file.
|
||||
func TestDetectDefaultNix(t *testing.T) {
|
||||
|
||||
+34
-4
@@ -263,18 +263,46 @@ bump_omb() {
|
||||
lock_version() {
|
||||
awk -v t="[[tools.$2]]" '$0 == t { f = 1; next } f && /^version = / { gsub(/"/, "", $3); print $3; exit }' "$1" 2>/dev/null || true
|
||||
}
|
||||
# lock_checksum LOCK TOOL PLATFORM: the tool's download for PLATFORM has a SHA-256 in the lock.
|
||||
# lock_checksum LOCK TOOL PLATFORM: the tool's download for PLATFORM has a SHA-256 in the lock, or
|
||||
# for dotnet the SHA-512 Microsoft publishes.
|
||||
lock_checksum() {
|
||||
awk -v h="[tools.$2.\"platforms.$3\"]" '
|
||||
$0 == h { f = 1; next }
|
||||
f { ok = $0 ~ /^checksum = "sha256:[0-9a-f]+"$/ && length($0) == 84; exit }
|
||||
f { ok = ($0 ~ /^checksum = "sha256:[0-9a-f]+"$/ && length($0) == 84) || ($0 ~ /^checksum = "sha512:[0-9a-f]+"$/ && length($0) == 148); exit }
|
||||
END { exit !ok }' "$1"
|
||||
}
|
||||
# dotnet_downloads LOCK PLATFORM...: the lock's dotnet entry, which mise locks without a download,
|
||||
# gets Microsoft's SDK archive for each platform and its SHA-512, from the channel's releases.json,
|
||||
# as devvm adds them when it resolves the lock (internal/tools/dotnet.go). Exits when Microsoft has
|
||||
# none for a platform yet.
|
||||
dotnet_downloads() {
|
||||
local lock=$1 v ch p rid url hash tables=""
|
||||
shift
|
||||
v=$(lock_version "$lock" dotnet)
|
||||
[[ $v =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { printf 'bump: mise locked dotnet at an unexpected version: %q\n' "$v" >&2; exit 1; }
|
||||
ch=${v%.*}
|
||||
fetch -o "$tmp/dotnet-releases.json" "https://builds.dotnet.microsoft.com/dotnet/release-metadata/$ch/releases.json"
|
||||
for p in "$@"; do
|
||||
case $p in *-musl) rid=${p%-musl}; rid=linux-musl-${rid#linux-} ;; *) rid=$p ;; esac
|
||||
read -r url hash < <(jq -r --arg v "$v" --arg rid "$rid" '[.releases[] | (.sdk // empty), (.sdks // [])[]
|
||||
| select(.version == $v) | .files[] | select(.rid == $rid and .name == "dotnet-sdk-\($rid).tar.gz")][0]
|
||||
| "\(.url) \(.hash)"' "$tmp/dotnet-releases.json")
|
||||
hash=$(tr 'A-F' 'a-f' <<<"$hash")
|
||||
if [[ $url != https://builds.dotnet.microsoft.com/dotnet/*.tar.gz || ! $hash =~ ^[0-9a-f]{128}$ ]]; then
|
||||
echo "bump: dotnet $v has no SDK archive with a SHA-512 for $p yet: try again later" >&2; exit 1
|
||||
fi
|
||||
tables+=$'\n'"[tools.dotnet.\"platforms.$p\"]"$'\n'"checksum = \"sha512:$hash\""$'\n'"url = \"$url\""$'\n'
|
||||
done
|
||||
T=$tables awk '{ print } $0 == "[[tools.dotnet]]" { f = 1 } f && /^specifiers = / { printf "%s", ENVIRON["T"]; f = 0 }' \
|
||||
"$lock" > "$tmp/dotnet.lock"
|
||||
cat "$tmp/dotnet.lock" > "$lock"
|
||||
}
|
||||
|
||||
# The shared tools' versions every e2e section but tools uses (tests/e2e-mise.lock): upstream's newest,
|
||||
# resolved as devvm resolves them (its pinned host mise, mise lock on assets/shared-tools/mise.toml), for
|
||||
# both architectures' glibc and musl VMs. Every tool must be in it, and each one's downloads but rust's
|
||||
# (rustup checks its own) need a SHA-256 on every platform, or this exits: a release without its files
|
||||
# both architectures' glibc and musl VMs, with dotnet's downloads added as devvm adds them. Every tool
|
||||
# must be in it, and each one's downloads but rust's (rustup checks its own) need a SHA-256 (dotnet's a
|
||||
# SHA-512) on every platform, or this exits: a release without its files
|
||||
# yet, to try again later. Its first line is the SHA-256 of the mise.toml it was resolved from, which
|
||||
# e2e checks before it runs.
|
||||
e2e_lock=""
|
||||
@@ -297,6 +325,8 @@ bump_e2e-tools() {
|
||||
"$tmp/mise" lock --platform "$(tr ' ' ',' <<<"$platforms")") >"$tmp/mise-lock.log" 2>&1; then
|
||||
cat "$tmp/mise-lock.log" >&2; echo "bump: mise lock failed" >&2; exit 1
|
||||
fi
|
||||
# shellcheck disable=SC2086 # the platforms, a word each
|
||||
dotnet_downloads "$d/mise.lock" $platforms
|
||||
while read -r tool; do
|
||||
new=$(lock_version "$d/mise.lock" "$tool")
|
||||
valid "${tool}_version" "$new"
|
||||
|
||||
Vendored
+21
@@ -81,6 +81,27 @@ checksum = "sha256:4f573944c1d2059109d75a2f4d0cc9c03697288224a5e407717a9de98fc01
|
||||
url = "https://github.com/openai/codex/releases/download/rust-v0.162.0/codex-package-x86_64-unknown-linux-musl.tar.gz"
|
||||
url_api = "https://api.github.com/repos/openai/codex/releases/assets/622683980"
|
||||
|
||||
[[tools.dotnet]]
|
||||
version = "10.0.401"
|
||||
backend = "core:dotnet"
|
||||
specifiers = ["latest"]
|
||||
|
||||
[tools.dotnet."platforms.linux-arm64"]
|
||||
checksum = "sha512:8d8cd675b78d00ebc51379d4a733a46b88a79b7f816abdfd8d1957b15e9e6a84d6dc6de91e7fc0c18d81071a43aaf2954af7f6fa378e097a1238ec6520c32c9d"
|
||||
url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.401/dotnet-sdk-10.0.401-linux-arm64.tar.gz"
|
||||
|
||||
[tools.dotnet."platforms.linux-arm64-musl"]
|
||||
checksum = "sha512:12d55a49b8a94b9d132ad9e4846516347a9dae1789bc58fda9fa54293edb24d7d49293c5b865551dc8b8e1516832793a7c9988af4e43ae8c9c4f3b7b5a881ae9"
|
||||
url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.401/dotnet-sdk-10.0.401-linux-musl-arm64.tar.gz"
|
||||
|
||||
[tools.dotnet."platforms.linux-x64"]
|
||||
checksum = "sha512:bc87ac5d0cdaa601354fdf58d6680890e5ad1a11b63ff0042207ea392ad9f0a3a531e3d3e0c543f8dccf93a085d6df01459139eb581f9922c27d3f9ddba719cb"
|
||||
url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.401/dotnet-sdk-10.0.401-linux-x64.tar.gz"
|
||||
|
||||
[tools.dotnet."platforms.linux-x64-musl"]
|
||||
checksum = "sha512:3a994e48a600ec1cafc0bac75c84fd89701a3972ea4afb4cd3df84ab23ab5d0f863364d13d6baf0ae1e11d568706ca6689827da557dc63c728bbcd8983d91175"
|
||||
url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.401/dotnet-sdk-10.0.401-linux-musl-x64.tar.gz"
|
||||
|
||||
[[tools.go]]
|
||||
version = "1.27.2"
|
||||
backend = "core:go"
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ stderr '^devvm: arg_missing args=TOOL\.\.\. command=devvm tools add$'
|
||||
! exec devvm tools add python+claude
|
||||
stderr '^devvm: tools_joined cmd=add given=python\+claude$'
|
||||
! exec devvm tools add docker
|
||||
stderr '^devvm: unknown_tool tool=docker tools=node python rust go claude codex opencode$'
|
||||
stderr '^devvm: unknown_tool tool=docker tools=node python rust go dotnet claude codex opencode$'
|
||||
exec devvm tools add node claude
|
||||
stdout '^==> has_tools tools=node vm=devvm-web-[0-9a-f]{14}$'
|
||||
stdout '^==> vm_tools_now tools=node claude vm=devvm-web-[0-9a-f]{14}$'
|
||||
|
||||
Vendored
+32
@@ -97,6 +97,29 @@ project cli
|
||||
exec devvm --network open --no-git-protect --tools go --agents claude
|
||||
! stdout 'checking_tools|building_tools'
|
||||
|
||||
# A .NET project's file calls for dotnet, named in the summary. Its build
|
||||
# gets the lock's download for this VM's platform and its SHA-512 after
|
||||
# its tool, version and file, which build.sh checks the SDK's archive
|
||||
# against (mise's own installer for it checks nothing).
|
||||
project shop
|
||||
cp $WORK/Shop.csproj Shop.csproj
|
||||
stub_reset
|
||||
exec devvm --network open --no-git-protect
|
||||
stdout '^new_vm_toolchain_for file=Shop\.csproj tool=dotnet$'
|
||||
stdout '^==> building_tools tools=dotnet 10\.0\.401$'
|
||||
vm_name SHOP shop
|
||||
vm_state $SHOP_dir/vm.json
|
||||
stdout '^tools.names=dotnet$'
|
||||
stdout '^tools.made.files=dotnet-10\.0\.401-[0-9a-f]{12}\.erofs$'
|
||||
stub_calls
|
||||
stdout '^limactl shell --workdir / devvm-tools-build bash -s -- dotnet 10\.0\.401 dotnet-10\.0\.401-[0-9a-f]{12}\.erofs https://builds\.dotnet\.microsoft\.com/dotnet/Sdk/10\.0\.401/dotnet-sdk-10\.0\.401-linux-(arm64|x64)\.tar\.gz [0-9a-f]{128}$'
|
||||
# global.json alone calls for it too.
|
||||
project sdk
|
||||
cp $WORK/global.json global.json
|
||||
exec devvm --network open --no-git-protect
|
||||
stdout '^new_vm_toolchain_for file=global\.json tool=dotnet$'
|
||||
! stdout 'building_tools'
|
||||
|
||||
# The shared tools aren't images: build and rebuild refuse them.
|
||||
! exec devvm rebuild node
|
||||
stderr '^devvm: tool_not_layer tool=node$'
|
||||
@@ -171,3 +194,12 @@ late: 1, mount ./share
|
||||
never: 60, 60 mounts
|
||||
-- package.json --
|
||||
{}
|
||||
-- Shop.csproj --
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
-- global.json --
|
||||
{ "sdk": { "version": "10.0.401" } }
|
||||
Vendored
+1
-1
@@ -158,7 +158,7 @@ stderr '^devvm: part_other_flag flag=--tools given=claude other=--agents$'
|
||||
! exec devvm --tools node,docker
|
||||
stderr '^devvm: part_other_flag flag=--tools given=docker other=--layers$'
|
||||
! exec devvm --tools java
|
||||
stderr '^devvm: unknown_part flag=--tools given=java names=node python rust go$'
|
||||
stderr '^devvm: unknown_part flag=--tools given=java names=node python rust go dotnet$'
|
||||
! exec devvm --agents cladue
|
||||
stderr '^devvm: unknown_part_like flag=--agents given=cladue like=claude$'
|
||||
! exec devvm --layers node
|
||||
|
||||
+22
-1
@@ -1,4 +1,4 @@
|
||||
# devvm e2e: shared-tools/mise.toml sha256:489cd0a62f4e363c3d2921caeb8fef7f3197e8b6e886c9395ed72cfcb74a6422
|
||||
# devvm e2e: shared-tools/mise.toml sha256:4ab9d148c8cf4837708baa7dcbc7458163589863c1c142c8d0fedfdfac2af4ef
|
||||
# @generated - this file is auto-generated by `mise lock` https://mise.jdx.dev/dev-tools/mise-lock.html
|
||||
|
||||
lockfile_version = 4
|
||||
@@ -86,6 +86,27 @@ checksum = "sha256:1d44b28bc4ac9937d7d3532264baa68a507ce364956a0d4ebb856f331cdee
|
||||
url = "https://github.com/openai/codex/releases/download/rust-v0.166.0/codex-package-x86_64-unknown-linux-musl.tar.gz"
|
||||
url_api = "https://api.github.com/repos/openai/codex/releases/assets/689712510"
|
||||
|
||||
[[tools.dotnet]]
|
||||
version = "10.0.403"
|
||||
backend = "core:dotnet"
|
||||
specifiers = ["latest"]
|
||||
|
||||
[tools.dotnet."platforms.linux-arm64"]
|
||||
checksum = "sha512:0966aa2b70f4677b8319be9df447a78a0dcd6164836425b55a68fd714f4023feb87b4cac21b9a996b79472ad54487cd0adcd2a9dfd570e2b2a1d26423a2baa9b"
|
||||
url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.403/dotnet-sdk-10.0.403-linux-arm64.tar.gz"
|
||||
|
||||
[tools.dotnet."platforms.linux-arm64-musl"]
|
||||
checksum = "sha512:a5a881429e879f0ff01e84a768dbc022e7fed0f4c2fe4936c0bec134fa184d16b42f98e1e43bc1c0fea5e9ce442fe57efc87bdc04023e337f9b0013c849bc2b1"
|
||||
url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.403/dotnet-sdk-10.0.403-linux-musl-arm64.tar.gz"
|
||||
|
||||
[tools.dotnet."platforms.linux-x64"]
|
||||
checksum = "sha512:b7b3d8461cf98b07d2552ce9199702fa3ad010ac2671a5f8cd5136f7534e50f6855ba7bbb02b11494563f1d04156276a31cda1103b900e5eecd0d9473dc7b9c5"
|
||||
url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.403/dotnet-sdk-10.0.403-linux-x64.tar.gz"
|
||||
|
||||
[tools.dotnet."platforms.linux-x64-musl"]
|
||||
checksum = "sha512:7c85806aeb15b5c02e282234532ac599f69409e45ba4ef09c13e848441d3a092c4e030efaaecbd271896c4137429c90daf3f44ca9805fa27468cc2323c670ac8"
|
||||
url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.403/dotnet-sdk-10.0.403-linux-musl-x64.tar.gz"
|
||||
|
||||
[[tools.go]]
|
||||
version = "1.27.3"
|
||||
backend = "core:go"
|
||||
|
||||
@@ -258,6 +258,7 @@ func fromDebianRuns(s *S, vm string) {
|
||||
func fromAlpineVM(s *S, nd []string) {
|
||||
al, _ := s.NewProject("fromalpine")
|
||||
_ = os.WriteFile(filepath.Join(al, "package.json"), []byte("{}\n"), 0o644) //nolint:gosec // a project's file, as a user's
|
||||
_ = os.WriteFile(filepath.Join(al, "global.json"), []byte("{}\n"), 0o644) //nolint:gosec // a project's file, as a user's
|
||||
vm, launched, _ := launchWith(s, al, nd, "--from", fromAlpine, "--network", "open", "--layers", "docker,nix,desktop")
|
||||
s.Check("an Alpine VM runs node from musl tool images", func() error {
|
||||
if vm == "" || s.Paths.State(vm)["tools.made.libc"] != "musl" || s.Paths.Record(fromRecord(s.Paths, fromAlpine), "libc") != "musl" {
|
||||
@@ -286,6 +287,8 @@ func fromAlpineVM(s *S, nd []string) {
|
||||
})
|
||||
inVMCheck(s, "and node, pnpm work there", vm,
|
||||
"grep -q '^ID=alpine' /etc/os-release && [[ $(node -v) == v"+s.Paths.ToolVersion("node")+` ]] && node -e 'require("os")' && pnpm -v`)
|
||||
inVMCheck(s, "and dotnet, its global.json's: the musl SDK, with ICU, makes and runs a console project", vm,
|
||||
"[[ $(dotnet --version) == "+s.Paths.ToolVersion("dotnet")+" ]] && cd /tmp && dotnet new console -o hello >/dev/null && [[ $(dotnet run --project hello) == 'Hello, World!' ]]")
|
||||
inVMCheck(s, "the docker layer's Docker runs in it (OpenRC)", vm, `sudo docker run --rm hello-world | grep -q Hello`, Needs(backend.FeatureDockerLayer))
|
||||
inVMCheck(s, "the desktop layer's programs are in it (Alpine's packages)", vm,
|
||||
`command -v Xvnc && command -v startxfce4 && command -v vncconfig && [[ -x /usr/local/bin/devvm-desktop ]]`)
|
||||
|
||||
+103
-18
@@ -11,6 +11,8 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/devvmhq/devvm/internal/tools"
|
||||
)
|
||||
|
||||
// toolsSection: what a user gets, upstream's newest versions of the shared
|
||||
@@ -18,7 +20,8 @@ import (
|
||||
// by devvm's pinned mise, downloaded and checked on the first run. This
|
||||
// section alone uses them: the pinned lock goes back at its end. A node
|
||||
// VM mounts them read-only from the share, at boot too; a tool missing
|
||||
// from the share stops the launch; devvm tools and devvm update.
|
||||
// from the share stops the launch; devvm tools and devvm update; a .NET
|
||||
// project's VM.
|
||||
func toolsSection(s *S) {
|
||||
s.Section("shared tool versions")
|
||||
s.Check("the shared tools resolve to upstream's newest, with checksums", func() error {
|
||||
@@ -32,23 +35,32 @@ func toolsSection(s *S) {
|
||||
toolsShare(s, vm, t)
|
||||
toolsMissing(s, vm, t)
|
||||
toolsCommands(s)
|
||||
toolsDotnet(s)
|
||||
if err := s.sb.pinLock(); err != nil {
|
||||
s.r.out.line(" e2e: couldn't put the pinned tool lock back")
|
||||
}
|
||||
}
|
||||
|
||||
// newestLock fails unless the lock has every shared tool, each with a
|
||||
// SHA-256 for this machine's Linux but rust, which rustup checks.
|
||||
// SHA-256 for this machine's Linux but rust, which rustup checks, and
|
||||
// dotnet, which has the SHA-512 devvm added from Microsoft's releases.
|
||||
func newestLock(s *S) error {
|
||||
toml, err := os.ReadFile(filepath.Join(s.sb.root, "assets", "shared-tools", "mise.toml"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lock, err := os.ReadFile(s.Paths.ToolLock)
|
||||
data, err := os.ReadFile(s.Paths.ToolLock)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ntools, in := 0, false
|
||||
// devvm writes the lock again as TOML of its own when it adds dotnet's
|
||||
// downloads, so it's read as TOML.
|
||||
lock, err := tools.ParseLock(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var names []string
|
||||
in := false
|
||||
for line := range strings.Lines(string(toml)) {
|
||||
line = strings.TrimSpace(line)
|
||||
switch {
|
||||
@@ -57,25 +69,27 @@ func newestLock(s *S) error {
|
||||
case strings.HasPrefix(line, "["):
|
||||
in = false
|
||||
case in && strings.Count(line, "=") == 1:
|
||||
ntools++
|
||||
name, _, _ := strings.Cut(line, "=")
|
||||
names = append(names, strings.TrimSpace(name))
|
||||
}
|
||||
}
|
||||
march := "arm64" // the lock's platform: mise's name for the arch
|
||||
if runtime.GOARCH == "amd64" {
|
||||
march = "x64"
|
||||
}
|
||||
lines := strings.Split(string(lock), "\n")
|
||||
entries, sums := 0, 0
|
||||
for i, l := range lines {
|
||||
if strings.HasPrefix(l, "[[tools.") {
|
||||
entries++
|
||||
platform := "linux-" + tools.MiseArch(runtime.GOARCH)
|
||||
var bad []string
|
||||
for _, n := range names {
|
||||
_, sum := lock.Download(n, platform)
|
||||
want := `^sha256:[0-9a-f]{64}$`
|
||||
switch n {
|
||||
case "rust":
|
||||
want = `^$`
|
||||
case "dotnet":
|
||||
want = `^sha512:[0-9a-f]{128}$`
|
||||
}
|
||||
if strings.Contains(l, `"platforms.linux-`+march+`"]`) && i+1 < len(lines) && strings.HasPrefix(lines[i+1], `checksum = "sha256:`) {
|
||||
sums++
|
||||
if !lock.Has(n) || !Matches(sum, want) {
|
||||
bad = append(bad, n)
|
||||
}
|
||||
}
|
||||
if entries != ntools || sums != ntools-1 {
|
||||
return fmt.Errorf("the lock has %d tools and %d checksums for linux-%s; mise.toml has %d tools", entries, sums, march, ntools)
|
||||
if len(names) == 0 || len(bad) > 0 {
|
||||
return fmt.Errorf("the lock lacks %q, or their checksums for %s; mise.toml has %q", bad, platform, names)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -414,4 +428,75 @@ func toolsRmAdd(s *S, vm, t2 string) {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
_, _ = s.Limactl("stop", vm) // before the dotnet VM: two VMs at once starve a nested Linux host
|
||||
}
|
||||
|
||||
// dotnetOther is the SDK a global.json in toolsDotnet asks for, which
|
||||
// isn't the shared one: mise installs it into the VM.
|
||||
const dotnetOther = "8.0.427"
|
||||
|
||||
// toolsDotnet: a .NET project's VM on the allowlist tier, its file calling
|
||||
// for dotnet: the shared SDK runs from the share; a console project
|
||||
// restores a package from NuGet, builds and runs; a global tool installs
|
||||
// into ~/.dotnet/tools and runs from a non-login shell; a workload
|
||||
// installs into ~/.dotnet, the SDK's folder being read-only; nothing it
|
||||
// reached was blocked; and a global.json's SDK installs into the VM.
|
||||
func toolsDotnet(s *S) {
|
||||
var vm string
|
||||
t, err := s.NewProject("dotnet")
|
||||
if err == nil {
|
||||
err = os.WriteFile(filepath.Join(t, "Shop.slnx"), []byte("<Solution />\n"), 0o600)
|
||||
}
|
||||
if err == nil {
|
||||
vm, _, _ = s.Launch(t, "exit", "--network", "allowlist", "--no-git-protect")
|
||||
}
|
||||
v := s.Paths.ToolVersion("dotnet")
|
||||
st := func() map[string]string { return s.Paths.State(vm) }
|
||||
inVM := func(script string) func() error {
|
||||
return func() error { _, err := s.InVM(vm, script); return err }
|
||||
}
|
||||
s.Check("a .NET project's VM: dotnet's tool image, at the lock's version, in its state", func() error {
|
||||
switch {
|
||||
case vm == "" || s.Status(vm) != "Running":
|
||||
return errors.New("the dotnet VM isn't running")
|
||||
case st()["tools.names"] != "dotnet" || !Matches("files="+st()["tools.made.files"], `^files=dotnet-`+regexp.QuoteMeta(v)+`-[0-9a-f]{12}\.erofs$`):
|
||||
return errors.New("its tools aren't dotnet's at the lock's version")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
for _, f := range strings.Fields(st()["tools.made.files"]) {
|
||||
b, _ := os.ReadFile(filepath.Join(s.Paths.Share, f+".json"))
|
||||
s.r.out.line(" glibc: %s needs %s", f, CaptureLine(string(b), `^ "glibc": "(.*)",?$`))
|
||||
}
|
||||
s.Check("dotnet runs the shared SDK from the share, read-only, with telemetry off", inVM(
|
||||
`[[ $(dotnet --version) == `+v+` && $DOTNET_CLI_TELEMETRY_OPTOUT == 1 ]] && p=$(readlink -f "$(mise which dotnet)") &&
|
||||
[[ $p == /opt/devvm/tools/dotnet/`+v+`/dotnet ]] && ! touch /opt/devvm/tools/dotnet/`+v+`/x 2>/dev/null`))
|
||||
s.Check("a console project restores a package from NuGet, builds and runs", inVM(
|
||||
"cd "+t+" && dotnet new console -o hello >/dev/null && cd hello && dotnet add package Newtonsoft.Json --version 13.0.3 >/dev/null &&"+
|
||||
" dotnet restore >/dev/null && dotnet build >/dev/null && [[ $(dotnet run) == 'Hello, World!' ]]"))
|
||||
s.Check("dotnet tool install -g installs into ~/.dotnet/tools, on the PATH", inVM(
|
||||
"dotnet tool install -g dotnetsay --version 3.0.3 >/dev/null && [[ $(command -v dotnetsay) == $HOME/.dotnet/tools/dotnetsay ]]"))
|
||||
s.Check("the global tool runs from a non-login shell", func() error {
|
||||
_, err := s.Run(Cmd{Args: []string{"ssh", "-F", filepath.Join(s.sb.lima, vm, "ssh.config"), "lima-" + vm, "dotnetsay hi"}})
|
||||
return err
|
||||
})
|
||||
s.Check("a workload installs into ~/.dotnet", inVM(
|
||||
"dotnet workload install wasi-experimental >/dev/null && dotnet workload list | grep -q '^wasi-experimental ' && [[ -d ~/.dotnet/packs ]]"))
|
||||
s.Check("the project's restore, tool and workload reached nothing the allowlist blocks", func() error {
|
||||
r, err := s.Devvm(t, "network", "log", "-n", "100000")
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case !Matches(r.Out, ` allowed api\.nuget\.org:443 `):
|
||||
return errors.New("devvm network log doesn't show NuGet\n" + r.Out)
|
||||
case strings.Contains(r.Out, " BLOCKED "):
|
||||
return errors.New("the proxy blocked a host\n" + r.Out)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
s.Check("a global.json's SDK installs into the VM, and the shared one runs again without it", inVM(
|
||||
"cd "+t+` && echo '{ "sdk": { "version": "`+dotnetOther+`" } }' > global.json && [[ $(dotnet --version 2>/dev/null) == `+dotnetOther+` ]] &&
|
||||
[[ $(readlink -f "$(mise which dotnet)") == $HOME/.local/share/mise/installs/dotnet/`+dotnetOther+`/dotnet ]]; r=$?; rm global.json
|
||||
[[ $r == 0 && $(dotnet --version) == `+v+` ]]`))
|
||||
_, _ = s.Limactl("stop", vm) // two VMs at once starve a nested Linux host
|
||||
}
|
||||
Reference in new issue
Block a user