mirror of
https://github.com/nix-community/comma.git
synced 2024-10-26 05:58:05 +03:00
Prefer local nix-index if present
The nix-index database offered in the derivation may be more out of date than what is present on the system. In fact, prefer any local nix-index database to the prebuilt database included with comma
This commit is contained in:
parent
4a62ec17e2
commit
60a4cf8ec5
9
,
9
,
@ -18,6 +18,13 @@ 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
|
||||
@ -25,7 +32,7 @@ case "${argv0}" in
|
||||
attr="${argv0}"
|
||||
;;
|
||||
*)
|
||||
attr="$(nix-locate --db "${NIX_INDEX_DB}" --top-level --minimal --at-root --whole-name "/bin/${argv0}")"
|
||||
attr="$(nix-locate --db "${database}" --top-level --minimal --at-root --whole-name "/bin/${argv0}")"
|
||||
if [[ "$(echo "${attr}" | wc -l)" -ne 1 ]]; then
|
||||
attr="$(echo "${attr}" | fzy)"
|
||||
fi
|
||||
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# ignore nix-build result folter
|
||||
result
|
19
default.nix
19
default.nix
@ -8,6 +8,7 @@
|
||||
, fzy ? pkgs.fzy
|
||||
, makeWrapper ? pkgs.makeWrapper
|
||||
, runCommand ? pkgs.runCommand
|
||||
, 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:
|
||||
@ -27,19 +28,17 @@ let
|
||||
|
||||
# nix-locate needs the --db argument to be a directory containing a file
|
||||
# named "files".
|
||||
nixIndexDB = runCommand "nix-index-cache" {} ''
|
||||
mkdir $out
|
||||
ln -s ${indexCache.out} $out/files
|
||||
'';
|
||||
nixIndexDB = linkFarm "nix-index-cache" [
|
||||
{ name = "files"; path = indexCache; }
|
||||
];
|
||||
|
||||
in
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
name = "comma";
|
||||
|
||||
src = ./.;
|
||||
|
||||
buildInputs = [ nix-index.out nix.out fzy.out ];
|
||||
buildInputs = [ nix-index nix fzy ];
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
installPhase = let
|
||||
@ -49,10 +48,10 @@ stdenv.mkDerivation rec {
|
||||
sed -e 's/@OVERLAY_PACKAGES@/${caseCondition}/' < , > $out/bin/,
|
||||
chmod +x $out/bin/,
|
||||
wrapProgram $out/bin/, \
|
||||
--set NIX_INDEX_DB ${nixIndexDB.out} \
|
||||
--prefix PATH : ${nix-index.out}/bin \
|
||||
--prefix PATH : ${nix.out}/bin \
|
||||
--prefix PATH : ${fzy.out}/bin
|
||||
--set PREBUILT_NIX_INDEX_DB ${nixIndexDB} \
|
||||
--prefix PATH : ${nix-index}/bin \
|
||||
--prefix PATH : ${nix}/bin \
|
||||
--prefix PATH : ${fzy}/bin
|
||||
|
||||
ln -s $out/bin/, $out/bin/comma
|
||||
'';
|
||||
|
Loading…
Reference in New Issue
Block a user