@@ -126,21 +126,20 @@ allow_direnv() {
126126}
127127
128128persist_nix_environment () {
129- local nix_bin nix_bin_dir profile=" $HOME /.bash_profile" nix_profile
129+ local activation_dir=" $HOME /.config/docker-extras"
130+ local activation=" $activation_dir /orb-dev-shell.sh"
131+ local marker=' # docker-extras Nix development shell'
132+ local nix_bin nix_bin_dir profile=" $HOME /.bash_profile" nix_profile temporary
130133 nix_bin=" $( command -v nix) "
131134 nix_bin_dir=" $( dirname " $nix_bin " ) "
132135 nix_profile=/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
133136 if [ ! -f " $nix_profile " ]; then
134137 nix_profile=" $HOME /.nix-profile/etc/profile.d/nix.sh"
135138 fi
136- local marker=' # docker-extras Nix development shell'
137- if grep -Fqx " $marker " " $profile " 2> /dev/null; then
138- return
139- fi
140-
141- cat >> " $profile " << EOF
142139
143- $marker
140+ mkdir -p " $activation_dir "
141+ cat > " $activation " << EOF
142+ # Generated by docker-extras .agents/setup.
144143if [ -f "$nix_profile " ]; then
145144 # shellcheck disable=SC1090
146145 source "$nix_profile "
@@ -150,6 +149,20 @@ if [[ -z "\${IN_NIX_SHELL:-}" && "\${PWD}" == "$repo_root" ]]; then
150149 export PATH="$nix_bin_dir :\$ {PATH}"
151150fi
152151EOF
152+
153+ # Amp applies the thread environment after setup and sources it from the
154+ # end of .bash_profile. Remove any previous copy, then append this managed
155+ # source block so the dev shell wins over that environment.
156+ touch " $profile "
157+ temporary=" $( mktemp) "
158+ awk -v marker=" $marker " '
159+ $0 == marker { skipping = 1; next }
160+ skipping && $0 == "" { skipping = 0; next }
161+ !skipping { print }
162+ ' " $profile " > " $temporary "
163+ cat " $temporary " > " $profile "
164+ rm -f " $temporary "
165+ printf ' \n%s\nsource %q\n\n' " $marker " " $activation " >> " $profile "
153166}
154167
155168verify_dev_shell () {
0 commit comments