feat: improve formatting

This commit is contained in:
Leon Schwarzäugl 2025-11-14 00:29:55 +01:00 committed by Leon Schwarzäugl
parent 4a6cbd763f
commit 47377f7a96
5 changed files with 89 additions and 6 deletions

View file

@ -561,6 +561,7 @@ A short overview over each input and what it does:
url = "github:astro/microvm.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs =
@ -1375,6 +1376,7 @@ Lastly, in the =perSystem= attribute set, we see that it is actually passed some
nixpkgs-fmt.enable = true;
statix.enable = true;
trim-trailing-whitespace.enable = true;
treefmt.enable = true;
destroyed-symlinks = {
enable = true;
@ -1583,10 +1585,32 @@ Otherwise, I define the function =mkTemplates= here which builds a named attribu
Defines a formatter that can be called using =nix flake format=. While a nice utility, I have stronger tools to perform this job.
#+begin_src nix-ts :tangle nix/formatter.nix
_:
{ inputs, ... }:
{
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem = { pkgs, ... }: {
formatter = pkgs.nixpkgs-fmt;
# formatter = pkgs.nixpkgs-fmt;
# formatter is set by treefmt to:
# formatter = lib.mkIf config.treefmt.flakeFormatter (lib.mkDefault config.treefmt.build.wrapper);
treefmt = {
projectRootFile = "flake.nix";
programs = {
nixfmt = {
enable = true;
package = pkgs.nixpkgs-fmt;
};
deadnix.enable = true;
statix.enable = true;
shellcheck.enable = true;
};
settings.formatter.shellcheck.options = [
"--shell"
"bash"
];
};
};
}
@ -22386,7 +22410,7 @@ This adds support for Terraform configuration files. I need this at work.
(add-hook 'terraform-mode-hook #'outline-minor-mode)
#+end_src
*** nixpkgs-fmt
*** nix formatting
:PROPERTIES:
:CUSTOM_ID: h:5ca7484b-b9d6-4023-88d1-a1e37d5df249
:END:

37
flake.lock generated
View file

@ -10577,6 +10577,22 @@
}
},
"nixpkgs_82": {
"locked": {
"lastModified": 1761236834,
"narHash": "sha256-+pthv6hrL5VLW2UqPdISGuLiUZ6SnAXdd2DdUE+fV2Q=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d5faa84122bc0a1fd5d378492efce4e289f8eac1",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_83": {
"locked": {
"lastModified": 1754800730,
"narHash": "sha256-HfVZCXic9XLBgybP0318ym3cDnGwBs/+H5MgxFVYF4I=",
@ -12582,6 +12598,7 @@
"swarsel-modules": "swarsel-modules_6",
"swarsel-nix": "swarsel-nix_3",
"systems": "systems_64",
"treefmt-nix": "treefmt-nix_3",
"vbc-nix": "vbc-nix_8",
"zjstatus": "zjstatus_8"
}
@ -16052,6 +16069,24 @@
"type": "github"
}
},
"treefmt-nix_3": {
"inputs": {
"nixpkgs": "nixpkgs_82"
},
"locked": {
"lastModified": 1762938485,
"narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"vbc-nix": {
"inputs": {
"nixpkgs": [
@ -16628,7 +16663,7 @@
"inputs": {
"crane": "crane_17",
"flake-utils": "flake-utils_29",
"nixpkgs": "nixpkgs_82",
"nixpkgs": "nixpkgs_83",
"rust-overlay": "rust-overlay_17"
},
"locked": {

View file

@ -102,6 +102,7 @@
url = "github:astro/microvm.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs =

View file

@ -27,6 +27,7 @@
nixpkgs-fmt.enable = true;
statix.enable = true;
trim-trailing-whitespace.enable = true;
treefmt.enable = true;
destroyed-symlinks = {
enable = true;

View file

@ -1,6 +1,28 @@
_:
{ inputs, ... }:
{
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem = { pkgs, ... }: {
formatter = pkgs.nixpkgs-fmt;
# formatter = pkgs.nixpkgs-fmt;
# formatter is set by treefmt to:
# formatter = lib.mkIf config.treefmt.flakeFormatter (lib.mkDefault config.treefmt.build.wrapper);
treefmt = {
projectRootFile = "flake.nix";
programs = {
nixfmt = {
enable = true;
package = pkgs.nixpkgs-fmt;
};
deadnix.enable = true;
statix.enable = true;
shellcheck.enable = true;
};
settings.formatter.shellcheck.options = [
"--shell"
"bash"
];
};
};
}