on master help sign in
Robustness: warn when fish is missing, de-dup image ref, tidy .gitignore
dfc2fe1iko
.gitignore−1
@@ -1,2 +1 @@
1−image.tar.gz
2result
1result
c+4−2
@@ -7,6 +7,8 @@
7set -l name (path basename $PWD)
7set -l name (path basename $PWD)
8# The flake lives next to this script (resolve symlinks so it works from $PATH too).
8# The flake lives next to this script (resolve symlinks so it works from $PATH too).
9set -l flake (path dirname (path resolve (status filename)))
9set -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
10
12
11switch $argv[1]
13switch $argv[1]
12 case init
14 case init
@@ -34,7 +36,7 @@ switch $argv[1]
34 set -l copyer (nix build --impure --no-link --print-out-paths --expr "$expr")
36 set -l copyer (nix build --impure --no-link --print-out-paths --expr "$expr")
35 set -l rc $status
37 set -l rc $status
36 if test $rc -eq 0
38 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"
38 set rc $status
40 set rc $status
39 end
41 end
40 if test $rc -eq 0
42 if test $rc -eq 0
@@ -52,7 +54,7 @@ switch $argv[1]
52
54
53 # Replace any existing container of the same name.
55 # Replace any existing container of the same name.
54 container rm --force $name 2>/dev/null
56 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
56 case start
58 case start
57 container start -ai $name
59 container start -ai $name
58 case '*'
60 case '*'
flake.nix+41−34
@@ -112,43 +112,50 @@
112
112
113 # Build the OCI image from a `{ pkgs, nur }: [ ... ]` package function.
113 # Build the OCI image from a `{ pkgs, nur }: [ ... ]` package function.
114 # The fish prompt config is always added; the default `cmd` is
114 # The fish prompt config is always added; the default `cmd` is
115− # /bin/fish, so a custom package set should include `fish` (or change
115+ # /bin/fish, so the package set should include `fish` (warned about
116− # `config.cmd`).
116+ # below if missing) or override `config.cmd`.
117 mkImage =
117 mkImage =
118 packages:
118 packages:
119− n2c.buildImage {
119+ let
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 {
120+ pkgList = packages {
128− pkgs = pkgsLinux;
121+ pkgs = pkgsLinux;
129− nur = nurPkgs;
122+ nur = nurPkgs;
130− } ++ [ fishRoot ];
131− pathsToLink = [
132− "/bin"
133− "/root"
134− ];
135 };
123 };
136−
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+
137− initializeNixDatabase = true;
143+ initializeNixDatabase = true;
138−
144+
139− config = {
145+ config = {
140− # `cmd` (not `entrypoint`): it's the default command and is
146+ # `cmd` (not `entrypoint`): it's the default command and is
141− # *replaced* by `container run … -- <cmd>`. An entrypoint would
147+ # *replaced* by `container run … -- <cmd>`. An entrypoint would
142− # be prepended instead, so `run … -- /bin/sh` would become
148+ # be prepended instead, so `run … -- /bin/sh` would become
143− # `/bin/bash /bin/sh` and fail with "cannot execute binary file".
149+ # `/bin/bash /bin/sh` and fail with "cannot execute binary file".
144− cmd = [ "/bin/fish" ];
150+ cmd = [ "/bin/fish" ];
145− env = [
151+ env = [
146− "PATH=/bin"
152+ "PATH=/bin"
147− # fish reads its prompt from $HOME/.config/fish/config.fish.
153+ # fish reads its prompt from $HOME/.config/fish/config.fish.
148− "HOME=/root"
154+ "HOME=/root"
149− ];
155+ ];
150− };
156+ };
151− };
157+ }
158+ );
152
159
153 # `nix run . -- init|start` runs the bundled `c` manager script. Its
160 # `nix run . -- init|start` runs the bundled `c` manager script. Its
154 # `init` builds the image from the project's `container.nix` (via
161 # `init` builds the image from the project's `container.nix` (via