- Nix 77%
- Shell 18.2%
- Lua 2.5%
- Just 1.1%
- FLUX 0.6%
- Other 0.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
Some checks failed
nix-ci / pr-diff-fennel (push) Has been skipped
nix-ci / pr-diff-fly (push) Has been skipped
nix-ci / pr-diff-leek (push) Has been skipped
nix-ci / pr-diff-paprika (push) Has been skipped
nix-ci / pr-diff-smgt-dev (push) Has been skipped
nix-ci / pr-diff-termite (push) Has been skipped
nix-ci / pr-diff-yam (push) Has been skipped
nix-ci / build-fennel (push) Successful in 12s
nix-ci / build-fly (push) Successful in 29s
nix-ci / build-leek (push) Successful in 14s
nix-ci / build-paprika (push) Successful in 13s
nix-ci / build-smgt-dev (push) Successful in 13s
nix-ci / build-termite (push) Failing after 3s
nix-ci / build-yam (push) Failing after 5s
|
||
| .forgejo/workflows | ||
| bin | ||
| config/terraform | ||
| docs | ||
| home | ||
| lib | ||
| machines | ||
| microvms | ||
| modules | ||
| pkgs | ||
| scripts | ||
| tests | ||
| .envrc | ||
| .gitignore | ||
| AGENTS.md | ||
| flake.lock | ||
| flake.nix | ||
| iso.nix | ||
| justfile | ||
| proxmox.md | ||
| README.md | ||
Nix
Home-manager standalone
home-manager build --flake .#[system name]
home-manager switch --flake .#[system name]
NixOS
Installation on hardware
Build ISO
# Inside the nix/ directory
export NIX_PATH=nixos-config=$PWD/iso.nix:nixpkgs=channel:nixos-25.11
nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage
This will result in a ISO with settings from the iso.nix file. After the
build is done you can write the ISO image to a USB stick or similar. The build
command will output the Nix store path and it will also be available in
./result/iso/.
Boot and provision
Boot the ISO on the new system, find the host name and provision the device using nixos-anywhere.
First create a configuration for the system in machines/[name]/default.nix.
Then add the system to flake.nix. After that is done you can provision the device.
We also generate the hardware configuration for the system.
# Example with disk encryption and sops
# --disk-encryption-keys [target host key location] [current host key location]
nix run github:nix-community/nixos-anywhere -- \
--flake .#[system name]\
--disk-encryption-keys /tmp/secret.key <(cat /secret/password) \
--generate-hardware-config nixos-generate-config machines/[system name]/hardware-configuration.nix \
--copy-host-keys \
--target-host simon@[ip address]
# Example without disk encryption
nix run github:nix-community/nixos-anywhere -- \
--flake .#[system name]\
--generate-hardware-config nixos-generate-config machines/[system name]/hardware-configuration.nix \
--target-host simon@[ip address]
Reboot the system.
Making changes to a system
Update a remote system.
nix run nixpkgs#nixos-rebuild -- \
--target-host simon@[hostname] \
--sudo \
switch \
--flake .#[system name]
Update a local system
sudo nixos-rebuild switch --flake .#[systemname]
Ephemeral development VPS
The dev-vps profile is a generic NixOS configuration for short-lived VPSes
created by another tool and converted from Ubuntu with nixos-anywhere. It uses
an unencrypted full-disk disko layout on /dev/nvme0n1 and enables Tailscale
without joining the tailnet automatically.
Provision an AWS VPS with EC2 boot defaults:
nix run github:nix-community/nixos-anywhere -- \
--flake .#dev-vps-aws \
--target-host root@[ip address]
For non-AWS providers that also expose the root disk as /dev/nvme0n1, use
.#dev-vps. The configured root partition uses 100% of the remaining disk after
the EFI partition.
After the install, join Tailscale manually with a one-off, tagged, non-ephemeral auth key. Replace the hostname with a useful per-instance name if you want it to show up that way in Tailscale.
ssh simon@[ip address]
sudo tailscale up \
--auth-key="$TS_AUTHKEY" \
--advertise-tags=tag:dev-vps \
--hostname=smgt-1-2-3-4
Configure Tailscale ACLs so trusted devices can reach tag:dev-vps on TCP port
22, without granting tag:dev-vps outbound access to other tailnet services.
Agent microVM on yam
yam includes a QEMU/KVM guest named agents (4 vCPUs, 8 GiB RAM) that starts
automatically at boot.
OpenCode2 is installed/configured on yam using smgtllm and installed in the
guest through Home Manager. The guest runs the server; the host runs the client
and editor. Only the two yam user keys from lib/yam-ssh-keys.nix can log in.
Before deploying, check id -u simon on yam: this configuration pins simon's UID
to 1000. If the existing UID differs, adjust it in machines/yam/agents.nix
before switching; do not change an existing account's UID without migrating files.
Also check ip route for conflicts with the dedicated 10.99.0.0/30 subnet.
Build/evaluate without starting the guest:
nix develop -c nix eval --impure --expr 'import ./tests/agents.nix (builtins.getFlake (toString ./.))'
nix develop -c nix build --no-link .#nixosConfigurations.yam.config.microvm.vms.agents.config.config.system.build.toplevel
nix develop -c nix eval --raw .#nixosConfigurations.yam.config.system.build.toplevel.drvPath
Deploy yam through the normal NixOS rebuild workflow. Then, on yam:
sudo systemctl start microvm@agents
ssh agents
The dedicated TAP link uses 10.99.0.1 on yam and 10.99.0.2 in the guest.
ssh agents is an alias for ssh simon@10.99.0.2, without SSH-agent forwarding.
Outbound traffic is NATed through yam's current uplink; no SSH or API port
forwarding is needed. The guest firewall accepts SSH/API traffic only from
10.99.0.1, and the API additionally requires the generated password.
From a project directory on yam:
cd ~/code/my-project
OPENCODE_PASSWORD="$(cat ~/microvm/agents/secrets/password)" \
opencode2 --server http://10.99.0.2:43827
Use the remote client to sign in to model providers. Authentication and sessions are written by the guest server to host-backed storage; recreating the guest does not require signing in again. Existing host-server sessions/authentication are not automatically imported. Do not point another server at this database.
Storage and isolation
| Host path | Guest use |
|---|---|
~/code |
Same path, read/write; includes untracked files and project secrets |
~/.config/opencode |
Same path, read-only; managed by smgtllm on yam |
/nix/store |
Read-only lower layer of the guest store |
~/microvm/agents/opencode |
~/.local/share/opencode: sessions, provider auth, logs |
~/microvm/agents/ssh |
Persistent SSH host keys, root-owned |
~/microvm/agents/secrets |
Generated server password, mounted read-only |
~/microvm/agents/nix |
Read-only host store validity snapshot, refreshed at VM start |
~/microvm/agents/backups |
Not mounted in the guest |
The guest has its own Nix daemon and database, not the host daemon socket. Its
32 GiB sparse root disk at /var/lib/microvms/agents/root.img preserves the guest
home, cache, Nix database and writable store overlay across starts. No disk is
automatically reset. OpenCode data and SSH host keys remain in the separate
host-backed directories above, so they also survive replacing the root disk.
An older ephemeral-store.img, if present, is left untouched; it is not a root
disk and must not be renamed to root.img.
The guest can read host store contents but cannot write them. Automatic host GC is skipped while this VM runs; do not run manual host GC while it is running. Paths added to the host store after the validity snapshot may require restarting the VM for Nix to recognize them. New dependencies can be downloaded/built inside the guest instead. At boot the guest verifies store registrations and repairs dependencies removed by host GC while it was stopped. Repair may require Internet access, take time, or block Nix/OpenCode startup if a dependency cannot be recovered or the disk is full. Config/skills referencing other host paths need explicit shares; private flake inputs will need guest-specific credentials. No host SSH, cloud or GPG credentials are forwarded.
Internet access is enabled, including reachability of host/LAN services through
yam; this is not an outbound network-isolation policy. Public DNS resolvers
(1.1.1.1 and 9.9.9.9) are used; host VPN/private DNS is not inherited. Agents
can modify or delete shared code and session data and disclose anything readable, including
provider credentials and store contents. They cannot access the backup directory
through these mounts. Config is read-only: perform changes on yam, and plugins
that insist on writing config files may need additional targeted storage.
Stop and back up
sudo systemctl stop microvm@agents
sudo tar -czf "$HOME/microvm/agents/backups/$(date -u +%Y%m%dT%H%M%SZ).tar.gz" \
-C "$HOME/microvm/agents" opencode ssh secrets
Stop the VM before copying its database so SQLite's database and WAL files are
consistent. Backups contain credentials: keep them private and copy them to a
separate disk/off-host backup. No automatic backup schedule is configured. Restore
only with the VM stopped, preserving ownership; first back up the current data.
The backup command covers sessions, credentials and SSH identity, not the root
disk. To preserve the entire guest as well, also back up root.img while stopped.
Do not delete ~/microvm/agents when replacing the guest root disk.
Runtime checks on yam
- Compare
idand file ownership inside/outside the guest; edit a throwaway file under~/codeon each side and check that the other side sees it. - Run
nix developin a project with dependencies already present on yam. Confirm reuse, then try a dependency absent from yam and confirm it installs in the guest without appearing in the host store. - Check
findmnt /nix/.ro-storeand try creating a file there: it must fail.findmnt ~/.config/opencodemust also be read-only. The guest's/nix/var/nix/daemon-socket/socketbelongs to its own daemon, not yam's. - Create a session/sign in through the remote client, then stop/start
microvm@agents. Reconnect: sessions, provider login and SSH host fingerprint must survive, along with guest-only Nix dependencies and files in the guest home. Also test recovery after host GC removes a dependency used by a guest-built output: the guest should repair that dependency rather than lose its output. - Check DNS and Internet connectivity in the guest. Verify the server requires the generated password and that a different machine cannot reach the guest's SSH/API services, even if it has a route to the private subnet through yam.
- Make a stopped-VM backup and test a restore before relying on it for important sessions. Persistence is not protection against disk failure or corruption.
SOPS
Create age identity for your system:
mkdir -p $HOME/.config/sops/age/
read -s SSH_TO_AGE_PASSPHRASE; export SSH_TO_AGE_PASSPHRASE
nix run nixpkgs#ssh-to-age -- \
-private-key \
-i $HOME/.ssh/id_ed25519 \
-o $HOME/.config/sops/age/keys.txt
Display system age recipient (public key) for you system:
age-keygen -y $HOME/.config/sops/age/keys.txt
Get target host age recipient:
cat /etc/ssh/ssh_host_ed25519_key.pub | nix run nixpkgs#ssh-to-age
Configure sops:
nvim .sops.yaml
Edit secret file:
nix run nixpkgs#sops secrets/example.yaml
Investigate
Housekeeping
Remove old generations
When you make changes to your system, Nix creates a new system Generation. All of the changes to the system since the previous generation are stored there. Old generations can add up and will not be removed automatically by default. You can see your generations with:
$ nix-env --list-generations
To keep just your current generation and the two older than it:
$ nix-env --delete-generations +3
To remove all but your current generation:
$ nix-env --delete-generations old
Generation trimmer script
For a smart interactive script which can handle all the normally available profile types across NixOS and be more conservative and safe than the built-in Nix generations deletion commands, see NixOS Generations Trimmer.
Garbage collection
As you work with your system (installs, uninstalls, upgrades), files in the Nix store are not automatically removed, even when no longer needed. Nix instead has a garbage collector which must be run periodically (you could set up, e.g., a cron to do this).
$ nix-collect-garbage
This is safe so long as everything you need is listed in an existing generation or garbage collector root (gcroot).
If you are sure you only need your current generation, this will delete all old generations and then do garbage collection:
$ nix-collect-garbage -d
On NixOS, you can enable a service to automatically do daily garbage collection:
/etc/nixos/configuration.nix
nix.gc.automatic = true;
FAQ
HELP cache is down and I can't remove it!
If a substitute is down and you can't remove it from your configuration since it
uses the substitute you can run your build with --option build-use-substitutes false
nix run nixpkgs#nixos-rebuild -- \
--sudo \
switch \
--option build-use-substitutes false \
--flake .#yam