/cc-skills-nix:nix-oci-imagefrom cc-skills-nix
Building and publishing OCI/Docker container images from Nix — dockerTools.buildLayeredImage over a buildEnv (app + cacert), non-root numeric User for Kubernetes runAsNonRoot, version-derived tags, and pushing with skopeo (docker-archive → OCI) to registries like Zot that reject `docker push`. Apply when adding a container image output to a flake; when writing packages/docker/*.nix or dockerTools code; when a Nix-built image fails TLS (missing CA bundle), lacks PATH, or runs as root; when pushing ./result to a private/homelab registry fails; when wiring an image build+push recipe into a justfile or CI. Do NOT use for Dockerfile-based builds, docker-compose, or Kubernetes manifest authoring.
Ships in cc-skills-nix. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Reference implementation: aldoborrero/reolink-exporter (nix/packages/docker/). The image is just another blueprint package: nix build .#docker produces a docker-archive tarball at ./result; skopeo publishes it. No Dockerfile, no daemon at build time.
# nix/packages/docker/default.nix — blueprint shim
{ pkgs, perSystem }:
pkgs.callPackage ./package.nix { myapp = perSystem.self.myapp; }
# nix/packages/docker/package.nix
{
dockerTools,
buildEnv,
myapp,
cacert,
}:
let
env = buildEnv {
name = "myapp-env";
paths = [
myapp
cacert # TLS trust root — without it every HTTPS call fails
];
pathsToLink = [ "/bin" "/etc" "/lib" "/share" ];
};
in
# `docker run -e MYAPP_OPT=... -p 8000:8000 myapp:0.2.0`
dockerTools.buildLayeredImage {
name = "myapp";
tag = myapp.version; # tag follows the package version, never "latest"
contents = [ env ];
config = {
Entrypoint = [ "/bin/myapp" ];
# Numeric so Kubernetes `runAsNonRoot` is satisfied without an /etc/passwd entry.
User = "10001:10001";
Env = [
"PATH=/bin"
"SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt"
"PYTHONUNBUFFERED=1" # language-appropriate runtime flags
];
ExposedPorts."8000/tcp" = { };
};
}
Why each piece:
buildEnv: merges app + cacert into one store path with a predictable /bin, /etc/ssl layout; pathsToLink controls what gets linked.cacert + SSL_CERT_FILE: there is no distro base layer, so no CA bundle exists unless you add one — missing it surfaces only at runtime, as certificate errors.buildLayeredImage: store-path-per-layer, so app-only changes reuse dependency layers on push/pull. Output: a compressed docker-archive tarball at ./result.PATH=/bin: no shell profile sets it for you.The image inherits blueprint's package plumbing: appears as packages.<sys>.docker and builds under checks.<sys>.pkgs-docker in nix flake check.
# justfile
registry := env_var_or_default("REGISTRY", "registry.example.com")
image := "myapp"
image:
nix build .#docker --log-format bar-with-logs
# Push the built image. Zot rejects `docker push`, it needs OCI via skopeo.
push tag: image
skopeo copy \
docker-archive:./result \
docker://{{ registry }}/{{ image }}:{{ tag }} \
--format oci
docker-archive:./result reads the tarball directly — no docker load, no daemon. --format oci converts the manifest to OCI, which registries like Zot require (docker push sends Docker-format manifests and gets rejected). skopeo must be in the devshell. Credentials: skopeo login <registry> beforehand, or --dest-creds.
contents/buildEnv, or SSL_CERT_FILE unset (the bundle sits at /etc/ssl/certs/ca-bundle.crt via cacert's /etc link).exec: "myapp": not found → Entrypoint must be the absolute /bin/... path, and the binary's package must be in the buildEnv paths with /bin in pathsToLink.docker push or omitting --format oci against an OCI-only registry../result is not an image → nix build .#docker was skipped or built a different attr; push recipes should depend on image (as above) so the tarball is fresh.runAsNonRoot → User unset or non-numeric.pkgs.bash/coreutils in contents "for debugging" drags in a userland; the reference image ships only app + certs. Debug with docker run --entrypoint on a temporary variant instead.packages/docker/ directory is invisible until git add.Daemonless inspection of the built artifact (skopeo inspect --config), the buildLayeredImage vs streamLayeredImage trade-off, tagging discipline and CI notes: references/inspect-and-variants.md.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub aldoborrero/skills --plugin cc-skills-nix6 skills in this plugin
/nix-blueprintnumtide/blueprint — Nix flake framework that maps a fixed directory structure to flake outputs with zero glue code. Apply when a repo's flake.nix calls `inputs.blueprint { ... }`; when deciding where a package, devshell, host, module, check or template file must live; when a package/devshell/host is missing from `nix flake show` or `nix build` says the attribute doesn't exist; when adding the `prefix` option; when writing packages/<name>/default.nix, devshell.nix or modules/<class>/<name>.nix. Do NOT use for generic Nix flakes without blueprint (hand-written outputs, flake-parts, flake-utils), for nixpkgs contributions, or for NixOS module semantics unrelated to file placement. Prefer nix-project-scaffold for creating a NEW project, nix-treefmt-formatter for formatter.nix internals, and nixos-host-provisioning for adding hosts with disko/facter./nixos-host-provisioningAdding or provisioning a NixOS host in a blueprint-based config flake — hosts/<name>/default.nix escape hatch wiring input modules (disko, sops-nix, nixos-hardware, nixos-facter), declarative partitioning with disko (GPT ESP+root, ext4 or btrfs subvolumes), hardware detection via nixos-facter instead of hardware-configuration.nix, and manual home-manager user wiring. Apply when adding a new machine to a NixOS flake; when writing or editing hosts/<name>/{default.nix,configuration.nix,disko.nix}; when generating or overriding facter.json; when a host needs modules from flake inputs; when home-manager users don't get created on a host. Do NOT use for non-NixOS projects, for nix-darwin-only hosts, or for flakes not using blueprint's hosts/ convention./nix-project-scaffoldHouse-style scaffold for new Nix-flake projects (Go, Python, or other languages) — numtide/blueprint with prefix="nix", direnv .envrc, numtide devshell with in-repo toolchain caches, treefmt formatter, two-file package (default.nix shim + nixpkgs-style package.nix with src=flake), justfile facade, and GitHub Actions CI pinned to flake.lock's nixpkgs. Apply when creating a new project or repository that should use Nix; when adding Nix/flake tooling to an existing Go or Python repo; when asked for a devshell + formatter + CI setup 'like my other repos'; when wiring justfile targets to nix commands; when setting up direnv for a flake. Do NOT use for repos that already follow a different flake convention (flake-parts, devenv, hand-rolled outputs), for NixOS system configuration repos, or for nixpkgs contributions./nix-sops-secretsSecrets in NixOS flakes with sops-nix + age (+ age-plugin-yubikey) — .sops.yaml recipients and creation_rules, a centralized sops.secrets declaration module, and runtime consumption from /run/secrets. Apply when adding, editing or rotating an encrypted secret; when adding a recipient (new host key or YubiKey) or a new host that must decrypt; when a service or user can't read a secret (permission denied, file missing, empty env var); when wiring an API key or password into a NixOS service, home-manager tool or wrapper script; when configuring .sops.yaml, sops.defaultSopsFile or the age host key. Do NOT use for agenix or vault-based setups, for git-crypt, or for generic sops usage outside Nix./nix-treefmt-formattertreefmt-nix formatter for Nix flakes — `formatter.nix` via `treefmt-nix.lib.evalModule` (build.wrapper + build.check), lint→format ordering with priorities (deadnix→nixfmt, shellcheck→shfmt, ruff-check→ruff-format), and the format check wired into `nix flake check` via passthru.tests. Apply when writing or editing formatter.nix / treefmt config in a flake; when adding a language formatter (Go, Python, shell, YAML, TOML, Markdown, just); when `nix fmt` misbehaves, formats vendored files, or skips files (excludes, on-unmatched, default excludes); when CI passes `nix flake check` but formatting is actually broken (check never ran); when deadnix deletes wanted lambda args. Do NOT use for non-treefmt formatting setups, editor/IDE format-on-save config, or choosing code style rules of a language.