@@ -1,7 +1,7 @@
11#!/usr/bin/env fish
22# Manage a container named after the current directory.
33# c init [-c FILE] [extra create args] build + load the image, then (re)create it
4−# (packages from FILE, default ./container.nix)
4+# (config from FILE, default ./container.nix)
55# c start start it and attach
66
77set -l name (path basename $PWD)
@@ -22,8 +22,8 @@ switch $argv[1]
2222 end
2323
2424 if not test -e $config
25− echo "c: package file not found: $config" >&2
26− echo " create one ('{ pkgs, nur }: [ ... ]') or pass -c FILE" >&2
25+ echo "c: config file not found: $config" >&2
26+ echo " create one ('{ packages = { pkgs, nur }: [ ... ]; mounts = [ ]; }') or pass -c FILE" >&2
2727 exit 1
2828 end
2929
@@ -33,12 +33,12 @@ switch $argv[1]
3333 set -l shell bash
3434 test -n "$SHELL"; and set shell (path basename $SHELL)
3535
36− # Build an image with the packages from $config (plus the shell) into a
36+ # Build an image with the config's `packages` (plus the shell) into a
3737 # temp dir, load it, then clean up.
3838 set -l tmp (mktemp -d)
3939 set -l archive $tmp/image.tar.gz
4040 set -lx NIX_CONTAINER_PKGS (path resolve $config)
41− set -l expr "(builtins.getFlake \"$flake\").lib.\${builtins.currentSystem}.copyWithShell \"nix-container-$name\" \"$shell\" (import (/. + builtins.getEnv \"NIX_CONTAINER_PKGS\"))"
41+ set -l expr "(builtins.getFlake \"$flake\").lib.\${builtins.currentSystem}.copyWithShell \"nix-container-$name\" \"$shell\" (import (/. + builtins.getEnv \"NIX_CONTAINER_PKGS\")).packages"
4242 set -l copyer (nix build --impure --no-link --print-out-paths --expr "$expr")
4343 set -l rc $status
4444 if test $rc -eq 0
@@ -53,8 +53,13 @@ switch $argv[1]
5353 rm -rf $tmp
5454 test $rc -eq 0; or exit $rc
5555
56− # Mount the project at /workspace (the default cwd).
56+ # Mount the project at /workspace (the default cwd), plus any extra
57+ # mounts from the config (`mounts = [ "host:container" … ]`). A leading
58+ # ~/ in the host path expands to $HOME (nix leaves it literal).
5759 set -l mounts -v "$PWD:/workspace"
60+ for m in (nix eval --impure --raw --expr "builtins.concatStringsSep \"\n\" ((import (/. + builtins.getEnv \"NIX_CONTAINER_PKGS\")).mounts or [])")
61+ set -a mounts -v (string replace -r '^~/' "$HOME/" -- $m)
62+ end
5863
5964 # TERM to bake into the container env (`-e TERM`): the runtime hands the
6065 # `start -ai` session a bare "xterm", so set the host's real terminal,