comma/update-index.nix
2022-03-22 06:44:06 +01:00

28 lines
556 B
Nix

{
pkgs ? import <nixpkgs> {},
coreutils ? pkgs.coreutils,
gnugrep ? pkgs.gnugrep,
lib ? pkgs.lib,
nix-index ? pkgs.nix-index,
writeScript ? pkgs.writeScript,
}:
writeScript "update-index" ''
PATH=${lib.makeBinPath [
coreutils
gnugrep
nix-index
]}
# on flake based installations nixpkgs is specified via
# flake input and therefore NIX_PATH might be unset
if echo $NIX_PATH | grep -q "nixpkgs="; then
nixpkgs=""
else
nixpkgs="-I nixpkgs=${pkgs.path}"
fi
nix-index -d $HOME/.cache/nix-index -f $nixpkgs
''