1{ lib, stdenv, fetchFromGitHub }:
2
3stdenv.mkDerivation rec {
4 version = "0.6.8";
5 pname = "nix-bash-completions";
6
7 src = fetchFromGitHub {
8 owner = "hedning";
9 repo = "nix-bash-completions";
10 rev = "v${version}";
11 sha256 = "1n5zs6xcnv4bv1hdaypmz7fv4j7dsr4a0ifah99iyj4p5j85i1bc";
12 };
13
14 postPatch = ''
15 # Nix 2.4+ provides its own completion for the nix command, see https://github.com/hedning/nix-bash-completions/issues/20
16 substituteInPlace _nix --replace 'nix nixos-option' 'nixos-option'
17 '';
18
19 strictDeps = true;
20 # To enable lazy loading via bash-completion we need a symlink to the script
21 # from every command name.
22 installPhase = ''
23 runHook preInstall
24
25 commands=$(
26 function complete() { shift 2; echo "$@"; }
27 shopt -s extglob
28 source _nix
29 )
30 install -Dm444 -t $out/share/bash-completion/completions _nix
31 cd $out/share/bash-completion/completions
32 for c in $commands; do
33 ln -s _nix $c
34 done
35
36 runHook postInstall
37 '';
38
39 meta = with lib; {
40 homepage = "https://github.com/hedning/nix-bash-completions";
41 description = "Bash completions for Nix, NixOS, and NixOps";
42 license = licenses.bsd3;
43 platforms = platforms.all;
44 maintainers = with maintainers; [ hedning ncfavier ];
45 # Set a lower priority such that Nix wins in case of conflicts.
46 priority = 10;
47 };
48}