on master help sign in
Robustness: warn when fish is missing, de-dup image ref, tidy .gitignore
commitdfc2fe195cebb8977ef6f947795c722a5cd93c4b authoriko <mail@iko.soy> dateSat 27 Jun 2026, 21:24 (3 months ago) parent5f26b3e
3 files changed+45−37
.gitignore−1 c+4−2 flake.nix+41−34
.gitignore−1
@@ -1,2 +1 @@
1−image.tar.gz
21result
c+4−2
@@ -7,6 +7,8 @@
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+# Image ref this script loads and runs (the archive tag + `create` reference).
11+set -l image nix-container:latest
1012
1113switch $argv[1]
1214 case init
@@ -34,7 +36,7 @@ switch $argv[1]
3436 set -l copyer (nix build --impure --no-link --print-out-paths --expr "$expr")
3537 set -l rc $status
3638 if test $rc -eq 0
37− $copyer/bin/copy-to "oci-archive:$archive:nix-container:latest"
39+ $copyer/bin/copy-to "oci-archive:$archive:$image"
3840 set rc $status
3941 end
4042 if test $rc -eq 0
@@ -52,7 +54,7 @@ switch $argv[1]
5254
5355 # Replace any existing container of the same name.
5456 container rm --force $name 2>/dev/null
55− container create --name $name --ssh -it --cwd /workspace $mounts $argv nix-container:latest
57+ container create --name $name --ssh -it --cwd /workspace $mounts $argv $image
5658 case start
5759 container start -ai $name
5860 case '*'
flake.nix+41−34
@@ -112,43 +112,50 @@
112112
113113 # Build the OCI image from a `{ pkgs, nur }: [ ... ]` package function.
114114 # The fish prompt config is always added; the default `cmd` is
115− # /bin/fish, so a custom package set should include `fish` (or change
116− # `config.cmd`).
115+ # /bin/fish, so the package set should include `fish` (warned about
116+ # below if missing) or override `config.cmd`.
117117 mkImage =
118118 packages:
119− n2c.buildImage {
120− name = imageName;
121− tag = imageTag;
122− inherit arch;
123−
124− # A plain, single-process root filesystem. No NixOS, no systemd.
125− copyToRoot = pkgsLinux.buildEnv {
126− name = "root";
127− paths = packages {
128− pkgs = pkgsLinux;
129− nur = nurPkgs;
130− } ++ [ fishRoot ];
131− pathsToLink = [
132− "/bin"
133− "/root"
134− ];
119+ let
120+ pkgList = packages {
121+ pkgs = pkgsLinux;
122+ nur = nurPkgs;
135123 };
136−
137− initializeNixDatabase = true;
138−
139− config = {
140− # `cmd` (not `entrypoint`): it's the default command and is
141− # *replaced* by `container run … -- <cmd>`. An entrypoint would
142− # be prepended instead, so `run … -- /bin/sh` would become
143− # `/bin/bash /bin/sh` and fail with "cannot execute binary file".
144− cmd = [ "/bin/fish" ];
145− env = [
146− "PATH=/bin"
147− # fish reads its prompt from $HOME/.config/fish/config.fish.
148− "HOME=/root"
149− ];
150− };
151− };
124+ in
125+ pkgsLinux.lib.warnIf (!builtins.any (p: (p.pname or "") == "fish") pkgList)
126+ "nix-container: config.cmd is /bin/fish but the package set has no `fish` — the container will fail to start unless something provides /bin/fish (or change config.cmd)."
127+ (
128+ n2c.buildImage {
129+ name = imageName;
130+ tag = imageTag;
131+ inherit arch;
132+
133+ # A plain, single-process root filesystem. No NixOS, no systemd.
134+ copyToRoot = pkgsLinux.buildEnv {
135+ name = "root";
136+ paths = pkgList ++ [ fishRoot ];
137+ pathsToLink = [
138+ "/bin"
139+ "/root"
140+ ];
141+ };
142+
143+ initializeNixDatabase = true;
144+
145+ config = {
146+ # `cmd` (not `entrypoint`): it's the default command and is
147+ # *replaced* by `container run … -- <cmd>`. An entrypoint would
148+ # be prepended instead, so `run … -- /bin/sh` would become
149+ # `/bin/bash /bin/sh` and fail with "cannot execute binary file".
150+ cmd = [ "/bin/fish" ];
151+ env = [
152+ "PATH=/bin"
153+ # fish reads its prompt from $HOME/.config/fish/config.fish.
154+ "HOME=/root"
155+ ];
156+ };
157+ }
158+ );
152159
153160 # `nix run . -- init|start` runs the bundled `c` manager script. Its
154161 # `init` builds the image from the project's `container.nix` (via