mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
docs: the state layout, each part described once in its owner page
Overview's State files explains the two folders, the formats, a VM's folder file by file, its state and the locks; the data folder's listing is space.md's and the config folder's settings.md's, linked from the others. design.md gets a note on the layout and why no database. Contributing names the paths and how to add a file, socket, record, default or lock. Stale facts fixed: the claims lock in space.md and design.md, the forwarder's control socket, the config folder's version, the proxy README's Nix cache path, an export's .folder file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
8 files changed
+85
-52
No files matched your search
@@ -157,6 +157,8 @@ Each copy gets one of three outcomes: extend the owner, make one owner, or leave
|
||||
|
||||
## Changing the state layout
|
||||
|
||||
[State files](../internals/overview.md#state-files) describes the layout, and [the design note](../internals/design.md#the-state-layout) says why it's built that way. Every path in it comes from `internal/paths`. `paths.Dirs` names the shared folders and files, and `Dirs.VM(name)` gives a VM's `paths.VM`, whose methods name each file in the VM's folder: `Dirs.VMDir(hash)`, `vms/<hash>/`, for a project VM, and `run/builds/<name>/` for a build VM. A new file of a VM's gets a method on `paths.VM`, so it lands in the VM's folder, and `vmFolders.teardown` in `internal/vm/teardown.go` deletes it with the folder, with no list of files to update. A new socket goes in `Dirs.Run()`, named by a hash, and `TestSocketsFit` checks the longest path against `paths.SocketMax`. A new record that only devvm writes is JSON, read with `encoding/json`, which ignores fields it doesn't know, and written whole with `state.WriteFile`. A new default goes in `internal/settings`, which reads `config.toml` strictly and saves `settings.json`, and a new lock is an OS file lock (`platform.LockFile` and its kin) on a file that `paths` names.
|
||||
|
||||
The data folder and the config folder each hold a `version` file with their layout version, `state.Layout` in `internal/state/layout.go`. Before each command that reads them, `state.CheckLayout` takes `version.lock` in the data folder and compares both files with `state.Layout`. A folder without the file gets this devvm's version, the same version goes on, and a newer one stops the command with `layout_newer`, because a newer devvm changed the folders. An older one runs the migrations from that version to this one, in order, and then writes `state.Layout` into both files. `skipsLayout` in `internal/cli/root.go` lists the commands that skip the check: help, completion, the version and devvm's own hidden commands.
|
||||
|
||||
`testdata/script/layout.txtar` makes two VMs with network policy, a forwarded port, a link and a secret, lists every file and folder under the data and config folders, and compares the lists with the ones at the end of the script, one for macOS and one for Linux. A change to the layout, such as a new file, a renamed folder or a file that moves, changes a listing, so the test fails until you update it. When it does, decide whether the change needs a new layout version:
|
||||
|
||||
@@ -61,7 +61,7 @@ These settings guard against the host's ssh asking for a forward that devvm's en
|
||||
- **A guest port bound around the rules:** ruled out on macOS with network policy. Lima forwards a port only by binding it on the host, and the sandbox refuses every port but the ssh port. End to end, with Lima's own rule put back for one start inside the sandbox, Lima tries the guest's TCP and UDP ports, is refused (`operation not permitted`), and has no port but its ssh port, while devvm's forwarder forwards the TCP port.
|
||||
- **The ssh port on every address:** listed. Seatbelt allows the ssh port on any address, so a Lima that bound it on `0.0.0.0` would put the VM's sshd on the network, where it still takes only keys. Lima binds it on `127.0.0.1`, and the end-to-end checks look at the hostagent's listeners. The rule allows the port over TCP alone, so the guest's UDP server on that port number can't get a forward from it; checked end to end.
|
||||
- **A program holding a stopped VM's ssh port:** ruled out, but for a race. A start looks for the recorded port with a bind on `127.0.0.1` and `::1` as well as a connection, so a program that has the port on any address, even one that accepts no connections, gives the VM a new port. Only a program that takes the port between that check and Lima's bind, a few seconds later, gets Lima's ssh, which is listed under not covered below. End to end, a VM whose port a host program holds starts on a new one, recorded, and the program keeps its own.
|
||||
- **Two VMs choosing the same ssh port:** confirmed, fixed. Without a lock, two devvm commands making VMs at once could each choose the same port from the ports other VMs record, and the second VM's Lima would wait on a port that the first one's has. devvm chooses and records a port while it holds its ports lock.
|
||||
- **Two VMs choosing the same ssh port:** confirmed, fixed. Without a lock, two devvm commands making VMs at once could each choose the same port from the ports other VMs record, and the second VM's Lima would wait on a port that the first one's has. devvm chooses and records a port while it holds the claims lock, `run/claims.lock` in its data folder, after the VM's own lock ([locks](overview.md#locks)).
|
||||
- **A build VM's ssh port:** listed. A build's ssh port is the one Lima or the backend picks at its start, which no VM's state records, so another VM forwarding every port could take it in the window before Lima binds it. Lima's ssh would then run the build's scripts in that VM, which learns nothing secret from them, because builds carry no credentials. An image is the build VM's own disk, and a tool build writes its images through a folder that only its own VM mounts, so the other VM can break a build but can't choose what an image or a tool image holds.
|
||||
- **What a failed start or create leaves:** ruled out. A VM whose create fails, other than by an interrupt, keeps its state, and with it its recorded port, until `devvm rm` deletes it, so the port stays reserved and nothing else takes it. `devvm rm` deletes the state, which frees the port.
|
||||
- **Unix sockets:** ruled out as a way out. The hostagent binds them only in the VM's Lima folder, which only Lima's own commands and devvm use.
|
||||
@@ -399,6 +399,20 @@ devvm's own files (`assets/` in the repo: `base.yaml`, `layers/`, `features/`, `
|
||||
|
||||
Lima merges `_config/default.yaml` and `override.yaml` of its home into every VM. In `~/.lima`, a `networks: [{vzNAT: true}]` there gave a VM with network policy a second network card with a default route around its proxy (the self-check caught it), and an extra mount went unnoticed. Hence a Lima home of devvm's own, which refuses those files and any network devvm didn't give a VM ([details](lima.md#a-lima-home-of-its-own)). The costs: plain `limactl list` doesn't show devvm's VMs, and VM names are shorter, as Lima's ssh socket path is at most 104 characters.
|
||||
|
||||
## The state layout
|
||||
|
||||
devvm keeps its state in plain files in two folders, which [State files](overview.md#state-files) describes. The layout follows a few rules:
|
||||
|
||||
- **One folder per VM, keyed by identity.** A VM's folder, `vms/<hash>/`, is named by the hash of its project folder's physical path, the same hash that ends the VM's name. The VM's name, its backend and its ssh alias are chosen once, when devvm makes the VM, and recorded in its state, so devvm finds a folder's VM by the hash, then reads the name and the backend from the state. A backend's limit on names, or another VM taking the same folder name, never changes which VM a folder finds. Every file devvm keeps for a VM is in its folder, so deleting a VM stops what runs for it, removes what it has outside the folder, and then deletes the folder whole, and `devvm space` and `devvm gc` count folders. A list of a VM's files, kept in each place that deletes or counts them, would drift, and one of those places would miss a file. Only sockets stay outside, in `run/` and named by hashes, because a socket's path is at most 104 characters.
|
||||
- **The folder says who writes a file.** `~/.config/devvm` holds what you write, and devvm never rewrites a file of yours there: it changes single lines of `policy` and keeps the rest, comments included, and it writes the folder's `version`. Everything devvm writes is in `~/.local/share/devvm`. A default comes from a flag, then `config.toml`, then `settings.json`, then devvm's own, and a command that would save a default that `config.toml` sets refuses, naming the file and the key, because the saved value would never apply.
|
||||
- **Two formats.** What you edit is TOML, read strictly, so a typo stops the command and devvm names the file and the line, rather than the key being ignored. What only devvm writes is JSON, through `encoding/json`, and devvm ignores fields it doesn't know, so a newer devvm's additions don't stop an older one. A change that an older devvm would read wrongly goes through the layout version instead.
|
||||
- **One section per package.** `vm.json` has the core fields every VM has, and each package that keeps something of a VM's owns one section of it, with its own type, so `internal/state` imports none of them. Each section keeps what you asked for apart from what devvm made, which sits under `made`, so a value is never stored twice under two names.
|
||||
- **The lock rule.** Each change to a VM's state holds that VM's lock, reads the file again, and writes it once, so a command's changes land together, and reads take no lock, because each write renames a whole file over the old one. A command holds at most one VM's lock at a time. A change across VMs, such as removing every link to a VM being deleted, lets go of the first VM's lock, then takes each other VM's lock in turn and reads its state again before writing it. The claims lock is taken only after a VM's own lock, never before, so no two devvms can each wait for the lock the other holds.
|
||||
- **A layout version.** Each folder records its layout version in `version`. A newer devvm that changes the layout raises it and adds a migration from the version before, an older layout is migrated before a command runs, and a newer one is refused, because this devvm would read it wrongly. `testdata/script/layout.txtar` lists every file and folder a VM with network policy, a port, a link and a secret leaves, so a change to the layout changes a listing and fails the test until someone decides whether it needs a new version ([changing the state layout](../contributing/_index.md#changing-the-state-layout)).
|
||||
- **devvm's own files stay in the binary,** as [one binary](#one-binary) describes, so neither folder holds a copy of `assets/`.
|
||||
|
||||
**Why not a database.** SQLite or bbolt would give transactions, but either one is a new dependency, and devvm builds without cgo, so SQLite would mean a large pure-Go port. State would also stop being files that you can read with `cat` or `jq`, back up, and check by hand. Files written whole and renamed into place, with an OS file lock for each VM, give what devvm needs: one writer to a VM at a time, and readers that never see half a file.
|
||||
|
||||
## Failed attempts
|
||||
|
||||
- **Claude's host login in VMs:** on macOS it's in the Keychain, which can't be shared. VMs use a `claude setup-token` token instead. The first token saved was the code the browser shows, so `devvm secret set claude` refuses one without the `sk-ant-oat01-` prefix.
|
||||
|
||||
@@ -98,33 +98,48 @@ On the way up, devvm also notes the nearest folder below the parent's that has a
|
||||
|
||||
## State files
|
||||
|
||||
devvm writes nothing into the project folder. It keeps what you edit in `~/.config/devvm` (`$XDG_CONFIG_HOME/devvm`), which [your settings](../using/settings.md#your-settings) lists file by file, and everything it writes itself in `~/.local/share/devvm` (`$XDG_DATA_HOME/devvm`):
|
||||
devvm writes nothing into the project folder. It keeps its files in two folders, and the folder a file is in says who writes it:
|
||||
|
||||
| Path in `~/.local/share/devvm` | Holds |
|
||||
- `~/.config/devvm` (`$XDG_CONFIG_HOME/devvm`) holds what you write: `config.toml`, your rules for every VM in `policy`, and your own layers, features and CAs. devvm never rewrites a file of yours there. It changes single lines of `policy` when `devvm network` adds or removes a rule for every VM, it writes a new layer's files when you run `devvm layer new`, and it writes the folder's `version` ([the layout version](#the-layout-version)). [Your settings](../using/settings.md#your-settings) lists the folder file by file.
|
||||
- `~/.local/share/devvm` (`$XDG_DATA_HOME/devvm`) holds everything devvm writes itself, and you never edit it. [devvm's data folder](../using/space.md#devvms-data-folder) lists it file by file, with how each one is cleaned up, and [what devvm keeps on this machine](../using/space.md) also lists what Lima keeps outside it.
|
||||
|
||||
The two folders use two formats. `config.toml` is TOML, which devvm reads strictly, so a key it doesn't know or a value that a key can't take stops the command, and devvm names the file and the line ([when devvm can't read it](../using/settings.md#when-devvm-cant-read-it)). devvm's own records are JSON: `settings.json`, each VM's `vm.json`, each image's record and each shared tool image's record. devvm ignores a field it doesn't know in them, so a field that a newer devvm adds doesn't stop an older one, and a change that an older devvm would read wrongly goes through the [layout version](#the-layout-version). devvm's other files are small ones of its own, such as pid files, the ssh config and the pinned host keys.
|
||||
|
||||
In the data folder, each VM has a folder of its own, `vms/<hash>/` ([a VM's folder](#a-vms-folder)), and the rest is shared by every VM:
|
||||
|
||||
- `settings.json` holds the defaults devvm's commands save, below `config.toml`'s ([where a default comes from](../using/settings.md#where-a-default-comes-from)).
|
||||
- `ssh_config` is the [ssh config](security.md#ssh-into-vms) for running VMs, and `known_hosts` holds their pinned host keys.
|
||||
- `agent-keys.json` lists the keys added to [devvm's own SSH agent](../using/ssh.md#devvms-own-agent), with each one's file, fingerprint, `confirm` and `lifetime`, and `agent.sock` is that agent's socket.
|
||||
- `secrets/` holds each [secret](network.md#where-secrets-are-saved) in a file of its own, on hosts without a Keychain.
|
||||
- `images/<key>/record.json` is each image's record, and `images/rebuilds.json` holds the [rebuild counters](images.md#rebuilding), by backend, `--from` and image.
|
||||
- `tools/` holds the [shared tools](images.md#the-share), each image with its record. Beside it are the tools lock, `mise.lock`, the `mise.toml` it was resolved from, `mise.lock.toml`, and `mise.lock.checked`, which says when devvm last [checked](images.md#versions) for newer versions.
|
||||
- `ca/` holds the certificate authority that VMs trust for the proxy.
|
||||
- `logs/runs/` holds the [run logs](../using/troubleshooting.md#a-command-fails), and `logs/tools-check.log` the daily tools check's output.
|
||||
- `exports/` holds the agents' history that `devvm history export` and `devvm rm` save.
|
||||
- `lima/` is devvm's own [Lima home](lima.md#a-lima-home-of-its-own), unless `DEVVM_LIMA_HOME` moves it.
|
||||
|
||||
`cache/` holds only what devvm makes again whenever it needs it, so it may be deleted at any time. That's devvm's own mise (`cache/mise/`), the [shared Nix cache](network.md#the-shared-nix-cache) (`cache/nix-cache/`) and the [digests](images.md#digests) of the container images that `--from` bases start from (`cache/from-digests.json`). `run/` holds what running VMs need that isn't one VM's, or whose path must be short: the QEMU wrapper on Linux hosts, the claims lock ([locks](#locks)), the sockets of port forwarders and link sessions, named by hashes, and in `builds/<name>/` each build VM's folder, laid out as a VM's folder is.
|
||||
|
||||
Each write replaces a file whole, so a file is never left half written. devvm makes its files readable only by you (mode 600), and the programs it keeps to run, such as its mise and QEMU wrapper, are mode 700, as are its folders. Before every command, devvm makes the data folder and `~/.config/devvm` when they're missing and sets both to mode 700, whatever mode they had. A wider mode on anything beneath them then opens nothing to others, and when devvm can't set a folder's mode, it warns and goes on. The folders that hold history, logs, keys or secrets (`exports/`, `logs/`, `logs/runs/`, `run/`, `ca/`, `secrets/`, and the `run/`, `logs/` and `backend/` folders in each VM's folder) are set to mode 700 again whenever devvm writes an export, a log, a key or a secret into them, whatever mode they had before. devvm refuses to use one of those folders when it's a symbolic link or not a folder at all, so it never sets the mode of whatever a link points to. The data folder and `~/.config/devvm` may be symbolic links, such as into a dotfiles repo, and devvm follows them. When a file can't be read, devvm names the file and the line, and you fix the line or delete the file.
|
||||
|
||||
### A VM's folder
|
||||
|
||||
Each VM's folder, `vms/<hash>/`, is named by the hash of its project folder's physical path, which also ends the VM's name, and it holds every file that devvm keeps for the VM in the data folder:
|
||||
|
||||
| Path in `vms/<hash>/` | Holds |
|
||||
| --- | --- |
|
||||
| `version`, `version.lock` | the folder's [layout version](#the-layout-version), and the lock each devvm checking it holds |
|
||||
| `settings.json` | the defaults devvm's commands save, below `config.toml`'s ([where a default comes from](../using/settings.md#where-a-default-comes-from)) |
|
||||
| `ssh_config`, `known_hosts` | the [ssh config](security.md#ssh-into-vms) for running VMs, and their pinned host keys |
|
||||
| `agent-keys.json` | the keys added to [devvm's own SSH agent](../using/ssh.md#devvms-own-agent): each one's file, fingerprint, `confirm` and `lifetime` |
|
||||
| `secrets/` | on hosts without a Keychain, each [secret](network.md#where-secrets-are-saved) in a file of its own |
|
||||
| `vms/<hash>/` | each VM's folder, named by the hash of its project folder's path that ends the VM's name: its state (`vm.json`), the lock each change to its state holds (`lock`), its own network rules (`policy`), its backend's files (`backend/`), its proxy's, link session's and sandbox's files (`run/`) and its logs (`logs/`) |
|
||||
| `images/<key>/record.json` | each image's record |
|
||||
| `images/rebuilds.json` | the [rebuild counters](images.md#rebuilding), by backend, `--from` and image |
|
||||
| `tools/`, `mise.lock` | the [shared tools](images.md#the-share), each image with its record, and the tools lock |
|
||||
| `cache/` | what devvm makes again whenever it needs it, so it may be deleted at any time: devvm's own mise (`cache/mise/`), the [shared Nix cache](network.md#the-shared-nix-cache) (`cache/nix-cache/`) and the [digests](images.md#digests) of the container images that `--from` bases start from (`cache/from-digests.json`) |
|
||||
| `mise.lock.toml`, `mise.lock.checked` | the `mise.toml` the tools lock was resolved from, and when devvm last [checked](images.md#versions) for newer versions |
|
||||
| `ca/` | the certificate authority that VMs trust for the proxy |
|
||||
| `oci-build.lock` | the lock a Lima build of a base [from a container image](images.md#how-its-converted) holds |
|
||||
| `tools.lock` | the lock a devvm [writing to the share](images.md#building-tools) or swapping the tools lock holds |
|
||||
| `images/locks/<key>`, `images/locks/rebuilds` | the lock the devvm [building an image](images.md#building) holds, and the one a devvm [changing a rebuild counter](images.md#rebuilding) holds |
|
||||
| `groups.lock` | the lock a devvm [joining or leaving a group](design.md#groups), or working its links out again, holds |
|
||||
| `run/` | what running VMs need that isn't one VM's or whose path must be short: the QEMU wrapper, the claims lock (`claims.lock`) and the sockets of port forwarders and link sessions, named by hashes, and in `builds/<name>/` each build VM's folder, laid out as a VM's folder is |
|
||||
| `logs/runs/`, `logs/tools-check.log` | the [run logs](../using/troubleshooting.md#a-command-fails) and the daily tools check's output |
|
||||
| `exports/` | the agents' history that `devvm history export` and `devvm rm` save |
|
||||
| `agent.sock` | the socket of [devvm's own SSH agent](../using/ssh.md#devvms-own-agent) |
|
||||
| `lima/` | devvm's own [Lima home](lima.md#a-lima-home-of-its-own), unless `DEVVM_LIMA_HOME` moves it |
|
||||
| `vm.json` | the VM's state ([a VM's state](#a-vms-state)) |
|
||||
| `lock` | the lock that each change to `vm.json` holds ([locks](#locks)) |
|
||||
| `policy` | the VM's own [network policy rules](network.md#policy-files), which `devvm network allow`, `deny` and `rm` change |
|
||||
| `backend/` | its backend's files: `ports`, which of the VM's ports devvm forwards, and its [port forwarder](ports.md#its-process-and-files)'s `ports.pid`, `ports.status`, `ports.log`, `ports.lock` and `ports.known_hosts` |
|
||||
| `run/` | what the VM's runs leave: its [proxy](network.md#the-proxy)'s `proxy.pid`, `proxy.status` and `proxy.auth`, what the proxy started with (`proxy.policy`, `proxy.bin` and `proxy.ca`, with `proxy.cas` and `proxy.upstream` [behind a company proxy](network.md#through-a-company-proxy)), its [secrets](network.md#how-the-proxy-puts-them-in)' bindings (`secrets.json`, `secrets.policy`), its [link session](ports.md#the-link-session)'s `links.pid` and `links.json`, the hostagent it was started on (`started`), and on macOS the hostagent's [sandbox profile](lima.md#confinement) (`sandbox.sb`) |
|
||||
| `logs/` | its proxy's decisions (`network.jsonl`) and its proxy's own output (`proxy.log`), which the [log files](network.md#log-files) describe, and its link session's output (`links.log`) |
|
||||
|
||||
[What devvm keeps on this machine](../using/space.md) says how each of these is cleaned up, and lists what the backends keep outside this folder.
|
||||
devvm finds a folder's VM by the hash of the folder's path, so an existing VM has the name and the backend its state records, whichever backend you ask for. Only a new VM gets a name, which fits its backend's limit. The VM's folder lasts as long as the VM, because `devvm rm` and `devvm gc --orphans` stop what runs for the VM, delete what devvm keeps for it outside the folder, and then delete the folder whole ([deleting a VM](#deleting-a-vm)), so the next devvm in that folder starts fresh.
|
||||
|
||||
No VM's folder holds a socket, because a unix socket's path is at most 104 characters and ssh adds 17 to a control socket's while it makes it. The sockets that VMs need are in `run/`, named by hashes: each port forwarder's control socket, `run/lima-<hash>.ctl`, and each link session's `run/link-<hash>.sock` and `run/link-<hash>.ctl`. With the default data folder, every socket fits for a home folder of up to 37 characters, and the ssh control sockets are the longest.
|
||||
|
||||
### A VM's state
|
||||
|
||||
A VM's state is `vm.json`, a JSON file that only devvm writes. It starts with the fields every VM has: the file's `version`, the VM's random `id`, its `name` and its ssh `alias`, the `image` the VM came from with its build `chain` and the `from` image its base started from, its project folder (`dir`) and that folder's identity (`folder`), its `backend` and where that backend kept it (`backend_at`), `created`, the time its backend finished making it, and `made_by`, the version of the devvm that made it, which later changes keep. A VM without `created` never starts, because its creation didn't finish. After those fields comes one section for each part of devvm that keeps something of the VM's:
|
||||
|
||||
@@ -144,13 +159,25 @@ A VM's state is `vm.json`, a JSON file that only devvm writes. It starts with th
|
||||
|
||||
Each section keeps what you asked for apart from what devvm made, which sits under the section's `made`. devvm reads fields it doesn't know without complaint and keeps them when it writes the file. A file that isn't JSON, lacks one of `version`, `id`, `name`, `image`, `dir` or `backend`, or holds a section devvm can't read is refused, and devvm names the file.
|
||||
|
||||
devvm finds a folder's VM by the hash of the folder's path, so an existing VM has the name and the backend its state records, whichever backend you ask for. Only a new VM gets a name, which fits its backend's limit, and devvm writes its whole state once, with everything you asked for, before its backend makes it. The VM's folder lasts as long as the VM, because `devvm rm` also deletes it, so the next devvm in that folder starts fresh.
|
||||
A new VM's whole state is written once, with everything you asked for, before its backend makes the VM.
|
||||
|
||||
Reading a VM's state takes no lock, because each write replaces the file whole. Each change takes the VM's `lock` with an OS file lock, reads the file again, makes the change and writes the file once, so a command's changes land together or not at all, and two devvms changing one VM at once lose neither's change. A command holds one VM's lock at a time. A change to other VMs, such as removing every link to a VM that `devvm rm` deletes, lets go of the first VM's lock and then takes each other VM's lock in turn. What no two VMs may have, a new VM's ssh alias and the host ports devvm chooses, is chosen under the claims lock, `run/claims.lock`, which devvm takes after the VM's own lock and holds until the VM's state is written.
|
||||
### Locks
|
||||
|
||||
No VM's folder holds a socket, because a unix socket's path is at most 104 characters and ssh adds 17 to a control socket's while it makes it. The sockets that VMs need are in `run/`, named by hashes: each port forwarder's control socket, `run/<backend>-<hash>.ctl`, and each link session's `run/link-<hash>.sock` and `run/link-<hash>.ctl`. With the default data folder, every socket fits for a home folder of up to 37 characters, and the ssh control sockets are the longest.
|
||||
Reading a VM's state takes no lock, because each write replaces the file whole. Each change takes the VM's `lock`, reads the file again, makes the change and writes the file once, so a command's changes land together or not at all, and two devvms changing one VM at once lose neither's change. A command holds one VM's lock at a time. A change to other VMs, such as removing every link to a VM that `devvm rm` deletes, lets go of the first VM's lock and then takes each other VM's lock in turn, reading each one's state again before it changes it. What no two VMs may have, a new VM's ssh alias and the host ports devvm chooses, is chosen under the claims lock, `run/claims.lock`, which devvm takes after the VM's own lock and holds until the VM's state is written.
|
||||
|
||||
Each write replaces a file whole, so a file is never left half written. devvm makes its files readable only by you (mode 600), and the programs it keeps to run, such as its mise and QEMU wrapper, are mode 700, as are its folders. Before every command, devvm makes the data folder and `~/.config/devvm` when they're missing and sets both to mode 700, whatever mode they had. A wider mode on anything beneath them then opens nothing to others, and when devvm can't set a folder's mode, it warns and goes on. The folders that hold history, logs, keys or secrets (`exports/`, `logs/`, `logs/runs/`, `run/`, `ca/`, `secrets/`, and the `run/`, `logs/` and `backend/` folders in each VM's folder) are set to mode 700 again whenever devvm writes an export, a log, a key or a secret into them, whatever mode they had before. devvm refuses to use one of those folders when it's a symbolic link or not a folder at all, so it never sets the mode of whatever a link points to. The data folder and `~/.config/devvm` may be symbolic links, such as into a dotfiles repo, and devvm follows them. When a file can't be read, devvm names the file and the line, and you fix the line or delete the file.
|
||||
Every lock devvm takes is an OS file lock on an open file, which the system lets go of when the devvm holding it ends, however it ends. So a lock file is empty, it stays when its lock is let go of, and a devvm that was killed never leaves a lock held. Besides each VM's `lock` and the claims lock, the data folder has these:
|
||||
|
||||
| Lock | Held by |
|
||||
| --- | --- |
|
||||
| `version.lock` | each devvm checking the [layout version](#the-layout-version) |
|
||||
| `vms/<hash>/backend/ports.lock` | whatever stops a VM's [port forwarder](ports.md#its-process-and-files) and starts the next one |
|
||||
| `images/locks/<key>` | the devvm [building an image](images.md#building) |
|
||||
| `images/locks/rebuilds` | a devvm [changing a rebuild counter](images.md#rebuilding) |
|
||||
| `oci-build.lock` | a Lima build of a base [from a container image](images.md#how-its-converted) |
|
||||
| `tools.lock` | a devvm [writing to the share](images.md#building-tools) or swapping the tools lock |
|
||||
| `making.lock` | each devvm making a VM or giving one new shared tools, shared, and `devvm gc --tool-images --force`, alone ([cleaning up](images.md#listing-and-cleaning-up)) |
|
||||
| `groups.lock` | a devvm [joining or leaving a group](design.md#groups), or working its links out again |
|
||||
| `retention.lock` | the devvm applying the [retention settings](../using/settings.md#retention) |
|
||||
|
||||
### The layout version
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ How the forwarder logs in, and when it ends, is up to the backend, as Lima's [Po
|
||||
|
||||
## Its process and files
|
||||
|
||||
The forwarder runs as a hidden devvm command, one process for each VM. devvm starts it after each start of the VM and again with the new ports when you change a running VM's ports, and `devvm stop` stops it. devvm keeps which ports a VM forwards in its own record for the VM, so `devvm ports` changes that record and never the backend's config. That record is in the VM's `backend/` folder, `~/.local/share/devvm/vms/<hash>/backend/`, and the forwarder's files are beside it: its log `ports.log`, and `ports.pid`, `ports.status`, `ports.known_hosts` and `ports.lock`. Its control socket is `~/.local/share/devvm/run/<backend>-<hash>.ctl`, outside the VM's folder, because a unix socket's path is at most 104 characters.
|
||||
The forwarder runs as a hidden devvm command, one process for each VM. devvm starts it after each start of the VM and again with the new ports when you change a running VM's ports, and `devvm stop` stops it. devvm keeps which ports a VM forwards in its own record for the VM, so `devvm ports` changes that record and never the backend's config. That record is in the VM's `backend/` folder, `~/.local/share/devvm/vms/<hash>/backend/`, and the forwarder's files are beside it: its log `ports.log`, and `ports.pid`, `ports.status`, `ports.known_hosts` and `ports.lock`. Its control socket is `~/.local/share/devvm/run/lima-<hash>.ctl`, named by a hash of the VM's name, outside the VM's folder, because a unix socket's path is at most 104 characters.
|
||||
|
||||
devvm reads every list of ports the same way, whether it comes from `--ports`, the VM's state or devvm's record. Each entry is a port from 1 to 65535 or a range of them, such as `8000-8010`. When the VM's state holds a list that devvm can't read this way, such as a file edited by hand, the VM doesn't start and devvm names the value it couldn't read with `port_invalid`, so a bad entry never becomes a port the VM didn't ask for.
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ title: Settings and files
|
||||
weight: 11
|
||||
---
|
||||
|
||||
devvm writes nothing into your project folders. It keeps the settings you edit in `~/.config/devvm` and everything it writes itself in `~/.local/share/devvm`, and it reads a few environment variables. [Overview](../internals/overview.md#state-files) describes the state files in full.
|
||||
devvm writes nothing into your project folders. It keeps the settings you edit in `~/.config/devvm` and everything it writes itself in `~/.local/share/devvm`, and it reads a few environment variables. [Your settings](#your-settings) lists the files you edit, [devvm's data folder](space.md#devvms-data-folder) lists the ones devvm writes, and [Overview](../internals/overview.md#state-files) explains how devvm keeps them.
|
||||
|
||||
## Your settings
|
||||
|
||||
`~/.config/devvm` (`$XDG_CONFIG_HOME/devvm`) holds what you edit, and it's the only folder of devvm's that you should change by hand. devvm never rewrites a file there. It reads `config.toml` and your own layers, features and CAs, it creates a new layer's files when you run `devvm layer new`, it changes single lines of `policy` when you add or remove a rule for every VM, and it writes `version` when the folder has none.
|
||||
`~/.config/devvm` (`$XDG_CONFIG_HOME/devvm`) holds what you edit, and it's the only folder of devvm's that you should change by hand. devvm never rewrites a file of yours there. It reads `config.toml` and your own layers, features and CAs, it creates a new layer's files when you run `devvm layer new`, it changes single lines of `policy` when you add or remove a rule for every VM, and it writes `version` when the folder has none and when it changes its folders to a newer layout.
|
||||
|
||||
| File | What it holds | Written by |
|
||||
| --- | --- | --- |
|
||||
@@ -16,7 +16,7 @@ devvm writes nothing into your project folders. It keeps the settings you edit i
|
||||
| `layers/` | your own [layers](customizing.md#your-own-layers) and their allowlists | `devvm layer new`, then you |
|
||||
| `features/` | your own [features](customizing.md#your-own-features) | you |
|
||||
| `ca/` | your [company's CA certificates](#a-companys-ca), which VMs and builds trust | you |
|
||||
| `version` | the folder's [layout version](troubleshooting.md#a-newer-devvm-changed-devvms-folders), which says how devvm keeps its files here | devvm, when it's missing |
|
||||
| `version` | the folder's [layout version](troubleshooting.md#a-newer-devvm-changed-devvms-folders), which says how devvm keeps its files here | devvm, when it's missing or older |
|
||||
|
||||
Edit the files in `~/.config/devvm`, and never edit the ones in `~/.local/share/devvm`. devvm writes those itself and rewrites them whole, so a change you make there can be lost, or can stop devvm from reading the file. To set a default by hand, put it in `config.toml` instead.
|
||||
|
||||
@@ -200,23 +200,13 @@ A CA in the folder can read every TLS connection a VM makes, as it can this mach
|
||||
|
||||
## devvm's state
|
||||
|
||||
`~/.local/share/devvm` (`$XDG_DATA_HOME/devvm`) holds what devvm makes and keeps for you. devvm writes everything in it, so don't edit it by hand:
|
||||
`~/.local/share/devvm` (`$XDG_DATA_HOME/devvm`) holds what devvm makes and keeps for you, and devvm writes everything in it, so don't edit it by hand. It holds the defaults that `devvm setup`, `devvm size -g`, `devvm ports -g`, `devvm network -g` and `devvm retention` save in `settings.json`, below [`config.toml`](#configtoml)'s, and a folder for each VM in `vms/`, with the VM's state, its own allowlist and its network logs. It also holds the images and the shared tools, the [run logs](troubleshooting.md#a-command-fails), the agents' history that `devvm history export` and `devvm rm` save, the [ssh config](ssh.md#ssh-access-by-name) for your VMs, and devvm's own Lima home (`lima/`), where the Lima backend's VMs and images live. [devvm's data folder](space.md#devvms-data-folder) lists each file and folder in it, with how each one is cleaned up.
|
||||
|
||||
- `settings.json`, the defaults that `devvm setup`, `devvm size -g`, `devvm ports -g`, `devvm network -g` and `devvm retention` save, below [`config.toml`](#configtoml)'s;
|
||||
- `ssh_config` and `known_hosts`, the [ssh config](ssh.md#ssh-access-by-name) for running VMs and their host keys, which devvm writes on each launch and stop;
|
||||
- `agent-keys.json`, the keys in [devvm's own SSH agent](ssh.md#devvms-own-agent) and their options, which `devvm ssh-agent add` and `rm` write;
|
||||
- on Linux hosts, your [secrets](../safety/network.md#saving-and-binding-secrets), in files under `secrets/` that only you can read (on macOS they're in the Keychain);
|
||||
- a folder for each VM in `vms/`, with the VM's state, its own allowlist and its network logs;
|
||||
- the images and their records, and the shared tools;
|
||||
- the [run logs](troubleshooting.md#a-command-fails) in `logs/runs/`;
|
||||
- the agents' history that `devvm history export` and `devvm rm` save, in `exports/`;
|
||||
- devvm's own Lima home (`lima/`), where the Lima backend's VMs and images live.
|
||||
|
||||
[What devvm keeps on this machine](space.md) lists everything in this folder, with how each is cleaned up. On Linux hosts this folder holds your secrets, so keep that in mind when you back it up.
|
||||
On Linux hosts this folder also holds your [secrets](../safety/network.md#saving-and-binding-secrets), in files under `secrets/` that only you can read, so keep that in mind when you back it up. On macOS they're in the Keychain.
|
||||
|
||||
devvm's Lima home is its own, whatever `LIMA_HOME` says, so Lima settings meant for other VMs never reach devvm's. Set `DEVVM_LIMA_HOME` to move it, for example to a sandbox or to a shorter path.
|
||||
|
||||
Only you can read devvm's files. Each time devvm runs, it makes `~/.config/devvm` and `~/.local/share/devvm` yours alone (mode 700), whatever mode they had, so nothing in them is open to others even when a file or folder inside has a wider mode. When devvm can't read one, it names the file and the line ([a file devvm can't read](troubleshooting.md#a-file-devvm-cant-read)).
|
||||
Only you can read devvm's files, in either folder, because each time devvm runs, it makes both folders yours alone ([devvm's data folder](space.md#devvms-data-folder)). When devvm can't read one of its files, it names the file and the line ([a file devvm can't read](troubleshooting.md#a-file-devvm-cant-read)).
|
||||
|
||||
## Project folders devvm refuses
|
||||
|
||||
|
||||
@@ -94,19 +94,19 @@ devvm keeps its state in `~/.local/share/devvm`, or in `$XDG_DATA_HOME/devvm` wh
|
||||
| `ssh_config`, `known_hosts` | the [ssh config](ssh.md#ssh-access-by-name) for running VMs and their host keys | devvm takes a VM out when it stops or deletes the VM |
|
||||
| `agent-keys.json` | the keys in [devvm's own SSH agent](ssh.md#devvms-own-agent) and their options | `devvm ssh-agent rm` takes a key out |
|
||||
| `secrets/` | on Linux hosts, your [secrets](../safety/network.md#saving-and-binding-secrets), one file each | `devvm secret rm` deletes one |
|
||||
| `vms/<hash>/` | one folder for each VM, which holds everything devvm keeps for it in its data folder. `<hash>` is the hash of the project folder's path that the VM's name ends with. The folder holds the VM's [state](settings.md#devvms-state) in `vm.json`, which records the VM's name, its ssh alias, its image, folder, backend and settings and the version of the devvm that made it, and the VM's own network rules in `policy`. Its backend's files are in `backend/`, the files of its proxy, link session and sandbox are in `run/`, and its logs are in `logs/` | `devvm rm` deletes the whole folder with the VM |
|
||||
| `vms/<hash>/` | one folder for each VM, which holds everything devvm keeps for it in its data folder. `<hash>` is the hash of the project folder's path that the VM's name ends with. The folder holds the VM's [state](../internals/overview.md#a-vms-state) in `vm.json`, which records the VM's name, its ssh alias, its image, folder, backend and settings and the version of the devvm that made it, and the VM's own network rules in `policy`. Its backend's files are in `backend/`, the files of its proxy, link session and sandbox are in `run/`, and its logs are in `logs/` | `devvm rm` deletes the whole folder with the VM |
|
||||
| `images/` | a folder for each image, named by its key, which holds the image's record, `record.json`; the [rebuild counters](images.md#rebuilding) in `rebuilds.json`, one for each backend, each image that base starts from and each image; and in `locks/` an empty file for each image that the devvm building it locks, and one, `rebuilds`, that a devvm changing a rebuild counter locks | `devvm gc` and `devvm images rm` delete an image's folder and its lock file with the image |
|
||||
| `tools/` | the [shared tools](images.md#shared-tools), one read-only image per tool version, each with a record beside it, `<image>.json`, which holds its checksum, the backend that built it, the C library it's built for, when it was built and, once retention finds that no VM has it, since when | `devvm gc` deletes the versions that no VM has and that aren't the current ones, `devvm gc --tool-images` also the current ones that no VM has, except those built in the last hour, and `devvm gc --tool-images --recent` those too, each with its record |
|
||||
| `mise.lock`, `mise.lock.toml`, `mise.lock.checked` | the tools lock, which holds the tools' versions and their checksums, the config it was resolved from, and when devvm last checked upstream for newer versions | devvm replaces them when it checks again |
|
||||
| `cache/` | what devvm makes again whenever it needs it: its own mise, the shared Nix cache, and in `from-digests.json` the digest that each container image a `--from` base starts from had when devvm last looked it up | you can delete it at any time, and devvm makes each part again when it's needed. An image built from a container image keeps that digest in its own record, so it stays current without the cache |
|
||||
| `cache/mise/<version>` | the mise that devvm runs on this machine to resolve the tools lock, one folder per mise version | `devvm gc` deletes the folders of older versions, which an upgrade of devvm leaves |
|
||||
| `exports/` | the agents' [history](coding-agents.md#history) that `devvm history export` and `devvm rm` save, one `.tar.gz` per export, each with a `.folder` file beside it that names its VM's folder | `devvm gc --history` deletes them, or with `--older-than 30d` those that old, and nothing else does |
|
||||
| `exports/` | the agents' [history](coding-agents.md#history) that `devvm history export` and `devvm rm` save, one `.tar.gz` per export, each with a `.folder` file beside it that names its VM's project folder | `devvm gc --history` deletes them, or with `--older-than 30d` those that old, and nothing else does |
|
||||
| `logs/runs/` | the [run logs](troubleshooting.md#a-command-fails), one per devvm run that runs a command | devvm keeps the newest 20 |
|
||||
| `logs/tools-check.log` | the output of the daily check for newer shared tools | each check replaces it |
|
||||
| `vms/<hash>/logs/` | a VM's network log, `network.jsonl`, which holds its proxy's decisions, its proxy's own output, `proxy.log`, and its link session's output, `links.log`. Before the network log or the proxy's log would grow past 10 MiB, the proxy moves it to the same name with `.1` added, replacing the older one, so each of them takes at most about 20 MiB, and `devvm network log` reads both of the network log's files | `devvm rm` deletes them with the VM's folder, `.1` files included |
|
||||
| `ca/` | the certificate authority that VMs trust for their proxy | devvm makes a new one when the old one has less than a week of its 30 days left |
|
||||
| `cache/nix-cache/` | the [shared Nix cache](toolchains.md#nix-projects): the packages that VMs with network policy and the `nix` layer downloaded from Nix's binary cache, once for all of them | the VMs' proxies and `devvm gc` delete its least recently used files while it takes more than its cap, `nix-cache.size`, which is 10 GiB when it's off, and `devvm gc --nix-cache` deletes all of it |
|
||||
| `run/` | what running VMs need that isn't one VM's or whose path must be short, such as the QEMU wrapper, the ports lock and the sockets of port forwarders and link sessions, which are named by hashes, and in `builds/` a folder for each build VM, laid out as a VM's folder is | devvm deletes a VM's sockets when it deletes the VM, and a build VM's folder when it deletes the build VM |
|
||||
| `run/` | what running VMs need that isn't one VM's or whose path must be short, such as the QEMU wrapper on Linux hosts, the claims lock, `claims.lock`, which devvm holds while it chooses a new VM's ssh alias or a VM's host ports, and the sockets of port forwarders and link sessions, which are named by hashes, and in `builds/` a folder for each build VM, laid out as a VM's folder is | devvm deletes a VM's sockets when it deletes the VM, and a build VM's folder when it deletes the build VM |
|
||||
| `agent.sock` | the socket of [devvm's own SSH agent](ssh.md#devvms-own-agent) | it takes no space |
|
||||
| `oci-build.lock` | an empty file that the devvm building a base from a container image on Lima locks, so that one such build runs at a time | it stays, and takes no space |
|
||||
| `tools.lock` | an empty file that the devvm building shared tools or updating the tools lock locks, so that one at a time writes to `tools/` | it stays, and takes no space |
|
||||
@@ -158,7 +158,7 @@ These warnings never make doctor fail, and `devvm doctor --json` lists them in `
|
||||
|
||||
## Your settings
|
||||
|
||||
`~/.config/devvm` holds what you edit: `config.toml`, your network policy rules, your own layers and features, and your company's CA certificates. devvm also writes the folder's [layout version](troubleshooting.md#a-newer-devvm-changed-devvms-folders) into `version` there when the file is missing. [Your settings](settings.md#your-settings) lists each file. devvm never deletes any of them.
|
||||
`~/.config/devvm` holds what you edit: `config.toml`, your network policy rules, your own layers and features, and your company's CA certificates. devvm also writes the folder's [layout version](troubleshooting.md#a-newer-devvm-changed-devvms-folders) into `version` there when the file is missing or older. [Your settings](settings.md#your-settings) lists each file. devvm never deletes any of them.
|
||||
|
||||
## Lima
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ On Lima, base starts from a pinned, dated release of Ubuntu's cloud image. Ubunt
|
||||
|
||||
## A file devvm can't read
|
||||
|
||||
When devvm can't read one of its settings or state files, it names the file, and the line when the problem is on one. Fix the line or delete the file. [Settings and files](settings.md) lists what each file holds.
|
||||
When devvm can't read one of its settings or state files, it names the file, and the line when the problem is on one. Fix the line or delete the file. [Your settings](settings.md#your-settings) lists what each file you edit holds, and [devvm's data folder](space.md#devvms-data-folder) what each file devvm writes holds.
|
||||
|
||||
## A newer devvm changed devvm's folders
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ Flags take one dash or two.
|
||||
| `-upstream-cas` | a file of CA certificates (PEM) the proxy's own TLS connections trust besides the system's |
|
||||
| `-upstream` | a file (mode 600) of the host's `HTTPS_PROXY=`, `HTTP_PROXY=` and `NO_PROXY=` lines: allowed requests go through that company proxy, which gets host names, and its credentials only in its own `Proxy-Authorization` (in a file because a process's arguments are visible to other users); logs name it by `host:port` |
|
||||
| `-auth-file` | a file (mode 600) with the VM's key: requests need it as the proxy password, user `devvm` (in a file because a process's arguments are visible to other users) |
|
||||
| `-nix-cache` | the shared Nix cache's folder (`~/.local/share/devvm/nix-cache`), made mode 700 if it isn't there: serve `http://devvm.proxy/nix/` from it; devvm passes it for VMs whose image has the nix layer |
|
||||
| `-nix-cache` | the shared Nix cache's folder (`~/.local/share/devvm/cache/nix-cache`), made mode 700 if it isn't there: serve `http://devvm.proxy/nix/` from it; devvm passes it for VMs whose image has the nix layer |
|
||||
| `-nix-cache-max` | with `-nix-cache`: the cache's cap, in bytes (devvm passes `nix-cache.size`, 10 GiB when it's off) |
|
||||
| `-links` | the VM's links' list, which `devvm _links` writes (`~/.local/share/devvm/vms/<hash>/run/links.json`): reach each link through its socket, before any rule; a missing list has no links |
|
||||
| `-link-sockets` | with `-links`: the folder of the links' sockets, devvm's run folder (`~/.local/share/devvm/run`); without it, no link is reached |
|
||||
|
||||
Reference in new issue
Block a user