From 60a4cf8ec5c93104d3cfb9fc5a5bac8fb18cc8e4 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Thu, 13 Aug 2020 12:48:15 -0700 Subject: [PATCH] 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 --- , | 9 ++++++++- .gitignore | 2 ++ default.nix | 19 +++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 .gitignore diff --git a/, b/, index 875fa30..c67b254 100755 --- a/, +++ b/, @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf07729 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# ignore nix-build result folter +result diff --git a/default.nix b/default.nix index fc391b3..611e4ea 100644 --- a/default.nix +++ b/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 '';