#──────────────────────────────────────────────────────────────────────────────┐
# SPDX-FileCopyrightText: 2026 toastal <https://toast.al/contact/>             │
# SPDX-License-Identifier: LGPL-2.1-or-later                                   │
#──────────────────────────────────────────────────────────────────────────────┘
{
   lib,
   makeBinaryWrapper,
   stdenvNoCC,
   topiary,
   writeText,
}:

let
   cfg = writeText "topairy-cfg.ncl" /* nickel */ ''
      {
      	languages = {
      		bash.indent | priority 1 = "	",
      		css.indent | priority 1 = "	",
      		json.indent | priority 1 = "	",
      		nickel.indent | priority 1 = "	",
      		ocaml.indent | priority 1 = "	",
      		ocaml_interface.indent | priority 1 = "	",
      		ocamllex.indent | priority 1 = "	",
      		openscad.indent | priority 1 = "	",
      		rust.indent | priority 1 = "	",
      		sdml.indent | priority 1 = "	",
      		toml.indent | priority 1 = "	",
      	},
      }
   '';
in
stdenvNoCC.mkDerivation {
   name = "topiary";

   preferLocalBuild = true;

   nativeBuildInputs = [ makeBinaryWrapper ];

   dontUnpack = true;

   installPhase = ''
      mkdir -p "$out/bin"
      makeBinaryWrapper "${lib.getExe topiary}" "$out/bin/topiary" \
         --add-flags "-M -C ${cfg}"
      cp -Tr "${topiary}/share" "$out/share"
   '';

   meta = {
      description = "Topiary with a tab-indented config";
   };
}
