Skip to content

feat(nix): Add a flake that builds brig with its Linux runtime - #38

Open
pmoust wants to merge 2 commits into
mainfrom
nix-flake
Open

pmoust wants to merge 2 commits into
mainfrom
nix-flake

Conversation

@pmoust

@pmoust pmoust commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

A host with nix had no route to a working sandbox. The nixpkgs brig package (NixOS/nixpkgs#581828) is the CLI alone, and this bundle wants a tarball under /var/lib/brig and the systemd units it writes itself.

The flake builds brig, urunc from the commit pins.env records, and the guest assets, and wraps them with the same environment and config build-bundle.sh generates. containerd, nerdctl and the CNI plugins come from nixpkgs. nix build .#brig-runtime plus one systemd unit boots a sandbox. nix/README.md has the steps.

Three choices are not obvious from the files, and each has a comment:

  • urunc is pinned to feat/linux-hvi-v050 at 3c00b69, what rc21's pins.env records, not the f6d54d6 the README names. brig asks urunc for the hvi monitor on Linux, and only that branch knows it.
  • The shim's default OCI runtime is sed'd in the vendored go-runc, as the Makefile does, because go-runc v1.0.0 declares it as a const.
  • virtiofsd and cloud-hypervisor come from the bundle tarball, not nixpkgs. urunc pivots into a monitor rootfs before it spawns them, and the nixpkgs builds are dynamically linked.

Tested on Debian 12 on GCP with nested virtualization and single-user nix: brig doctor all ok, the ubuntu profile boots, DNS and apt work in the guest, a file written under /work appears on the host, the unit comes back after a reboot. Not tested: aarch64, NixOS.

A NixOS module (nixosModules.default, services.brig.enable) and a NixOS VM test (nix flake check) are on the branch too. The VM test passed on the same Debian host: unit up, socket present, brig doctor all ok inside the NixOS machine. The test machine has no network, so it boots no sandbox.

A host with nix had no route to a working sandbox: the nixpkgs brig
package is the CLI alone, and the bundle wants a tarball under
/var/lib/brig and systemd units it writes itself. The flake builds brig,
urunc from the pinned commit and the guest assets, and wraps them with
the same environment and config the bundle generates, so `nix build`
plus one systemd unit boots a sandbox.

Three choices are not obvious from the files. urunc is pinned to the
commit pins.env records, not the one the README names, because brig asks
for the hvi monitor on Linux and only that branch knows it. The shim's
default OCI runtime is sed'd in the vendored go-runc, as the upstream
Makefile does, because go-runc v1.0.0 makes it a const. virtiofsd and
cloud-hypervisor come from the bundle tarball rather than nixpkgs,
because urunc pivots into a monitor rootfs before it spawns them and the
nixpkgs builds are dynamically linked.

Verified on Debian 12 with nested virtualization: doctor green, the
ubuntu profile boots, guest DNS and apt work, the unit survives a reboot.

Signed-off-by: Panagiotis Moustafellos <pmoust@nofire.ai>
@pmoust
pmoust marked this pull request as ready for review November 1, 2026 17:40
On NixOS the Debian recipe, copying the unit from the store by hand,
is the wrong shape. The module declares the unit, the kernel modules
and the state directories, and puts brig on PATH, so services.brig.enable
is the whole install.

The VM test boots a NixOS machine from the module alone and checks the
unit, the socket, /dev/vhost-vsock and brig doctor. The test machine has
no network, so it pulls no image and boots no sandbox; a real boot is
still a manual check on a host with KVM. Passed on a Debian host with
nested virtualization.

Signed-off-by: Panagiotis Moustafellos <pmoust@nofire.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant