Files
Matt Sturgeon 134bfa753c treefmt.withConfig: add check function
Inspired by treefmt-nix's `config.build.check` option, add a similar
check function to `treefmt.withConfig`'s wrapper.

`check` is a function of `Path → Derivation`, which returns a derivation
that builds ok when the path is already formatted, or fails to build if
the wrapped-treefmt would change the path's formatting.

Add the `check` function, tests for it, and initial docs.

See treefmt-nix: https://github.com/numtide/treefmt-nix/blob/db947814/module-options.nix#L301-L349
2026-06-09 07:37:38 +01:00

41 lines
892 B
Nix

{
lib,
pkgs,
config,
options,
...
}:
{
options.result = lib.mkOption {
type = lib.types.package;
description = ''
The wrapped treefmt package.
'';
readOnly = true;
internal = true;
};
config.result = pkgs.symlinkJoin (finalAttrs: {
pname = config.name;
inherit (config.package) meta version;
nativeBuildInputs = [ pkgs.makeBinaryWrapper ];
paths = [ config.package ];
env = {
inherit (config) configFile;
binPath = lib.makeBinPath config.runtimeInputs;
};
passthru = {
inherit (config) runtimeInputs;
inherit config options;
check = pkgs.callPackage ../check-wrapper.nix {
wrapper = finalAttrs.finalPackage;
};
};
postBuild = ''
wrapProgram "$out/bin/treefmt" \
--prefix PATH : "$binPath" \
--add-flags "--config-file $configFile"
'';
});
}