on master help sign in
init: run the host login shell instead of hard-coded fish
commitbd3aac1b03313f599f8bdc3cf69b020c2cd7d8b6 authoriko <mail@iko.soy> dateSat 27 Jun 2026, 21:36 (3 months ago) parentdbcb628
3 files changed+23−9
README.md+4−4 c+6−1 flake.nix+13−4
README.md+4−4
@@ -5,8 +5,8 @@ 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). It runs `fish` by default; you choose what it ships
9−via a per-project `container.nix`.
8+[`flake.nix`](./flake.nix). `init` runs your host login shell (`$SHELL`); you
9+choose what else it ships via a per-project `container.nix`.
1010
1111## Prerequisites
1212
@@ -32,7 +32,7 @@ is **required**; there is no default set.
3232```nix
3333# ./container.nix
3434{ pkgs, nur }: with pkgs; [
35− fish # the default cmd is /bin/fish, so include it (or change config.cmd)
35+ fish # `init` runs your host shell — include it (here, fish)
3636 coreutils
3737 git
3838 go
@@ -55,7 +55,7 @@ that holds a `container.nix`; the container is named after that directory.
5555# build the image, load it, and create the container (named after $PWD):
5656nix run github:ilyakooo0/nix-container -- init
5757
58−# start it and attach — drops you into fish:
58+# start it and attach — drops you into your shell:
5959nix run github:ilyakooo0/nix-container -- start
6060```
6161
c+6−1
@@ -51,9 +51,14 @@ switch $argv[1]
5151 set -l mounts -v "$PWD:/workspace"
5252 test -d $HOME/.config; and set -a mounts -v "$HOME/.config:/root/.config"
5353
54+ # Run the host's login shell (by name) instead of the image's default
55+ # cmd. The shell must be in the package set.
56+ set -l shell fish
57+ test -n "$SHELL"; and set shell (path basename $SHELL)
58+
5459 # Replace any existing container of the same name.
5560 container rm --force $name 2>/dev/null
56− container create --name $name --ssh -it --cwd /workspace $mounts $argv $image
61+ container create --name $name --ssh -it --cwd /workspace $mounts $argv $image /bin/$shell
5762 case start
5863 container start -ai $name
5964 case '*'
flake.nix+13−4
@@ -77,8 +77,9 @@
7777 imageTag = "latest";
7878
7979 # Build the OCI image from a `{ pkgs, nur }: [ ... ]` package function.
80− # The default `cmd` is /bin/fish, so the package set should include
81− # `fish` (warned about below if missing) or override `config.cmd`.
80+ # The default `cmd` is /bin/fish, but `c init` runs your host login
81+ # shell instead — so include that shell in the package set (a missing
82+ # shell is warned about below).
8283 mkImage =
8384 packages:
8485 let
@@ -86,9 +87,17 @@
8687 pkgs = pkgsLinux;
8788 nur = nurPkgs;
8889 };
90+ hasShell = builtins.any (
91+ p:
92+ builtins.elem (p.pname or "") [
93+ "fish"
94+ "bash"
95+ "zsh"
96+ ]
97+ ) pkgList;
8998 in
90− pkgsLinux.lib.warnIf (!builtins.any (p: (p.pname or "") == "fish") pkgList)
91− "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)."
99+ pkgsLinux.lib.warnIf (!hasShell)
100+ "nix-container: the package set has no shell (fish/bash/zsh) — the container's command may not exist (`c init` runs your host shell)."
92101 (
93102 n2c.buildImage {
94103 name = imageName;