on master help sign in

A Nix flake that builds an OCI image for running with Apple's container CLI on macOS.

git clone ssh://git.iko.soy/nix-container

nix-container

A Nix flake that builds an OCI image (via nix2container) for running with Apple's container CLI on macOS.

It's a plain, single-process image — no NixOS, no systemd — defined in flake.nix. c start drops you into a herdr session whose panes use your host login shell (detected and bundled by c init). You choose what else it ships via a per-project container.nix.

Prerequisites

Packages

init builds the image from a container.nix in the current directory — an attrset with a packages function ({ pkgs, nur } returning the package list; nur is NUR, for packages outside nixpkgs) and an optional mounts list. It is required; there is no default.

# ./container.nix
{
  packages = { pkgs, nur }: with pkgs; [
    git
    go
    nur.repos.charmbracelet.crush
  ];
  # Extra "host:container" bind mounts, on top of $PWD → /workspace. A leading
  # ~/ in the host path expands to $HOME. Optional.
  mounts = [
    "~/data:/data"
  ];
}

Your host login shell (detected by c init, bash fallback), coreutils, herdr (the session c start launches), Nix itself (with CA certs and nix-command/flakes enabled, single-user), and the ncurses terminfo database are always included — no need to list them.

Point at a different file with -c/--config:

nix run github:ilyakooo0/nix-container -- init --config envs/ci.nix

Quick start

No clone needed — nix run drives everything. Run it from a project directory that holds a container.nix; the container is named after that directory.

# build the image, load it, and create the container (named after $PWD):
nix run github:ilyakooo0/nix-container -- init

# start it and attach — drops you into a herdr session:
nix run github:ilyakooo0/nix-container -- start

Working from a checkout, ./c init / ./c start are equivalent — and c can be symlinked onto your $PATH and run from any project.

Re-running after a rebuild

Just run init again — it reloads the image and replaces the existing container (removing the old one first), so there's nothing to clean up:

nix run github:ilyakooo0/nix-container -- init

Customize further

Fork or clone to change what isn't per-project — config.cmd/env or the image name — in flake.nix. The flake also exposes build helpers:

The flake uses flake-utils over {aarch64,x86_64}-{darwin,linux}; the host system maps to the matching Linux target automatically (an Intel Mac builds an amd64 image), so there's nothing to change per-arch.

How it works

License

MIT.