7 # batdiff, batgrep, and batwatch
18 withShFmt ? shfmt != null,
20 withPrettier ? nodePackages ? prettier,
22 withClangTools ? clang-tools != null,
24 withRustFmt ? rustfmt != null,
27 withEntr ? entr != null,
31 withDelta ? delta != null,
38 # Core derivation that all the others are based on.
39 # This includes the complete source so the per-script derivations can run the tests.
40 core = stdenv.mkDerivation rec {
42 version = "2024.07.10";
44 src = fetchFromGitHub {
48 hash = "sha256-6IRAKSy5f/WcQZBcJKVSweTjHLznzdxhsyx074bXnUQ=";
49 fetchSubmodules = true;
52 # bat needs to be in the PATH during building so EXECUTABLE_BAT picks it up
53 nativeBuildInputs = [ bat ];
58 patchShebangs --build test.sh test/shimexec .test-framework/bin/best.sh
63 bash ./build.sh --minify=none --no-verify
67 # Run the library tests as they don't have external dependencies
73 ] ++ (lib.optionals stdenv.hostPlatform.isDarwin [ getconf ]);
76 # test list repeats suites. Unique them
77 declare -A test_suites
78 while read -r action arg _; do
79 [[ "$action" == "test_suite" && "$arg" == lib_* ]] &&
80 test_suites+=(["$arg"]=1)
81 done <<<"$(./test.sh --compiled --list --porcelain)"
82 (( ''${#test_suites[@]} != 0 )) || {
83 echo "Couldn't find any library test suites"
86 ./test.sh --compiled $(printf -- "--suite %q\n" "''${!test_suites[@]}")
96 # A few random files have shebangs. Don't patch them, they don't make it into the final output.
97 # The per-script derivations will go ahead and patch the files they actually install.
98 dontPatchShebangs = true;
101 description = "Bash scripts that integrate bat with various command line tools";
102 homepage = "https://github.com/eth-p/bat-extras";
103 license = with licenses; [ mit ];
104 maintainers = with maintainers; [ bbigras ];
105 platforms = platforms.all;
109 name: # the name of the script
110 dependencies: # the tools we need to prefix onto PATH
111 stdenv.mkDerivation {
113 inherit (core) version;
117 nativeBuildInputs = [ makeWrapper ];
118 # Make the dependencies available to the tests.
119 buildInputs = dependencies;
121 # Patch shebangs now because our tests rely on them
123 patchShebangs --host bin/${name}
126 dontConfigure = true;
127 dontBuild = true; # we've already built
130 nativeCheckInputs = [
135 ] ++ (lib.optionals stdenv.hostPlatform.isDarwin [ getconf ]);
138 bash ./test.sh --compiled --suite ${name}
146 cp -p bin/${name} $out/bin/${name}
148 + lib.optionalString (dependencies != [ ]) ''
149 wrapProgram $out/bin/${name} \
150 --prefix PATH : ${lib.makeBinPath dependencies}
157 dontPatchShebangs = true;
159 meta = core.meta // {
165 assert cond -> dep != null;
166 lib.optional cond dep;
169 batdiff = script "batdiff" (
175 ++ optionalDep withDelta delta
177 batgrep = script "batgrep" [
182 batman = script "batman" (lib.optionals stdenv.hostPlatform.isLinux [ util-linux ]);
183 batpipe = script "batpipe" [ less ];
184 batwatch = script "batwatch" (
189 ++ optionalDep withEntr entr
191 prettybat = script "prettybat" (
193 ++ optionalDep withShFmt shfmt
194 ++ optionalDep withPrettier nodePackages.prettier
195 ++ optionalDep withClangTools clang-tools
196 ++ optionalDep withRustFmt rustfmt