Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing bash-completion makes bash startup slow on NixOS #32533

Closed
hedning opened this issue Dec 10, 2017 · 1 comment
Closed

Installing bash-completion makes bash startup slow on NixOS #32533

hedning opened this issue Dec 10, 2017 · 1 comment

Comments

@hedning
Copy link
Contributor

hedning commented Dec 10, 2017

Issue description

Opening up a new issue, as the last one, #22648, is closed.

bash-completion is designed to lazy load completions via __completion_loader. NixOS's generated /etc/bashrc however eagerly sources everything in $NIX_PROFILES/bash-completion/completions/* on startup (bash.nix).

This usually isn't a big problem when bash-completion isn't installed into a profile, since the big bulk of completion scripts bash-completion ships with will be correctly lazy loaded, leaving only a small amount of scripts being sourced on startup.

This however breaks when installing bash-completion as everything will be sourced on startup.

The fix

I believe the fix is simply not sourcing $NIX_PROFILES/bash-completion/completions/* via /etc/bashrc, leaving it fully up to bash-completion lazely load the scripts (it should look in its own nix store path and in ~/.nix-profile/share via $XDG_DATA_DIRS (ref).

Though I might've missed something of course so ccing @peti as he's the author of e627d30 and might know if there's any pitfalls in not sourcing on startup.

Steps to reproduce

  • enable programs.bash.enableCompletion
  • install bash-completion, either via. systemPackages or nix-env -iA nixos.bash-completion
  • start a new interactive bash shell

Technical details

  • system: "x86_64-linux"
  • host os: Linux 4.9.65, NixOS, 18.03.git.4cbbecc (Impala)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 1.11.15
  • channels(hed): ""
  • channels(root): "nixos-17.09.1462.07ca7b64d2"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs
@hedning
Copy link
Contributor Author

hedning commented Dec 10, 2017

Tested the fix out now, and it does seem to work, (completion scripts are being picked up from /run/current-system/sw/share/bash-completion/completions and ~/.nix-profile/share/bash-completion/completions), will make PR.

diff --git a/nixos/modules/programs/bash/bash.nix b/nixos/modules/programs/bash/bash.nix
index ef1acdfe66e..52d3780e045 100644
--- a/nixos/modules/programs/bash/bash.nix
+++ b/nixos/modules/programs/bash/bash.nix
@@ -20,7 +20,7 @@ let
       nullglobStatus=$(shopt -p nullglob)
       shopt -s nullglob
       for p in $NIX_PROFILES; do
-        for m in "$p/etc/bash_completion.d/"* "$p/share/bash-completion/completions/"*; do
+        for m in "$p/etc/bash_completion.d/"*; do
           . $m
         done
       done

@orivej orivej closed this as completed in 9988224 Dec 10, 2017
LnL7 pushed a commit to Kaali/nix-darwin that referenced this issue Jan 21, 2020
As described in detail here: NixOS/nixpkgs#32533
bash will load completion scripts in $p/share/bash-completion/completions/ on
startup instead of letting bash-completion do it's lazy loading. Bash startup
will then slow down (very noticeable when bash-completion is installed in a
profile).

This commit leaves loading of scripts in the hands of bash-completion,
improving startup time for everyone using `enableCompletion`.

Fixes LnL7#101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant