# devvm build: base from Ubuntu's cloud image, a layer as a clone of its # parent's image, each built once and recorded; what a failed or # interrupted build leaves behind (a stopped VM to inspect, or nothing). env IMAGES=$XDG_DATA_HOME/devvm/images mkdir $XDG_CONFIG_HOME/devvm/layers cp foo.sh $XDG_CONFIG_HOME/devvm/layers/foo.sh cp bar.sh $XDG_CONFIG_HOME/devvm/layers/bar.sh # base: Ubuntu's newest dated release, its signed checksums checked, pinned # on this machine first; without host mounts, confined; its record says # which image it came from. base.yaml goes on limactl create's input, from # the binary: devvm writes none of its own files out. ! exists $IMAGES/ubuntu.json exec devvm build base stdout '^==> origin_pinned origin=release-20261016$' stdout '^==> building_image image=base key=[0-9a-f]{12}$' stdout '^base_build_time$' stdout '^==> image_ready image=base$' catg $IMAGES/ubuntu.json stdout '^ "release": "release-20261016",$' stdout '^ "digest": "sha256:[0-9a-f]{64}",$' stub_calls # Lima gets devvm's own copy of the image, named for the pin's digest. stdout '^limactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} --set \.images = \[\{"location":"/\S*/data/devvm/images/ubuntu/[0-9a-f]{64}\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"\}\] --cpus=4 --memory=8 --disk=100 -$' cmp $STUB_DIR/create-template $DEVVM_REPO/assets/base.yaml ! exists $XDG_DATA_HOME/devvm/assets stdout '^limactl edit --tty=false devvm-img-[0-9a-f]{12} .*--set \.portForwards = \[\{"guestIP":"127\.0\.0\.1"' stdout '^limactl start --tty=false devvm-img-[0-9a-f]{12}$' stdout '^limactl shell --start=false devvm-img-[0-9a-f]{12} bash -s$' stdout '^limactl shell --start=false --workdir / devvm-img-[0-9a-f]{12} sync$' stdout '^limactl stop devvm-img-[0-9a-f]{12}$' # Its ssh port is devvm's, on every host, given up once it has started. stdout '^limactl edit --tty=false devvm-img-[0-9a-f]{12} --set \.ssh\.localPort=[1-9][0-9]+ ' exists $RUN/build-ports ! exec sh -c 'ls -A "$RUN/build-ports" | grep .' grep 'Essentials, and mise' $STUB_DIR/scripts catg $IMAGES/????????????/record.json stdout '^ "name": "base",$' stdout '^ "chain": "base=[0-9a-f]{12}",$' stdout '^ "digest": "file://.*/release-[0-9]{8}/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img sha256:[0-9a-f]{64}",$' stdout '^ "libc": "gnu",$' stdout '^ "built": "\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ",$' stdout '^ "made_by": "\S+"$' # Each step is numbered in the run log, and the count is what ran. catg $DATA/logs/runs/*.log stdout '^# \[1/7\] creating_from_ubuntu vm=devvm-img-' stdout '^# \[2/7\] configuring what=devvm-img-' stdout '^# \[3/7\] starting what=devvm-img-' stdout '^# \[4/7\] running_script script=apt\.sh what=devvm-img-' stdout '^# \[5/7\] running_script script=base\.sh what=devvm-img-' stdout '^# \[6/7\] running_script script=apt\.sh what=devvm-img-' stdout '^# \[7/7\] stopping vm=devvm-img-' ! stdout '\[8/7\]' # Its packages: a recording, sent no mirror (config.toml sets none), which # gave back none, recorded under base's key. exec tar -tf $STUB_DIR/packages-in.tar cmp stdout want-recording exists $DATA/packages/sets exec sh -c 'ls "$XDG_DATA_HOME"/devvm/packages/sets' stdout '^[0-9a-f]{12}\.json$' # Built and recorded: reused, from the image pinned. stub_reset exec devvm build base ! stdout building_image ! stdout origin_pinned stub_calls ! stdout 'create|clone|start' # An image without a record is a failed build: deleted and built again. # With -v, the run log's lines are streamed to stderr as well, numbered # steps and commands, and the log still gets them. exec sh -c 'rm "$IMAGES"/????????????/record.json' exec devvm -v build base stdout '^==> image_leftover image=base key=[0-9a-f]{12}$' stderr '^# \[1/7\] creating_from_ubuntu vm=devvm-img-' stderr '^\+ limactl create ' # Built again under the same key, it replays the set recorded. exec tar -tf $STUB_DIR/packages-in.tar cmp stdout want-replay ! stdout '^\+ limactl' exec sh -c 'ls -t "$XDG_DATA_HOME"/devvm/logs/runs/*.log | head -1 | xargs cat' stdout '^\+ limactl create ' stub_calls stdout '^limactl delete -f devvm-img-[0-9a-f]{12}$' catg $IMAGES/????????????/record.json stdout '^ "name": "base",$' # A layer is a clone of its parent's image, without host mounts, running # the user's script; its record has its whole chain. exec sh -c ': > "$STUB_LOG" && : > "$STUB_DIR/scripts"' exec devvm build base+foo stdout '^==> building_image image=foo key=[0-9a-f]{12}$' ! stdout 'image=base' stub_calls stdout '^limactl clone --tty=false --mount-none devvm-img-[0-9a-f]{12} devvm-img-[0-9a-f]{12}$' ! stdout 'limactl create' grep '^echo foo$' $STUB_DIR/scripts exec sh -c 'cat "$IMAGES"/????????????/record.json' stdout '^ "chain": "base=[0-9a-f]{12} foo=[0-9a-f]{12}",$' stdout -count=2 '^ "libc": "gnu",$' # Names that aren't base or a layer are refused, before anything runs. stub_reset ! exec devvm build foo+stray stderr '^devvm: unknown_layer layer=stray layers=base bar desktop docker foo nix$' ! exec devvm build stray+node stderr '^devvm: unknown_layer layer=stray layers=base bar desktop docker foo nix$' ! exec devvm build '' stderr '^devvm: arg_blank command=devvm build$' ! exec devvm rebuild ../../x stderr '^devvm: unknown_layer layer=\.\./\.\./x layers=base bar desktop docker foo nix$' ! exec devvm build stderr '^devvm: arg_missing args=IMAGE command=devvm build$' # An image holds base and layers alone: a shared tool's name is refused, # naming it. ! exec devvm build node stderr '^devvm: tool_not_layer tool=node$' ! exec devvm build foo+claude stderr '^devvm: tool_not_layer tool=claude$' ! exec devvm rebuild node stderr '^devvm: tool_not_layer tool=node$' ! stub_calls # A failed script: the end of the run log, and the image's VM kept, # stopped and without a record, for inspection in devvm's Lima home. exec sh -c ': > "$STUB_DIR/shell-fails"' ! exec devvm build foo+bar stderr '^--- log_end file=.*\.log$' stderr '^\+ limactl shell --start=false --workdir / devvm-img-[0-9a-f]{12} sudo bash -s -- lists$' stderr '^devvm: script_failed script=apt\.sh vm=devvm-img-[0-9a-f]{12}$' ! stdout unfinished_image stub_calls stdout '^limactl stop devvm-img-[0-9a-f]{12}$' ! stdout 'limactl delete' exec sh -c 'stub vms | grep -c .; stub vms | grep -c " Stopped$"; ls "$IMAGES"/????????????/record.json | grep -c .' stdout '^3\n3\n2\n$' rm $STUB_DIR/shell-fails # The next build deletes it first. While it builds, devvm images lists it # as building, gc leaves it and images rm refuses it. Ctrl+C during a # build deletes the unfinished image, never a finished one. exec sh -c ': > "$STUB_LOG" && : > "$STUB_DIR/shell-hangs"' ! exec devvm build foo+bar &b& wait_file $STUB_DIR/hanging exec devvm images stdout '^- +- +- +[0-9a-f]{12} +building +' exec sh -c 'devvm images | awk "\$5 == \"building\" { print \$4 }" > building.key' exec devvm gc --force ! stdout 'gc_unfinished|deleted_unfinished_build' exec sh -c '! devvm images rm --force "$(cat building.key)"' stderr '^devvm: image_building key=[0-9a-f]{12}$' exec sh -c 'grep "^limactl delete" "$STUB_LOG" | grep -c "$(cat building.key)"' stdout '^1$' kill -INT b wait b stdout '^==> image_leftover image=foo\+bar key=[0-9a-f]{12}$' stdout '^==> interrupted_image vm=devvm-img-[0-9a-f]{12}$' ! stderr script_failed stub_calls stdout -count=2 '^limactl delete -f devvm-img-[0-9a-f]{12}$' exec sh -c 'stub vms | grep -c .; ls "$IMAGES"/????????????/record.json | grep -c .' stdout '^2\n2\n$' rm $STUB_DIR/shell-hangs # A failed clone: nothing to inspect, so the partial instance is deleted. exec sh -c ': > "$STUB_LOG" && : > "$STUB_DIR/clone-fails"' ! exec devvm build foo+bar stderr '^devvm: vm_create_failed vm=devvm-img-[0-9a-f]{12}$' stdout '^==> unfinished_image vm=devvm-img-[0-9a-f]{12}$' stub_calls stdout -count=1 '^limactl delete -f devvm-img-[0-9a-f]{12}$' exec sh -c 'stub vms | grep -c .; ls "$IMAGES"/????????????/record.json | grep -c .' stdout '^2\n2\n$' rm $STUB_DIR/clone-fails -- want-recording -- in/mirrors -- want-replay -- in/Packages -- foo.sh -- #!/bin/bash echo foo -- bar.sh -- #!/bin/bash echo bar