base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / pkgs / by-name / ni / nix-bash-completions / package.nix
blob10fb097fd2c8ed08dec3cc5bda60845457d34886
1 { lib, stdenv, fetchFromGitHub, fetchpatch }:
3 stdenv.mkDerivation rec {
4   version = "0.6.8";
5   pname = "nix-bash-completions";
7   src = fetchFromGitHub {
8     owner = "hedning";
9     repo = "nix-bash-completions";
10     rev = "v${version}";
11     sha256 = "1n5zs6xcnv4bv1hdaypmz7fv4j7dsr4a0ifah99iyj4p5j85i1bc";
12   };
14   patches = [
15     # Fix improper escaping: https://github.com/NixOS/nixpkgs/issues/284162
16     (fetchpatch {
17       url = "https://github.com/hedning/nix-bash-completions/pull/28/commits/ef2055aa28754fa9e009bbfebc1491972e4f4e67.patch";
18       hash = "sha256-TRkHrk7bX7DX0COzzYR+1pgTqLy7J55BcejNjRwthII=";
19     })
20   ];
22   postPatch = ''
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'
28   '';
30   strictDeps = true;
31   # To enable lazy loading via bash-completion we need a symlink to the script
32   # from every command name.
33   installPhase = ''
34     runHook preInstall
36     commands=$(
37       function complete() { shift 2; echo "$@"; }
38       shopt -s extglob
39       source _nix
40     )
41     install -Dm444 -t $out/share/bash-completion/completions _nix
42     cd $out/share/bash-completion/completions
43     for c in $commands; do
44       ln -s _nix $c
45     done
47     runHook postInstall
48   '';
50   meta = with lib; {
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.
57     priority = 10;
58   };