1 { lib, stdenv, fetchFromGitHub, makeWrapper, bat
2 # batdiff, batgrep, and batwatch
13 , withShFmt ? shfmt != null, shfmt ? null
14 , withPrettier ? nodePackages?prettier, nodePackages ? null
15 , withClangTools ? clang-tools != null, clang-tools ? null
16 , withRustFmt ? rustfmt != null, rustfmt ? null
18 , withEntr ? entr != null, entr ? null
21 , withDelta ? delta != null, delta ? null
27 # Core derivation that all the others are based on.
28 # This includes the complete source so the per-script derivations can run the tests.
29 core = stdenv.mkDerivation rec {
31 version = "2021.04.06";
33 src = fetchFromGitHub {
37 sha256 = "sha256-MphI2n+oHZrw8bPohNGeGdST5LS1c6s/rKqtpcR9cLo=";
38 fetchSubmodules = true;
41 # bat needs to be in the PATH during building so EXECUTABLE_BAT picks it up
42 nativeBuildInputs = [ bat ];
47 patchShebangs --build test.sh test/shimexec .test-framework/bin/best.sh
52 bash ./build.sh --minify=none --no-verify
56 # Run the library tests as they don't have external dependencies
58 checkInputs = [ bash fish zsh ] ++ (lib.optionals stdenv.isDarwin [ getconf ]);
61 # test list repeats suites. Unique them
62 declare -A test_suites
63 while read -r action arg _; do
64 [[ "$action" == "test_suite" && "$arg" == lib_* ]] &&
65 test_suites+=(["$arg"]=1)
66 done <<<"$(./test.sh --compiled --list --porcelain)"
67 (( ''${#test_suites[@]} != 0 )) || {
68 echo "Couldn't find any library test suites"
71 ./test.sh --compiled $(printf -- "--suite %q\n" "''${!test_suites[@]}")
81 # A few random files have shebangs. Don't patch them, they don't make it into the final output.
82 # The per-script derivations will go ahead and patch the files they actually install.
83 dontPatchShebangs = true;
86 description = "Bash scripts that integrate bat with various command line tools";
87 homepage = "https://github.com/eth-p/bat-extras";
88 license = with licenses; [ mit ];
89 maintainers = with maintainers; [ bbigras lilyball ];
90 platforms = platforms.all;
94 name: # the name of the script
95 dependencies: # the tools we need to prefix onto PATH
97 pname = "${core.pname}-${name}";
98 inherit (core) version;
102 nativeBuildInputs = [ makeWrapper ];
103 # Make the dependencies available to the tests.
104 buildInputs = dependencies;
106 # Patch shebangs now because our tests rely on them
108 patchShebangs --host bin/${name}
111 dontConfigure = true;
112 dontBuild = true; # we've already built
115 checkInputs = [ bash fish zsh ] ++ (lib.optionals stdenv.isDarwin [ getconf ]);
118 bash ./test.sh --compiled --suite ${name}
125 cp -p bin/${name} $out/bin/${name}
126 '' + lib.optionalString (dependencies != []) ''
127 wrapProgram $out/bin/${name} \
128 --prefix PATH : ${lib.makeBinPath dependencies}
134 dontPatchShebangs = true;
138 optionalDep = cond: dep:
139 assert cond -> dep != null;
140 lib.optional cond dep;
143 batdiff = script "batdiff" ([ less coreutils gitMinimal ] ++ optionalDep withDelta delta);
144 batgrep = script "batgrep" [ less coreutils ripgrep ];
145 batman = script "batman" [ util-linux ];
146 batpipe = script "batpipe" [ less ];
147 batwatch = script "batwatch" ([ less coreutils ] ++ optionalDep withEntr entr);
148 prettybat = script "prettybat" ([]
149 ++ optionalDep withShFmt shfmt
150 ++ optionalDep withPrettier nodePackages.prettier
151 ++ optionalDep withClangTools clang-tools
152 ++ optionalDep withRustFmt rustfmt);