diff --git a/SwarselSystems.org b/SwarselSystems.org index b61752f..5acc547 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -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: diff --git a/flake.lock b/flake.lock index 10b1bfe..2c8ba1c 100644 --- a/flake.lock +++ b/flake.lock @@ -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": { diff --git a/flake.nix b/flake.nix index 065ad8b..363b431 100644 --- a/flake.nix +++ b/flake.nix @@ -102,6 +102,7 @@ url = "github:astro/microvm.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + treefmt-nix.url = "github:numtide/treefmt-nix"; }; outputs = diff --git a/nix/devshell.nix b/nix/devshell.nix index a32661b..8d8274c 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -27,6 +27,7 @@ nixpkgs-fmt.enable = true; statix.enable = true; trim-trailing-whitespace.enable = true; + treefmt.enable = true; destroyed-symlinks = { enable = true; diff --git a/nix/formatter.nix b/nix/formatter.nix index c00f3f2..cf3ce6a 100644 --- a/nix/formatter.nix +++ b/nix/formatter.nix @@ -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" + ]; + }; }; }