Merge pull request #18 from nix-community/remove-prebuilt

remove prebuilt cache
This commit is contained in:
Artturi 2022-04-17 16:28:48 +03:00 committed by GitHub
commit 10ba38ddd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 79 deletions

12
,
View File

@ -25,20 +25,10 @@ fi
if [[ "$1" == "--install" ]] || [[ "$1" == "-i" ]]; then
install=1
shift
elif [[ "$1" == "--update" ]] || [[ "$1" == "-u" ]]; then
${UPDATE_SCRIPT}
exit
else
install=""
fi
# if a nix-index exists locally; use that as it's likely much more recent
# than the prebuilt one.
database=$PREBUILT_NIX_INDEX_DB
if [ -f "${HOME}/.cache/nix-index/files" ]; then
database="${HOME}/.cache/nix-index"
fi
argv0=$1; shift
case "${argv0}" in
@ -46,7 +36,7 @@ case "${argv0}" in
attr="${argv0}"
;;
*)
attr="$(nix-locate --db "${database}" --top-level --minimal --at-root --whole-name "/bin/${argv0}")"
attr="$(nix-locate --top-level --minimal --at-root --whole-name "/bin/${argv0}")"
if [[ "$(echo "${attr}" | wc -l)" -ne 1 ]]; then
attr="$(echo "${attr}" | "${picker}")"
fi

View File

@ -19,3 +19,8 @@ YouTube](https://www.youtube.com/watch?v=VUM3Km_4gUg&list=PLRGI9KQ3_HP_OFRG6R-p4
```bash
, cowsay neato
```
## Prebuilt index
https://github.com/Mic92/nix-index-database

View File

@ -3,13 +3,9 @@
, stdenv ? pkgs.stdenv
, lib ? pkgs.lib
, fetchurl ? pkgs.fetchurl
, nix-index ? pkgs.nix-index
, nix ? pkgs.nix
, fzy ? pkgs.fzy
, makeWrapper ? pkgs.makeWrapper
, runCommand ? pkgs.runCommand
, updateScript ? import ./update-index.nix { inherit pkgs; }
, linkFarm ? pkgs.linkFarm
# We use this to add matchers for stuff that's not in upstream nixpkgs, but is
# in our own overlay. No fuzzy matching from multiple options here, it's just:
@ -17,36 +13,11 @@
, overlayPackages ? []
}:
let
indexCaches = {
x86_64-linux = fetchurl {
url = "https://github.com/Mic92/nix-index-database/releases/download/2021-12-12/index-x86_64-linux";
hash = "sha256-+SoG5Qz2KWA/nIWXE6SLpdi8MDqTs8LY90fGZxGKOiA=";
};
x86_64-darwin = fetchurl {
url = "https://github.com/Mic92/nix-index-database/releases/download/2022-02-27/index-x86_64-darwin";
hash = "sha256-sHGUSjd6EOpzdWtS5FGtTkS9KEKvDCGMHTYVwxOkZIo=";
};
};
# nix-index takes a little while to run and the contents don't change
# meaningfully very often.
indexCache = indexCaches.${stdenv.hostPlatform.system} or (throw "unsupported system: ${stdenv.hostPlatform.system}");
# nix-locate needs the --db argument to be a directory containing a file
# named "files".
nixIndexDB = linkFarm "nix-index-cache" [
{ name = "files"; path = indexCache; }
];
in
stdenv.mkDerivation rec {
name = "comma";
src = ./.;
buildInputs = [ nix-index nix fzy ];
nativeBuildInputs = [ makeWrapper ];
installPhase = let
@ -56,10 +27,6 @@ stdenv.mkDerivation rec {
sed -e 's/@OVERLAY_PACKAGES@/${caseCondition}/' < , > $out/bin/,
chmod +x $out/bin/,
wrapProgram $out/bin/, \
--set PREBUILT_NIX_INDEX_DB ${nixIndexDB} \
--set NIXPKGS ${pkgs.path} \
--set UPDATE_SCRIPT ${updateScript} \
--prefix PATH : ${nix-index}/bin \
--prefix PATH : ${nix}/bin \
--prefix PATH : ${fzy}/bin

View File

@ -19,18 +19,10 @@
(system: pkgs: {
comma = import ./default.nix {
inherit pkgs;
updateScript = apps."${system}".update-index.program;
};
});
defaultPackage = forAllSystems (system: pkgs: packages."${system}".comma);
apps = forAllSystems
(system: pkgs: {
update-index = {
type = "app";
program = b.toString (pkgs.callPackage ./update-index.nix {});
};
});
};
}

View File

@ -1,27 +0,0 @@
{
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
''