nixpkgs/pkgs/tools/misc/bat-extras/default.nix

146 lines
4.4 KiB
Nix
Raw Normal View History

{ lib, stdenv, callPackage, fetchFromGitHub, bash, makeWrapper, bat
2020-06-18 01:03:03 +02:00
# batdiff, batgrep, and batwatch
, coreutils
2020-04-25 05:23:59 +02:00
, less
# batgrep
, ripgrep
# prettybat
, withShFmt ? shfmt != null, shfmt ? null
, withPrettier ? nodePackages?prettier, nodePackages ? null
, withClangTools ? clang-tools != null, clang-tools ? null
, withRustFmt ? rustfmt != null, rustfmt ? null
# batwatch
, withEntr ? entr != null, entr ? null
2020-06-18 01:03:03 +02:00
# batdiff
, gitMinimal
, withDelta ? delta != null, delta ? null
2020-06-18 01:03:03 +02:00
}:
2020-04-25 05:23:59 +02:00
let
# Core derivation that all the others are based on.
# This includes the complete source so the per-script derivations can run the tests.
core = stdenv.mkDerivation rec {
pname = "bat-extras";
2020-06-18 01:03:03 +02:00
# there hasn't been a release since 2020-05-01 but there are important bugfixes
# to the test suite so we'll pull the latest commit as of 2020-06-17.
version = "20200515-dev"; # latest commit was dated 2020-05-15
2020-04-25 05:23:59 +02:00
src = fetchFromGitHub {
owner = "eth-p";
repo = pname;
2020-06-18 01:03:03 +02:00
rev = "3029b6749f61f7514e9eef30e035cfab0e31eb1d";
sha256 = "08mb94k2n182ql97c5s5j1v7np25ivynn5g0418whrx11ra41wr7";
2020-04-25 05:23:59 +02:00
fetchSubmodules = true;
};
2020-06-18 01:03:03 +02:00
# bat needs to be in the PATH during building so EXECUTABLE_BAT picks it up
nativeBuildInputs = [ bash bat ];
2020-04-25 05:23:59 +02:00
dontConfigure = true;
postPatch = ''
patchShebangs --build test.sh test/shimexec .test-framework/bin/best.sh
'';
buildPhase = ''
runHook preBuild
bash ./build.sh --minify=none --no-verify
runHook postBuild
'';
# Run the library tests as they don't have external dependencies
doCheck = true;
checkPhase = ''
runHook preCheck
# test list repeats suites. Unique them
declare -A test_suites
while read -r action arg _; do
[[ "$action" == "test_suite" && "$arg" == lib_* ]] &&
test_suites+=(["$arg"]=1)
done <<<"$(bash ./test.sh --compiled --list --porcelain)"
(( ''${#test_suites[@]} != 0 )) || {
echo "Couldn't find any library test suites"
exit 1
}
bash ./test.sh --compiled $(printf -- "--suite %q\n" "''${!test_suites[@]}")
runHook postCheck
'';
installPhase = ''
runHook preInstall
cp -a . $out
runHook postInstall
'';
# A few random files have shebangs. Don't patch them, they don't make it into the final output.
# The per-script derivations will go ahead and patch the files they actually install.
dontPatchShebangs = true;
meta = with lib; {
2020-04-25 05:23:59 +02:00
description = "Bash scripts that integrate bat with various command line tools";
homepage = "https://github.com/eth-p/bat-extras";
license = with licenses; [ mit ];
maintainers = with maintainers; [ bbigras lilyball ];
platforms = platforms.all;
};
};
script =
name: # the name of the script
dependencies: # the tools we need to prefix onto PATH
stdenv.mkDerivation {
pname = "${core.pname}-${name}";
inherit (core) version;
src = core;
nativeBuildInputs = [ bash makeWrapper ];
# Make the dependencies available to the tests.
buildInputs = dependencies;
# Patch shebangs now because our tests rely on them
postPatch = ''
patchShebangs --host bin/${name}
'';
dontConfigure = true;
dontBuild = true; # we've already built
doCheck = true;
checkPhase = ''
runHook preCheck
bash ./test.sh --compiled --suite ${name}
runHook postCheck
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp -p bin/${name} $out/bin/${name}
2021-01-15 10:19:50 +01:00
'' + lib.optionalString (dependencies != []) ''
2020-04-25 05:23:59 +02:00
wrapProgram $out/bin/${name} \
2021-01-15 10:19:50 +01:00
--prefix PATH : ${lib.makeBinPath dependencies}
2020-04-25 05:23:59 +02:00
'' + ''
runHook postInstall
'';
# We already patched
dontPatchShebangs = true;
inherit (core) meta;
};
optionalDep = cond: dep:
assert cond -> dep != null;
2021-01-15 10:19:50 +01:00
lib.optional cond dep;
2020-04-25 05:23:59 +02:00
in
{
batdiff = script "batdiff" ([ less coreutils gitMinimal ] ++ optionalDep withDelta delta);
2020-06-18 01:03:03 +02:00
batgrep = script "batgrep" [ less coreutils ripgrep ];
batman = script "batman" [];
batwatch = script "batwatch" ([ less coreutils ] ++ optionalDep withEntr entr);
prettybat = script "prettybat" ([]
2020-04-25 05:23:59 +02:00
++ optionalDep withShFmt shfmt
++ optionalDep withPrettier nodePackages.prettier
++ optionalDep withClangTools clang-tools
2020-06-18 01:03:03 +02:00
++ optionalDep withRustFmt rustfmt);
2020-04-25 05:23:59 +02:00
}