From 6bf7edb18b2815ac5758c937d69c1098e021edca Mon Sep 17 00:00:00 2001 From: Hraban Luyat Date: Sun, 12 May 2024 21:36:08 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20don=E2=80=99t=20expand=20aliases=20in=20?= =?UTF-8?q?develop=20stdenv=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes https://github.com/NixOS/nixpkgs/pull/290775 by not expanding aliases when sourcing the stdenv setup script. The way bash handles aliases is to expand them when a function is defined, not when it is used. I.e.: $ alias echo="echo bar " $ echo foo bar foo $ xyzzy() { echo foo; } $ shopt -u expand_aliases $ xyzzy bar foo $ xyzzy2() { echo foo; } $ xyzzy2 foo The problem is that ~/.bashrc is sourced before the stdenv setup, and bashrc commonly sets aliases for ‘cp’, ‘mv’ and ‘rm’ which you don’t want to take effect in the stdenv derivation builders. The original commit introducing this feature (5fd8cf76676a280ae2b7a86ddabc6b14b41ebfe5) even mentioned this very alias. The only way to avoid this is to disable aliases entirely while sourcing the stdenv setup, and reenable them afterwards. --- src/nix/develop.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 08d44d7aa..0363ca829 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -610,7 +610,7 @@ struct CmdDevelop : Common, MixEnvironment } else { - script = "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc;\n" + script; + script = "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc;\nshopt -u expand_aliases\n" + script + "\nshopt -s expand_aliases\n"; if (developSettings.bashPrompt != "") script += fmt("[ -n \"$PS1\" ] && PS1=%s;\n", shellEscape(developSettings.bashPrompt.get()));