on master help sign in
Restore shell detection: add host shell to image and set as default (bash fallback)
commit721fa1d1699998b25d45ea11a4a22e0572711a21 authoriko <mail@iko.soy> dateSun 28 Jun 2026, 05:20 (3 months ago) parentc8c08a1
2 files changed+21−4
c+12−4 flake.nix+9
c+12−4
@@ -27,12 +27,18 @@ switch $argv[1]
2727 exit 1
2828 end
2929
30− # Build an image with the packages from $config into a temp dir, load
31− # it, then clean up.
30+ # Host login shell (by name): added to the image automatically and used
31+ # as the default shell (what zellij panes etc. spawn), so it needn't be
32+ # 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 packages from $config (plus the shell) into a
37+ # temp dir, load it, then clean up.
3238 set -l tmp (mktemp -d)
3339 set -l archive $tmp/image.tar.gz
3440 set -lx NIX_CONTAINER_PKGS (path resolve $config)
35− set -l expr "(builtins.getFlake \"$flake\").lib.\${builtins.currentSystem}.copyWith (import (/. + builtins.getEnv \"NIX_CONTAINER_PKGS\"))"
41+ set -l expr "(builtins.getFlake \"$flake\").lib.\${builtins.currentSystem}.copyWithShell \"$shell\" (import (/. + builtins.getEnv \"NIX_CONTAINER_PKGS\"))"
3642 set -l copyer (nix build --impure --no-link --print-out-paths --expr "$expr")
3743 set -l rc $status
3844 if test $rc -eq 0
@@ -62,7 +68,9 @@ switch $argv[1]
6268 # The image only lays down /bin and /etc, so /tmp and /run don't exist;
6369 # without them anything that writes temp files (zellij, build tools, …)
6470 # fails with ENOENT. Mount writable tmpfs at both.
65− container create --name $name --ssh -it -e "HOST_TERM=$TERM" \
71+ # SHELL=/bin/<detected> makes the host shell the default (zellij panes,
72+ # etc.); it overrides the image's baked-in SHELL=/bin/fish fallback.
73+ container create --name $name --ssh -it -e "HOST_TERM=$TERM" -e "SHELL=/bin/$shell" \
6674 --tmpfs /tmp --tmpfs /run --memory 8g --cwd /workspace $mounts $argv $image
6775 case start
6876 # Boot the container detached (its PID1 fish keeps it alive), then attach
flake.nix+9
@@ -242,6 +242,15 @@
242242 # skopeo copy app (`skopeo copy nix:<image> "$@"`) for an image built
243243 # from a `{ pkgs, nur }: [ ... ]` function.
244244 copyWith = packages: (mkImage packages).copyTo;
245+ # Like `copyWith`, but also adds the named shell package (when it
246+ # exists in nixpkgs) so `c init` can make the host shell available
247+ # without it being listed in `container.nix`.
248+ copyWithShell =
249+ shell: packages:
250+ (mkImage (
251+ { pkgs, nur }:
252+ packages { inherit pkgs nur; } ++ pkgs.lib.optional (pkgs ? ${shell}) pkgs.${shell}
253+ )).copyTo;
245254 };
246255 }
247256 );