on master help sign in
Load the bundled fish prompt via --no-config so ~/.config can't override it
b65e1e6iko
README.md+2−1
@@ -66,7 +66,8 @@ nix run github:ilyakooo0/nix-container -- start
66- `init` builds the OCI archive in a temp dir, loads it into `container`,
66- `init` builds the OCI archive in a temp dir, loads it into `container`,
67 deletes the temp file, then (re)creates the container. It mounts the current
67 deletes the temp file, then (re)creates the container. It mounts the current
68 directory at `/workspace` (the container's working directory) and your
68 directory at `/workspace` (the container's working directory) and your
69− `~/.config` at `/root/.config`.
69+ `~/.config` at `/root/.config` (fish runs with `--no-config`, so this won't
70+ override its bundled prompt; other tools still read it).
70- `--ssh` forwards your host SSH agent socket into the container (so `git` over
71- `--ssh` forwards your host SSH agent socket into the container (so `git` over
71 SSH works with your keys).
72 SSH works with your keys).
72- Add more mounts by passing them through (mounts can only be set at creation):
73- Add more mounts by passing them through (mounts can only be set at creation):
c+1−1
@@ -48,7 +48,7 @@ switch $argv[1]
48 test $rc -eq 0; or exit $rc
48 test $rc -eq 0; or exit $rc
49
49
50 # Mount the project at /workspace (the default cwd) and host ~/.config.
50 # Mount the project at /workspace (the default cwd) and host ~/.config.
51− # (Mounting ~/.config shadows the image's bundled fish prompt config.)
51+ # (fish runs with --no-config, so the mount can't shadow the prompt.)
52 set -l mounts -v "$PWD:/workspace"
52 set -l mounts -v "$PWD:/workspace"
53 test -d $HOME/.config; and set -a mounts -v "$HOME/.config:/root/.config"
53 test -d $HOME/.config; and set -a mounts -v "$HOME/.config:/root/.config"
54
54
flake.nix+20−14
@@ -76,10 +76,11 @@
76 imageName = "nix-container";
76 imageName = "nix-container";
77 imageTag = "latest";
77 imageTag = "latest";
78
78
79− # Fish prompt config, installed at /root/.config/fish/config.fish
79+ # Fish prompt config. Installed at /etc/fish/prompt.fish and loaded via
80− # (fish reads $HOME/.config/fish). Built on the host arch — it's just a
80+ # `fish --no-config --init-command` (see `cmd` below), NOT from
81+ # $HOME/.config/fish — so the `~/.config` mount can't shadow it. Built
81− # text file, so no Linux builder is needed.
82+ # on the host arch (just a text file), so no Linux builder is needed.
82− fishConfig = pkgsHost.writeText "config.fish" ''
83+ fishConfig = pkgsHost.writeText "prompt.fish" ''
83 # No welcome banner.
84 # No welcome banner.
84 set -g fish_greeting
85 set -g fish_greeting
85
86
@@ -105,10 +106,10 @@
105 end
106 end
106 '';
107 '';
107
108
108− # Lay the config out at the path fish reads.
109+ # Lay the prompt out at the path the cmd sources.
109− fishRoot = pkgsHost.runCommand "fish-config-root" { } ''
110+ fishRoot = pkgsHost.runCommand "fish-prompt" { } ''
110− mkdir -p "$out/root/.config/fish"
111+ mkdir -p "$out/etc/fish"
111− cp ${fishConfig} "$out/root/.config/fish/config.fish"
112+ cp ${fishConfig} "$out/etc/fish/prompt.fish"
112 '';
113 '';
113
114
114 # Build the OCI image from a `{ pkgs, nur }: [ ... ]` package function.
115 # Build the OCI image from a `{ pkgs, nur }: [ ... ]` package function.
@@ -144,7 +145,7 @@
144 ];
145 ];
145 pathsToLink = [
146 pathsToLink = [
146 "/bin"
147 "/bin"
147− "/root"
148+ "/etc/fish"
148 "/etc/ssl"
149 "/etc/ssl"
149 ];
150 ];
150 };
151 };
@@ -152,11 +153,16 @@
152 initializeNixDatabase = true;
153 initializeNixDatabase = true;
153
154
154 config = {
155 config = {
155− # `cmd` (not `entrypoint`): it's the default command and is
156+ # `cmd` (not `entrypoint`): the default command, *replaced* by any
156− # *replaced* by `container run … -- <cmd>`. An entrypoint would be
157+ # command passed to `container run/create`. `--no-config` skips
157− # prepended instead, so `run … -- /bin/sh` would become
158+ # $HOME/.config/fish (so a mounted ~/.config can't override the
158− # `/bin/bash /bin/sh` and fail with "cannot execute binary file".
159+ # prompt); `--init-command` loads the bundled prompt instead.
160+ cmd = [
159− cmd = [ "/bin/fish" ];
161+ "/bin/fish"
162+ "--no-config"
163+ "--init-command"
164+ "source /etc/fish/prompt.fish"
165+ ];
160 env = [
166 env = [
161 "PATH=/bin"
167 "PATH=/bin"
162 "HOME=/root"
168 "HOME=/root"