comma/default.nix
Burke Libbey 0c6fcf3405 ,q
2020-05-02 14:17:19 -04:00

58 lines
1.6 KiB
Nix

{ pkgs ? import <nixpkgs> { }
, stdenv ? pkgs.stdenv
, lib ? pkgs.lib
, fetchurl ? pkgs.fetchurl
, nix-index ? pkgs.nix-index
, nix ? pkgs.nix
, ruby ? pkgs.ruby
, fzf ? pkgs.fzf
, makeWrapper ? pkgs.makeWrapper
, runCommand ? pkgs.runCommand
# 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:
# Was the command `, mything`? Run `nixpkgs.mything`.
, overlayPackages ? []
}:
let
# nix-index takes a little while to run and the contents don't change
# meaningfully very often. This is generated by running `nix-index` and
# uploading `~/.cache/nix-index/files` to, well, anywhere.
indexCache = fetchurl {
url = "https://s3.amazonaws.com/burkelibbey/nix-index-files";
sha256 = "06p58f82wipd0a8wbc7j3l0p8iaxvdibgshmc9dbxkjf0hmln3kx";
};
# 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
'';
in
stdenv.mkDerivation rec {
name = "comma";
src = ./.;
buildInputs = [ nix-index nix fzf ];
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out/bin
sed \
-e 's|#!ruby|#!${ruby}/bin/ruby|' \
-e 's|@PATH_PREPEND@|${lib.makeBinPath buildInputs}|' \
-e 's|@NIX_INDEX_DB@|${nixIndexDB}|' \
-e 's|@OVERLAY_PACKAGES@|${lib.concatStringsSep ":" overlayPackages}|' \
< , > $out/bin/,
chmod +x $out/bin/,
${ruby}/bin/ruby install-symlinks $out/bin
'';
}