on master help sign in
Make 'c init' build, load, and clean up the image archive
commit85eaf3940f62734cc12d8bd0da4d0aad257396bd authoriko <mail@iko.soy> dateSat 27 Jun 2026, 20:43 (3 months ago) parente3e2c82
2 files changed+18−5
README.md+9−4 c+9−1
README.md+9−4
@@ -55,14 +55,19 @@ container start -ai nixos
5555
5656You land in `fish`. Exit the shell to stop the container.
5757
58−> **Shortcut:** the [`c`](./c) script wraps create/start and names the container
59−> after the current directory (handy for per-project containers):
58+> **Shortcut:** the [`c`](./c) script bundles the workflow and names the
59+> container after the current directory (handy for per-project containers). It
60+> resolves the flake from its own location, so you can symlink it onto your
61+> `$PATH` and run it from any project:
6062>
6163> ```sh
62−> ./c init # create; append create args to add mounts, e.g.
63−> ./c init -v $PWD:/work # (mounts can only be set at creation time)
64+> ./c init # build + load the image, then create the container
65+> ./c init -v $PWD:/work # add create-time mounts (set only at creation)
6466> ./c start # start and attach
6567> ```
68+>
69+> `c init` builds the archive in a temp dir, loads it, and deletes it — so no
70+> `image.tar.gz` is left lying around.
6671
6772## Re-running after a rebuild
6873
c+9−1
@@ -1,12 +1,20 @@
11#!/usr/bin/env fish
22# Manage a container named after the current directory.
3−# c init [extra create args] create it (e.g. c init -v $PWD:/work)
3+# c init [extra create args] build + load the image, then create the container
44# c start start it and attach
55
66set -l name (path basename $PWD)
7+# The flake lives next to this script (resolve symlinks so it works from $PATH too).
8+set -l flake (path dirname (path resolve (status filename)))
79
810switch $argv[1]
911 case init
12+ # Build the OCI archive into a temp dir, load it, then clean up.
13+ set -l tmp (mktemp -d)
14+ nix run $flake -- $tmp/image.tar.gz; and container image load --input $tmp/image.tar.gz
15+ set -l rc $status
16+ rm -rf $tmp
17+ test $rc -eq 0; or exit $rc
1018 container create --name $name --ssh -it $argv[2..-1] nix-container:latest
1119 case start
1220 container start -ai $name