1 { lib, stdenv, fetchFromGitHub, fetchpatch }:
3 stdenv.mkDerivation rec {
5 pname = "nix-bash-completions";
7 src = fetchFromGitHub {
9 repo = "nix-bash-completions";
11 sha256 = "1n5zs6xcnv4bv1hdaypmz7fv4j7dsr4a0ifah99iyj4p5j85i1bc";
15 # Fix improper escaping: https://github.com/NixOS/nixpkgs/issues/284162
17 url = "https://github.com/hedning/nix-bash-completions/pull/28/commits/ef2055aa28754fa9e009bbfebc1491972e4f4e67.patch";
18 hash = "sha256-TRkHrk7bX7DX0COzzYR+1pgTqLy7J55BcejNjRwthII=";
23 # Nix 2.4+ provides its own completion for the nix command, see https://github.com/hedning/nix-bash-completions/issues/20
24 # NixOS provides its own completions for nixos-rebuild now.
25 substituteInPlace _nix \
26 --replace 'nix nixos-option' 'nixos-option' \
27 --replace 'nixos-rebuild nixos-install' 'nixos-install'
31 # To enable lazy loading via bash-completion we need a symlink to the script
32 # from every command name.
37 function complete() { shift 2; echo "$@"; }
41 install -Dm444 -t $out/share/bash-completion/completions _nix
42 cd $out/share/bash-completion/completions
43 for c in $commands; do
51 homepage = "https://github.com/hedning/nix-bash-completions";
52 description = "Bash completions for Nix, NixOS, and NixOps";
53 license = licenses.bsd3;
54 platforms = platforms.all;
55 maintainers = with maintainers; [ hedning ncfavier ];
56 # Set a lower priority such that Nix wins in case of conflicts.