nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildGoModule,
5 callPackages,
6 fetchFromGitHub,
7 installShellFiles,
8}:
9buildGoModule rec {
10 pname = "treefmt";
11 version = "2.4.0";
12
13 src = fetchFromGitHub {
14 owner = "numtide";
15 repo = "treefmt";
16 rev = "v${version}";
17 hash = "sha256-Okwwu5ls3BwLtm8qaq+QX3P+6uwuodV82F3j38tuszk=";
18 };
19
20 vendorHash = "sha256-fiBpyhbkzyhv7i4iHDTsgFcC/jx6onOzGP/YMcUAe9I=";
21
22 subPackages = [ "." ];
23
24 env.CGO_ENABLED = 1;
25
26 ldflags = [
27 "-s"
28 "-w"
29 "-X github.com/numtide/treefmt/v2/build.Name=treefmt"
30 "-X github.com/numtide/treefmt/v2/build.Version=v${version}"
31 ];
32
33 nativeBuildInputs = [ installShellFiles ];
34
35 postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
36 installShellCompletion --cmd treefmt \
37 --bash <($out/bin/treefmt --completion bash) \
38 --fish <($out/bin/treefmt --completion fish) \
39 --zsh <($out/bin/treefmt --completion zsh)
40 '';
41
42 passthru = {
43 inherit (callPackages ./lib.nix { })
44 evalConfig
45 withConfig
46 buildConfig
47 ;
48
49 tests = callPackages ./tests.nix { };
50
51 # Documentation for functions defined in `./lib.nix`
52 functionsDoc = callPackages ./functions-doc.nix { };
53
54 # Documentation for options declared in `treefmt.evalConfig` configurations
55 optionsDoc = callPackages ./options-doc.nix { };
56 };
57
58 meta = {
59 description = "One CLI to format the code tree";
60 longDescription = ''
61 [treefmt](${meta.homepage}) streamlines the process of applying formatters
62 to your project, making it a breeze with just one command line.
63
64 The `treefmt` package provides functions for configuring treefmt using
65 the module system, which are documented in the [treefmt section] of the
66 Nixpkgs Manual.
67
68 Alternatively, treefmt can be configured using [treefmt-nix].
69
70 [treefmt section]: https://nixos.org/manual/nixpkgs/unstable#treefmt
71 [treefmt-nix]: https://github.com/numtide/treefmt-nix
72 '';
73 homepage = "https://github.com/numtide/treefmt";
74 license = lib.licenses.mit;
75 maintainers = with lib.maintainers; [
76 brianmcgee
77 MattSturgeon
78 zimbatm
79 ];
80 mainProgram = "treefmt";
81 };
82}