on master help sign in
4 files changed+212−225
since splitsnapshots
unifiedsplit
.gitignore−1 README.md+73−80 c+57−25 flake.nix+82−119
.gitignore−1
@@ -1,2 +1 @@
1−image.tar.gz
21result
README.md+73−80
@@ -5,10 +5,10 @@ A Nix flake that builds an **OCI image** (via
55Apple's [`container`](https://github.com/apple/container) CLI on macOS.
66
77It's a plain, single-process image — no NixOS, no systemd — defined in
8−[`flake.nix`](./flake.nix). The default command is `fish` (with a configured
9−prompt), and the image ships a handful of dev/LLM tools: `git`, `jujutsu`,
10−`ripgrep`, `fd`, `jq`, `nodejs`, `python3`, a Rust + C toolchain,
11−`charmbracelet.crush`, `openssh`, and more.
8+[`flake.nix`](./flake.nix). `c start` drops you into a
9+[`herdr`](https://herdr.dev) session whose panes use your host login shell
10+(detected and bundled by `c init`). You choose what else it ships via a
11+per-project `container.nix`.
1212
1313## Prerequisites
1414
@@ -16,36 +16,72 @@ prompt), and the image ships a handful of dev/LLM tools: `git`, `jujutsu`,
1616- Apple's [`container`](https://github.com/apple/container) CLI installed, with
1717 services started: `container system start` (first run downloads a Linux
1818 kernel).
19−- A **Linux builder** — the image *contents* are Linux binaries, which can't be
20− built on macOS. Use a [remote builder][builders] or, on Apple Silicon, the
21− `nix-darwin` `linux-builder`. With one configured, `nix` dispatches Linux
22− builds to it automatically (most packages also come prebuilt from the binary
23− cache, so the builder is only needed for the uncached bits).
19+- A **Linux builder** *only if you use packages that aren't in the binary
20+ cache*. The image is assembled entirely on macOS — the root filesystem is just
21+ a host-built symlink tree over the **substituted** Linux store paths — so a
22+ fully-cached package set needs no builder. Compiling a Linux package that
23+ `cache.nixos.org` doesn't have does, though: use a [remote builder][builders]
24+ or, on Apple Silicon, the `nix-darwin` `linux-builder`.
2425
2526[builders]: https://nix.dev/manual/nix/latest/advanced-topics/distributed-builds
2627
28+## Packages
29+
30+`init` builds the image from a **`container.nix`** in the current directory — an
31+attrset with a `packages` function (`{ pkgs, nur }` returning the package list;
32+`nur` is [NUR](https://github.com/nix-community/NUR), for packages outside
33+nixpkgs) and an optional `mounts` list. It is **required**; there is no default.
34+
35+```nix
36+# ./container.nix
37+{
38+ packages = { pkgs, nur }: with pkgs; [
39+ git
40+ go
41+ nur.repos.charmbracelet.crush
42+ ];
43+ # Extra "host:container" bind mounts, on top of $PWD → /workspace. A leading
44+ # ~/ in the host path expands to $HOME. Optional.
45+ mounts = [
46+ "~/data:/data"
47+ ];
48+}
49+```
50+
51+Your **host login shell** (detected by `c init`, bash fallback), **coreutils**,
52+[**herdr**](https://herdr.dev) (the session `c start` launches), **Nix** itself
53+(with CA certs and `nix-command`/`flakes` enabled, single-user), and the ncurses
54+**terminfo** database are always included — no need to list them.
55+
56+Point at a different file with `-c`/`--config`:
57+
58+```sh
59+nix run github:ilyakooo0/nix-container -- init --config envs/ci.nix
60+```
61+
2762## Quick start
2863
29−No clone needed — `nix run` drives everything. Run it from a project directory;
30−the container is named after that directory.
64+No clone needed — `nix run` drives everything. Run it from a project directory
65+that holds a `container.nix`; the container is named after that directory.
3166
3267```sh
3368# build the image, load it, and create the container (named after $PWD):
3469nix run github:ilyakooo0/nix-container -- init
3570
36−# start it and attach — drops you into fish:
71+# start it and attach — drops you into a herdr session:
3772nix run github:ilyakooo0/nix-container -- start
3873```
3974
4075- `init` builds the OCI archive in a temp dir, loads it into `container`,
41− deletes the temp file, then runs `container create --name <dir> --ssh -it`.
76+ deletes the temp file, then (re)creates the container. It mounts the current
77+ directory at `/workspace` (the container's working directory).
4278- `--ssh` forwards your host SSH agent socket into the container (so `git` over
4379 SSH works with your keys).
44−- Mounts can only be set at creation, so pass them to `init` (forwarded to
45− `container create`):
80+- Add more mounts persistently via `mounts` in `container.nix` (above), or
81+ ad-hoc by passing them through to `create` (mounts can only be set at creation):
4682
4783 ```sh
48− nix run github:ilyakooo0/nix-container -- init -v $PWD:/work
84+ nix run github:ilyakooo0/nix-container -- init -v $HOME/data:/data
4985 ```
5086
5187Working from a checkout, [`./c init`](./c) / `./c start` are equivalent — and
@@ -53,75 +89,29 @@ Working from a checkout, [`./c init`](./c) / `./c start` are equivalent — and
5389
5490## Re-running after a rebuild
5591
56−`container` keeps the loaded image and the created container, so remove them
57−before re-initialising:
92+Just run `init` again — it reloads the image and replaces the existing container
93+(removing the old one first), so there's nothing to clean up:
5894
5995```sh
60−container rm <dir> # the container is named after the directory
61−container image rm nix-container:latest
6296nix run github:ilyakooo0/nix-container -- init
6397```
6498
65−## Manual steps
66−
67−`init` is just a wrapper; you can run the pieces yourself for more control. The
68−`image` app is nix2container's skopeo wrapper (`skopeo copy nix:<image> "$@"`) —
69−it takes the ref name from the destination, so spell out the tag:
70−
71−```sh
72−# 1. build a tagged OCI archive
73−nix run github:ilyakooo0/nix-container#image -- oci-archive:image.tar:nix-container:latest
74−
75−# 2. load, create, start
76−container image load --input image.tar
77−container create --name myctr --ssh -it nix-container:latest
78−container start -ai myctr
79−```
80−
81−## Other image destinations
82−
83−The same `image` app can copy anywhere skopeo can:
84−
85−```sh
86−nix run github:ilyakooo0/nix-container#image -- docker://ghcr.io/me/img:latest # push to a registry
87−nix run github:ilyakooo0/nix-container#image -- docker-daemon:nix-container:latest # local Docker daemon
88−```
89−
90−## Configuring packages
91−
92−The image ships a curated tool set (`defaultPackages` in
93−[`flake.nix`](./flake.nix)). To use your own set **without forking**, drop a
94−`container.nix` in the directory you run `init` from — a `{ pkgs, nur }`
95−function returning the package list (`nur` is [NUR](https://github.com/nix-community/NUR),
96−for packages outside nixpkgs):
97−
98−```nix
99−# ./container.nix
100−{ pkgs, nur }: with pkgs; [
101− fish # the default cmd is /bin/fish, so include it (or change config.cmd)
102− coreutils
103− go
104− terraform
105− nur.repos.charmbracelet.crush
106−]
107−```
108−
109−`nix run github:ilyakooo0/nix-container -- init` (and `./c init`) then builds an
110−image with **exactly** those packages, replacing the default set. It's a full
111−replacement, so include the basics you need.
99+## Customize further
112100
113−Point at a different file with `-c`/`--config`:
101+Fork or clone to change what isn't per-project — `config.cmd`/`env` or the image
102+name — in [`flake.nix`](./flake.nix). The flake also exposes build helpers:
114103
115−```sh
116−nix run github:ilyakooo0/nix-container -- init --config envs/ci.nix
117−```
104+- `lib.<system>.copyWith` → a skopeo copy app for a `{ pkgs, nur }: [ ... ]`
105+ function, for building/pushing the image anywhere skopeo can write (e.g. a
106+ registry):
118107
119−## Customize further
120−
121−Fork or clone to change what isn't per-project — the default package set,
122−`config.cmd`/`env`, or the image name — by editing `defaultPackages` / `mkImage`
123−in [`flake.nix`](./flake.nix). `mkImage` and `lib.<system>.copyWith` are exposed
124−for building images from your own flake.
108+ ```sh
109+ drv=$(nix build --no-link --print-out-paths --impure --expr \
110+ '(builtins.getFlake "github:ilyakooo0/nix-container").lib.${builtins.currentSystem}.copyWith (import ./container.nix).packages')
111+ $drv/bin/copy-to docker://ghcr.io/me/img:latest
112+ ```
113+- `lib.<system>.mkImage <name> <shell>` → the underlying OCI image (`copyWith`
114+ defaults these to `nix-container` / `bash`).
125115
126116The flake uses `flake-utils` over `{aarch64,x86_64}-{darwin,linux}`; the host
127117system maps to the matching Linux target automatically (an Intel Mac builds an
@@ -129,9 +119,12 @@ system maps to the matching Linux target automatically (an Intel Mac builds an
129119
130120## How it works
131121
132−- **Contents** (`copyToRoot`) are built from `pkgsLinux` → the Linux builder.
133−- **Assembly** (`nix2container` + the `skopeo` copy) runs on your Mac, so a
134− single `nix run` produces a loadable archive.
122+- **Contents** are Linux store paths — downloaded prebuilt from the binary cache
123+ (only built on a Linux builder if not cached).
124+- **Assembly** runs entirely on your Mac: `copyToRoot` is a *host-arch* `buildEnv`
125+ symlink tree over those Linux paths (symlinks are arch-neutral), and
126+ `nix2container` + `skopeo` package it — so for a cached set, `init` produces a
127+ loadable Linux image with no Linux build at all.
135128- Apple's `container` runs each container in its own lightweight Linux VM and
136129 consumes standard OCI images — no `--privileged` or systemd needed.
137130
c+57−25
@@ -1,12 +1,14 @@
11#!/usr/bin/env fish
22# Manage a container named after the current directory.
3−# c init [-c FILE] [extra create args] build + load the image, then create it
4−# (packages from FILE, default ./container.nix)
3+# c init [-c FILE] [extra create args] build + load the image, then (re)create it
4+# (config from FILE, default ./container.nix)
55# c start start it and attach
66
77set -l name (path basename $PWD)
88# The flake lives next to this script (resolve symlinks so it works from $PATH too).
99set -l flake (path dirname (path resolve (status filename)))
10+# Per-directory image ref this script loads and runs (archive tag + `create`).
11+set -l image "nix-container-$name:latest"
1012
1113switch $argv[1]
1214 case init
@@ -15,36 +17,34 @@ switch $argv[1]
1517 argparse --ignore-unknown 'c/config=' -- $argv[2..-1]
1618 or exit 1
1719 set -l config container.nix
18− set -l explicit 0
1920 if set -q _flag_config
2021 set config $_flag_config
21− set explicit 1
2222 end
2323
24− # Build the OCI archive into a temp dir, load it, then clean up.
25− set -l tmp (mktemp -d)
26− set -l archive $tmp/image.tar.gz
27− set -l rc 0
28−
29− if test -e $config
30− # Per-project package set: build an image with exactly these packages.
31− set -lx NIX_CONTAINER_PKGS (path resolve $config)
32− set -l expr "(builtins.getFlake \"$flake\").lib.\${builtins.currentSystem}.copyWith (import (/. + builtins.getEnv \"NIX_CONTAINER_PKGS\"))"
33− set -l copyer (nix build --impure --no-link --print-out-paths --expr "$expr")
34− set rc $status
35− if test $rc -eq 0
36− $copyer/bin/copy-to "oci-archive:$archive:nix-container:latest"
37− set rc $status
38− end
39− else if test $explicit -eq 1
24+ if not test -e $config
4025 echo "c: config file not found: $config" >&2
41− rm -rf $tmp
26+ echo " create one ('{ packages = { pkgs, nur }: [ ... ]; mounts = [ ]; }') or pass -c FILE" >&2
4227 exit 1
43− else
44− nix run "$flake#image" -- "oci-archive:$archive:nix-container:latest"
45− set rc $status
4628 end
4729
30+ # Host login shell (by name): added to the image automatically and baked
31+ # in as the cmd + default $SHELL (what herdr panes etc. spawn), so it
32+ # needn't be listed in container.nix. Falls back to bash.
33+ set -l shell bash
34+ test -n "$SHELL"; and set shell (path basename $SHELL)
35+
36+ # Build an image with the config's `packages` (plus the shell) into a
37+ # temp dir, load it, then clean up.
38+ set -l tmp (mktemp -d)
39+ set -l archive $tmp/image.tar.gz
40+ set -lx NIX_CONTAINER_CONFIG (path resolve $config)
41+ set -l expr "(builtins.getFlake \"$flake\").lib.\${builtins.currentSystem}.copyWithShell \"nix-container-$name\" \"$shell\" (import (/. + builtins.getEnv \"NIX_CONTAINER_CONFIG\")).packages"
42+ set -l copyer (nix build --impure --no-link --print-out-paths --expr "$expr")
43+ set -l rc $status
44+ if test $rc -eq 0
45+ $copyer/bin/copy-to "oci-archive:$archive:$image"
46+ set rc $status
47+ end
4848 if test $rc -eq 0
4949 container image load --input $archive
5050 set rc $status
@@ -53,8 +53,40 @@ switch $argv[1]
5353 rm -rf $tmp
5454 test $rc -eq 0; or exit $rc
5555
56− container create --name $name --ssh -it $argv nix-container:latest
56+ # Mount the project at /workspace (the default cwd), plus any extra
57+ # mounts from the config (`mounts = [ "host:container" … ]`). A leading
58+ # ~/ in the host path expands to $HOME (nix leaves it literal).
59+ set -l mounts -v "$PWD:/workspace"
60+ for m in (nix eval --impure --raw --expr "builtins.concatStringsSep \"\n\" ((import (/. + builtins.getEnv \"NIX_CONTAINER_CONFIG\")).mounts or [])")
61+ set -a mounts -v (string replace -r '^~/' "$HOME/" -- $m)
62+ end
63+
64+ # TERM to bake into the container env (`-e TERM`): the runtime hands the
65+ # `start -ai` session a bare "xterm", so set the host's real terminal,
66+ # mapped to an entry the bundled ncurses ships — Ghostty reports
67+ # "xterm-ghostty", which ncurses ships as "ghostty" — falling back to
68+ # xterm-256color for an empty or bare-"xterm" value.
69+ set -l term xterm-256color
70+ if test "$TERM" = xterm-ghostty
71+ set term ghostty
72+ else if test -n "$TERM"; and test "$TERM" != xterm
73+ set term $TERM
74+ end
75+
76+ # Replace any existing container of the same name, then create it running
77+ # herdr in a session named after the project (`<dir>-container`). This
78+ # overrides the image's default plain-herdr cmd; `c start` attaches to it.
79+ container rm --force $name 2>/dev/null
80+ # The image only lays down /bin and /etc, so /tmp and /run don't exist;
81+ # without them anything that writes temp files (herdr, build tools, …)
82+ # fails with ENOENT. Mount writable tmpfs at both.
83+ container create --name $name --ssh -it -e "TERM=$term" \
84+ --tmpfs /tmp --tmpfs /run --memory 8g --cwd /workspace $mounts $argv \
85+ $image /bin/herdr session attach "$name-container"
5786 case start
87+ # Start the container and attach to its cmd (herdr). TERM was baked into
88+ # the container env at create time (`-e TERM`), which survives this path.
89+ # Exiting herdr (PID1) stops the container; `c start` boots it again.
5890 container start -ai $name
5991 case '*'
6092 echo "usage: c init [-c FILE] [create args] | start" >&2
flake.nix+82−119
@@ -72,138 +72,101 @@
7272 # Host package set, for the wrapper app below.
7373 pkgsHost = nixpkgs.legacyPackages.${system};
7474
75− # Name/tag baked into the image's OCI config.
75+ # Default image name (for `copyWith`); `c init` passes a per-directory
76+ # name (`nix-container-<dir>`) to `copyWithShell` instead.
7677 imageName = "nix-container";
7778 imageTag = "latest";
7879
79− # Fish prompt config, installed at /root/.config/fish/config.fish
80− # (fish reads $HOME/.config/fish).
81− fishConfig = pkgsLinux.writeText "config.fish" ''
82− # No welcome banner.
83− set -g fish_greeting
84−
85− # Define the prompt as a function so fish renders it before every
86− # command; at top level it would run once at startup and be ignored.
87− function fish_prompt
88− set -l nix_shell_info
89− if set -q IN_NIX_SHELL; or set -q IN_NIX_RUN
90− set nix_shell_info ' ❄️'
91− end
92−
93− set -l cwd (prompt_pwd)
94−
95− set -l bookmark_info
96− if jj root 2>/dev/null >/dev/null
97− set -l jj_bookmark (jj log -r 'heads(::@ & bookmarks())' -T 'local_bookmarks ++ "\n"' --no-graph 2>/dev/null | tail -1)
98− if test -n "$jj_bookmark"
99− set bookmark_info ' ' (set_color brmagenta) $jj_bookmark (set_color normal)
100− end
101− end
102−
103− echo -n -s (set_color $fish_color_cwd) $cwd (set_color normal) $bookmark_info ' 🏗️' $nix_shell_info '> '
104− end
105− '';
106−
107− # Lay the config out at the path fish reads.
108− fishRoot = pkgsLinux.runCommand "fish-config-root" { } ''
109− mkdir -p "$out/root/.config/fish"
110− cp ${fishConfig} "$out/root/.config/fish/config.fish"
111− '';
112−
113− # The curated tool set baked into the image. Drop a `container.nix`
114− # (`{ pkgs, nur }: [ ... ]`) next to where you run `c init` to replace
115− # this with your own list — see README.
116− defaultPackages =
117− { pkgs, nur }:
118− with pkgs;
119− [
120− bashInteractive
121− fish
122− openssh
123− coreutils-full
124− btop
125− jujutsu
126− zellij
127− micro
128− helix
129− nur.repos.charmbracelet.crush
130−
131− # LLM tools
132− git
133− ripgrep
134− fd
135− jq
136− curl
137− wget
138− gnused
139− gnugrep
140− gawk
141− findutils
142− gnutar
143− gzip
144− unzip
145− less
146− which
147− tree
148− nodejs
149− python3
150−
151− # rust
152− rustc
153− cargo
154− rustfmt
155− clippy
156−
157− # C toolchain — rustc links final binaries through `cc`/`ld`.
158− gcc # provides cc/gcc; pulls in binutils (ld) via its closure
159− ];
160−
161− # Build the OCI image from a `{ pkgs, nur }: [ ... ]` package function.
162− # The fish prompt config is always added; the default `cmd` is
163− # /bin/fish, so a custom package set should include `fish` (or change
164− # `config.cmd`).
80+ # Build the OCI image (named `name`) from a `{ pkgs, nur }: [ ... ]`
81+ # package function, for the named shell. The image's `cmd` is herdr
82+ # (the session `c start` attaches to); the shell is the default `$SHELL`
83+ # (what herdr panes spawn) and is added automatically, so `container.nix`
84+ # lists only your extras. Nix (+ CA certs) and the ncurses terminfo
85+ # database are always shipped too. Nothing here is fish-specific: the
86+ # TERM fixup happens host-side in `c` (passed via `-e TERM` at create).
16587 mkImage =
166− packages:
88+ name: shell: packages:
16789 n2c.buildImage {
168− name = imageName;
90+ inherit name;
16991 tag = imageTag;
17092 inherit arch;
17193
17294 # A plain, single-process root filesystem. No NixOS, no systemd.
173− copyToRoot = pkgsLinux.buildEnv {
95+ # buildEnv only *symlinks* paths (never runs them), so build it on
96+ # the host arch — the tree is arch-neutral and links the
97+ # (substituted) Linux store paths, sparing the Linux builder.
98+ copyToRoot = pkgsHost.buildEnv {
17499 name = "root";
175− paths = packages {
176− pkgs = pkgsLinux;
177− nur = nurPkgs;
178− } ++ [ fishRoot ];
100+ paths =
101+ packages {
102+ pkgs = pkgsLinux;
103+ nur = nurPkgs;
104+ }
105+ # The shell (cmd + $SHELL), when it exists in nixpkgs.
106+ ++ pkgsLinux.lib.optional (pkgsLinux ? ${shell}) pkgsLinux.${shell}
107+ ++ [
108+ pkgsLinux.nix
109+ pkgsLinux.cacert
110+ # Basic userland (ls, cat, cp, sleep, …) so the container is
111+ # usable out of the box and tools that shell out don't fail.
112+ pkgsLinux.coreutils-full
113+ # Networking glue glibc needs: /etc/nsswitch.conf (+passwd,
114+ # group) so DNS/host lookups resolve, and /etc/protocols,
115+ # /etc/services. Without these, hostname resolution fails.
116+ pkgsLinux.fakeNss
117+ pkgsLinux.iana-etc
118+ # The terminfo database (+ tput/clear/reset) so TUIs find the
119+ # entry for whatever TERM `c` passes in and render correctly.
120+ pkgsLinux.ncurses
121+ # The session `c start` always launches.
122+ pkgsLinux.herdr
123+ ];
124+ # Link all of /etc so the above files (nsswitch.conf, protocols,
125+ # services, passwd, group, ssl certs) are present.
179126 pathsToLink = [
180127 "/bin"
181− "/root"
128+ "/etc"
182129 ];
183130 };
184131
185132 initializeNixDatabase = true;
186133
187134 config = {
188− # `cmd` (not `entrypoint`): it's the default command and is
189− # *replaced* by `container run … -- <cmd>`. An entrypoint would
190− # be prepended instead, so `run … -- /bin/sh` would become
191− # `/bin/bash /bin/sh` and fail with "cannot execute binary file".
192− cmd = [ "/bin/fish" ];
135+ # `cmd` (not `entrypoint`): the default command, *replaced* by any
136+ # command passed to `container run/create`. Plain herdr here;
137+ # `c init` overrides it with `herdr session attach <dir>-container` so
138+ # the session is named per project. `c start` attaches via
139+ # `container start -ai`; exiting herdr (PID1) stops the container.
140+ cmd = [ "/bin/herdr" ];
193141 env = [
194142 "PATH=/bin"
195− # fish reads its prompt from $HOME/.config/fish/config.fish.
196143 "HOME=/root"
144+ # Default shell for tools that spawn one (herdr panes, etc.).
145+ "SHELL=/bin/${shell}"
146+ # Marker so shells/scripts can detect they're in here.
147+ "NIX_CONTAINER=1"
148+ # Advertise truecolor for 24-bit-aware tools; `c` passes the
149+ # resolved TERM via -e (the runtime would otherwise force xterm).
150+ "COLORTERM=truecolor"
151+ # A UTF-8 locale so tools handle multibyte/wide characters
152+ # correctly. glibc ships C.UTF-8 built in, so this needs no
153+ # locale-archive.
154+ "LANG=C.UTF-8"
155+ # CA trust for every TLS client (curl/git/…) and Nix.
156+ "SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt"
157+ "NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt"
158+ # Make the bundled Nix usable: flake commands on, and
159+ # single-user (no daemon/nixbld).
160+ "NIX_CONFIG=experimental-features = nix-command flakes\nbuild-users-group =\nsandbox = false"
197161 ];
198162 };
199163 };
200164
201− image = mkImage defaultPackages;
202−
203165 # `nix run . -- init|start` runs the bundled `c` manager script. Its
204− # build step shells back to `nix run .#image`; the script finds the
205− # flake from its own (store) location, so this works from a checkout
206− # or straight from `nix run github:…/nix-container`.
166+ # `init` builds the image from the project's `container.nix` (via
167+ # `lib.copyWithShell`); the script finds the flake from its own (store)
168+ # location, so this works from a checkout or straight from
169+ # `nix run github:…/nix-container`.
207170 cApp = pkgsHost.writeShellScriptBin "c" ''
208171 exec ${pkgsHost.fish}/bin/fish ${self}/c "$@"
209172 '';
@@ -212,24 +175,24 @@
212175 apps = {
213176 # nix run . -- init|start → build+load+create / start a container
214177 default = flake-utils.lib.mkApp { drv = cApp; };
215−
216− # nix run .#image -- <skopeo-dest> → copy the image anywhere, e.g.
217− # nix run .#image -- oci-archive:image.tar:nix-container:latest
218− # nix run .#image -- docker://ghcr.io/me/img:latest
219− # skopeo (`skopeo copy nix:<image> "$@"`) takes the ref.name from
220− # the destination, so spell out the tag to avoid an `untagged` load.
221− image = flake-utils.lib.mkApp { drv = image.copyTo; };
222178 };
223179
224− # Build helpers. `c init` uses `copyWith` to honour a per-project
225− # `container.nix`:
180+ # Build helpers take a `{ pkgs, nur }: [ ... ]` packages function (the
181+ # `packages` attr of a project's `container.nix`). `c init` uses
182+ # `copyWithShell` (host shell baked in); `copyWith` is the generic form:
226183 # (builtins.getFlake "github:…/nix-container")
227− # .lib.<system>.copyWith (import ./container.nix)
184+ # .lib.<system>.copyWith (import ./container.nix).packages
228185 lib = {
229186 inherit mkImage;
230− # skopeo copy app (`skopeo copy nix:<image> "$@"`) for an image built
231− # from a `{ pkgs, nur }: [ ... ]` function.
232− copyWith = packages: (mkImage packages).copyTo;
187+ # Build the image's `copyTo` script (a skopeo-copy wrapper) from a
188+ # `{ pkgs, nur }: [ ... ]` function, named `imageName`. Defaults the
189+ # shell (cmd + $SHELL) to bash; use `copyWithShell` to pick another.
190+ copyWith = packages: (mkImage imageName "bash" packages).copyTo;
191+ # Like `copyWith`, but for the given image `name` and shell — `c init`
192+ # passes `nix-container-<dir>` and the host login shell, which is added
193+ # to the image and used as cmd + $SHELL without being listed in
194+ # `container.nix`.
195+ copyWithShell = name: shell: packages: (mkImage name shell packages).copyTo;
233196 };
234197 }
235198 );