Howdy, I have this setup where I’m using dune to invoke rustc to take advantage of rust’s test system. It works really well actually aside from the color output. I have set CLICOLOR_FORCE=1 in the env of buildDunePackage, but it still refuses. On my terminal, it works fine, and prints the expected colored output. All other things print in color correctly, as well.
Here is the code:
{
default = buildDunePackage (finalAttrs: {
inherit (dune-project) version;
pname = dune-project.package.name;
src = cleanSource ./.;
buildInputs = attrValues (depends // {
inherit cmdliner;
});
doCheck = true;
nativeCheckInputs = attrValues {
inherit (pkgs) ocamlformat;
inherit (pkgs) rustc rustfmt;
};
CLICOLOR_FORCE = 1;
checkPhase = ''
red() {
printf "\033[1;31m%s\033[0m" "$*"
}
if ! diff --color=always "${finalAttrs.src}/${dune-project.name}.opam" "./${dune-project.name}.opam"; then
printf "\n"
printf "$(red "Error:") Generated opam file does not match provided opam file\n"
exit 1
fi
if ! dune fmt --diff-command="diff --color=always"; then
printf "\n"
printf "$(red "Error:") Some OCaml files are not properly formatted\n"
exit 1
fi
if ! rustfmt --check --color=always "${finalAttrs.src}/test/test_ns.rs"; then
printf "\n"
printf "$(red "Error:") test.rs is not properly formatted\n"
exit 1
fi
if ! dune test --force --no-buffer; then
printf "\n"
printf "$(red "Error:") dune test reported test failures\n"
exit 1
fi
'';
postInstall = ''
${cmdliner}/bin/cmdliner install tool-support $out/bin/ns $out
${cmdliner}/bin/cmdliner install generic-completion $out/share
'';
meta =
let
inherit (dune-project.source) type owner repo;
maintainers = map (m: pkgs.lib.maintainers.${(elemAt (split " " m) 0)}) dune-project.maintainers;
in
{
inherit maintainers;
description = dune-project.package.synopsis;
longDescription = dune-project.package.description;
homepage = "https://${type}.com/${owner}/${repo}";
license = getLicenseFromSpdxId dune-project.license;
};
});
}