#!/bin/bash | |
# | |
# usage example: | |
# $ , yarn --help | |
# This finds a derivation providing a bin/yarn, and runs it with `nix run`. | |
# If there are multiple candidates, the user chooses one using `fzy`. | |
set -euo pipefail | |
if [[ $# -lt 1 ]]; then | |
>&2 echo "usage: , <program> [arguments]" | |
exit 1 | |
fi | |
argv0=$1; shift | |
attr="$(nix-locate --top-level --minimal --at-root --whole-name "/bin/${argv0}")" | |
if [[ "$(echo "${attr}" | wc -l)" -ne 1 ]]; then | |
attr="$(echo "${attr}" | fzy)" | |
fi | |
nix run "nixpkgs.${attr}" -c "${argv0}" "$@" |
{ stdenv, fetchurl, nix-index, nix, fzy, makeWrapper }: | |
stdenv.mkDerivation rec { | |
name = "comma"; | |
src = ./.; | |
buildInputs = [ nix-index.out nix.out fzy.out ]; | |
nativeBuildInputs = [ makeWrapper ]; | |
installPhase = '' | |
mkdir -p $out/bin | |
cp , $out/bin/, | |
chmod +x $out/bin/, | |
wrapProgram $out/bin/, \ | |
--prefix PATH : ${nix-index.out}/bin \ | |
--prefix PATH : ${nix.out}/bin \ | |
--prefix PATH : ${fzy.out}/bin | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment