nix-darwin icon indicating copy to clipboard operation
nix-darwin copied to clipboard

Completions for nix will conflict with Nix 2.4

Open kubukoz opened this issue 3 years ago • 6 comments

Nix 2.4 defines its own zsh completions. When I used https://github.com/NixOS/nixpkgs/pull/144197's pkgs.nix as my nix.package, I started getting errors during the build:

error: collision between `/nix/store/j5i4bhqa2dh8wk98l0g2csnmz63l2k9y-nix-2.4/share/zsh/site-functions/_nix' and `/nix/store/bbz7556b8yk668y1dpyma3qcwhrswf0d-nix-zsh-completions-0.4.4/share/zsh/site-functions/_nix'

I believe the problem is that enabling the programs.zsh.enableCompletion option does two things:

https://github.com/LnL7/nix-darwin/blob/44da835ac40dab5fd231298b59d83487382d2fab/modules/programs/zsh/default.nix#L103

  1. adding pkgs.nix-zsh-completions to system packages
  2. run autoload -U compinit && compinit in /etc/zshrc

I would suggest either splitting the option into two (both defaulting to true, to be consistent with the current behavior) or removing the first behavior.

As a workaround, I'm looking into whether I can rely on home-manager's zsh setup to call compinit instead (and disable this flag completely), worst case overriding nix-zsh-completions to an almost-empty package.

Update: I had something else that was wrong in nix-darwin setup, apparently just disabling the option here makes things okay (home-manager's zsh will call compinit anyway)

kubukoz avatar Nov 03 '21 12:11 kubukoz

I got the exact same error and thought it was just me

rpearce avatar Nov 03 '21 23:11 rpearce

I've been scratching my head on this issue for hours without a solution. I'm using nix-darwin and home-manager via a nix flake and I'm installing zsh using home-manager's programs.zsh.enableCompletion

@kubukoz can you explain what was the issue with your nix-darwin config which solved this?

jfchevrette avatar Nov 04 '21 00:11 jfchevrette

I don't use home manager, but I've been able to work around this problem for now with programs.zsh.enableCompletion = false; and then adding autoload -U compinit && compinit to programs.zsh.interactiveShellInit.

mattsawyer77 avatar Nov 13 '21 19:11 mattsawyer77

I ported over the fix from nixpkgs for this issue: https://github.com/LnL7/nix-darwin/pull/379

antifuchs avatar Nov 14 '21 10:11 antifuchs

Now that NixOS/nixpkgs#146030 is in nixpkgs (and I believe backported to 21.11), I think/hope this can be closed?

antifuchs avatar Dec 03 '21 10:12 antifuchs

I still have this while I was trying to unstable Nix 2.5 (via the unstable channel).

The workaround described previously seems to work for me.

Here is the config I use:

programs.zsh = {
    enable = true; 
    enableCompletion = false;
    interactiveShellInit = "autoload -U compinit && compinit";
};

Mayeu avatar Jan 06 '22 21:01 Mayeu

Looks like this should be fixed in 22.05 and above; please comment here if you're still experiencing it.

emilazy avatar Jul 10 '23 09:07 emilazy