Home-manager: compinit not run then using zsh on non-nixos system

Created on 1 Apr 2020  路  5Comments  路  Source: nix-community/home-manager

When using zsh on a non-NixOs system (ubuntu) with zsh installed and configured via home-manager, the autocompletion for nix commands does not work. For everything else, it is just fine.

I've found a snippet to test it:

for command completion in ${(kv)_comps:#-*(-|-,*)}
do
    echo $command $completion
done | sort | grep nix

I had to manually add

    programs.zsh.initExtra = "
    autoload -U compinit && compinit
    ";

to finally have something come out of that list (and indeed, nix commands autocomplete).
I'm on master channel of home-manager.

Note:
I've read the previous tickets about similar issues, but I'm not sure how to read them. It looks like compinit is run automatically on nixos systems (which then would not experience the issue) and should not be "automatically" run because then it would be a performance penalty on on NixOs.
I'm now wondering if simply documenting it would be enough for other people having the same issue...

Most helpful comment

Can you try to remove .zcompdump files to make sure it's not a problem with them? You can see their location with $ echo $ZSH_COMPDUMP. Make sure to open a new shell after removing them.

All 5 comments

Have you tried to set programs.zsh.enableCompletion = true in your config? Unless you are using oh-my-zsh, it should add compinit call to your zshrc: https://github.com/rycee/home-manager/blob/7fa890462d2105566cc36599833cb3cb153df0ed/modules/programs/zsh.nix#L399-L401

Thanks for the answer. I have enableCompletion = true and I'm using oh-my-zsh, but even if I read on some previous bug-report that oh-my-zsh should automatically perform these operations, it looks like it is not happening on my side.

My (almost complete) conf is this one:

  programs.zsh = lib.recursiveUpdate conf.zsh {
    enable = true;
    enableAutosuggestions = true;
    enableCompletion = true;
    defaultKeymap = "emacs";
    history.share = true;
    localVariables = {
      EDITOR = "emacs";
    };
    oh-my-zsh = {
      enable = true;
      theme = "minimal";
      plugins = ["git" "sudo"];
    };
    shellAliases = {
      e="emacs -nw";
      g="git";
    };
  };

Any suggestion on how to debug this?

Can you try to remove .zcompdump files to make sure it's not a problem with them? You can see their location with $ echo $ZSH_COMPDUMP. Make sure to open a new shell after removing them.

Looks like that was the issue indeed.

Sorry for the time loss on this, I really had no clue :)

No problem, glad it helped!

Was this page helpful?
0 / 5 - 0 ratings