Skip to content

Instantly share code, notes, and snippets.

@burke
Created December 16, 2019 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burke/922f495d1d18ce826a47f1ab075123f1 to your computer and use it in GitHub Desktop.
Save burke/922f495d1d18ce826a47f1ab075123f1 to your computer and use it in GitHub Desktop.
#!/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