Dune test output refuses to print with color in the derivation sandbox

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;
              };
          });
        }

Oddly enough, on macos it does print in color in the derivation, but it has some extra character ( (B ) appended to each colored output:

       > test single_arg_shell_single_attr ... ok(B
       >
       > thread 'single_arg_flake_multi_attr' (5459192) panicked at test_ns.rs:81:5:
       > assertion failed: false
       > note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
       > test single_arg_flake_single_attr ... ok(B
       > test single_arg_flake_multi_attr ... FAILED(B
       > test single_arg_flake_no_attr ... ok(B
       > test single_arg_shell_no_attr ... ok(B