#──────────────────────────────────────────────────────────────────────────────┐
# SPDX-FileCopyrightText: 2026 toastal <https://toast.al/contact/>             │
# SPDX-License-Identifier: MPL-2.0                                             │
#──────────────────────────────────────────────────────────────────────────────┘
{
   lib,
   makeBinaryWrapper,
   stdenvNoCC,
   nixfmt,
}:

stdenvNoCC.mkDerivation {
   name = "nixfmt";

   preferLocalBuild = true;

   nativeBuildInputs = [ makeBinaryWrapper ];

   dontUnpack = true;

   installPhase = ''
      mkdir -p "$out/bin"
      makeBinaryWrapper "${lib.getExe nixfmt}" "$out/bin/nixfmt" \
         --add-flags "--indent=3"
      cp -Tr "${nixfmt}/share" "$out/share"
   '';

   meta = {
      mainProgram = "nixfmt";
      description = "nixfmt, but with 3-space indentation";
      longDescription = ''
         I don’t like *this* formatter, but it is *a* formatter. Tweaking it to
         expand to 3 spaces, helps the maker actually read the code since 2
         spaces is not enough contrast (& Nix magic strings don’t support tabs).
      '';
   };
}
