Skip to content

Commit c3c8907

Browse files
committed
feat(flake): enhance formatting capabilities with treefmt integration
Updated `flake.nix` to incorporate `treefmt-nix` for comprehensive file formatting across multiple types, including Nix, shell, Python, and more. Refined the formatter output and application setup to streamline usage, allowing users to format all files with a single command. This enhancement improves the development workflow and accessibility of formatting tools.
1 parent 0ddd124 commit c3c8907

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

flake.nix

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
inherit system;
6060
config.allowUnfree = true;
6161
};
62+
# Eval the treefmt modules from ./treefmt.nix
63+
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
6264
in {
6365
nixosConfigurations = {
6466
default = nixpkgs.lib.nixosSystem {
@@ -119,18 +121,18 @@
119121
};
120122
};
121123

122-
# Formatter output for nix formatting
123-
# Uses nixfmt (official Nix formatter, RFC-style is now default)
124-
# Reference: https://github.com/NixOS/nixfmt
125-
# Usage: nix fmt
126-
formatter.${system} = pkgs.nixfmt;
124+
# Formatter output for comprehensive formatting (all file types)
125+
# Uses treefmt-nix to format: Nix, shell, Python, YAML, JS/TS/JSON/MD, etc.
126+
# Reference: https://github.com/numtide/treefmt-nix
127+
# Usage: nix fmt (formats all file types via treefmt)
128+
formatter.${system} = treefmtEval.config.build.wrapper;
127129

128-
# treefmt configuration
130+
# treefmt app (alternative way to run treefmt)
129131
# Reference: https://github.com/numtide/treefmt-nix
130132
# Usage: nix run .#treefmt
131133
apps.${system}.treefmt = {
132134
type = "app";
133-
program = "${(treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper}/bin/treefmt";
135+
program = "${treefmtEval.config.build.wrapper}/bin/treefmt";
134136
};
135137

136138
# Development shell (minimal - use devshells for project-specific tools)
@@ -156,7 +158,7 @@
156158
echo " nh update - Update flake inputs"
157159
echo ""
158160
echo "Formatting:"
159-
echo " nix fmt - Format Nix files (single formatter)"
161+
echo " nix fmt - Format all files (via treefmt)"
160162
echo " treefmt - Format all files (multiple formatters)"
161163
echo " nix run .#treefmt - Run treefmt via flake"
162164
echo ""

0 commit comments

Comments
 (0)