From ee7b1d28e41a5ef25686ae1efc58b862e282813a Mon Sep 17 00:00:00 2001 From: Jakub Stachurski Date: Mon, 22 Dec 2025 22:57:24 +0100 Subject: Enable formatting using treefmt --- flake.nix | 31 +++++++++++++++++++++++++++++-- modules/treefmt.nix | 6 ++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 modules/treefmt.nix diff --git a/flake.nix b/flake.nix index 3a552bf..5613a2c 100644 --- a/flake.nix +++ b/flake.nix @@ -19,13 +19,40 @@ url = "github:Wilkuu-2/tatuin/flake"; inputs.nixpkgs.follows = "nixpkgs"; }; + + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = - { self, nixpkgs, nixpkgs-stable, ... }@inputs: + { self, nixpkgs, nixpkgs-stable, treefmt-nix, ... }@inputs: let + lib = nixpkgs.lib; + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + forAllSystems = f: (lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system })); + treefmtEval = forAllSystems (pkgs: treefmt-nix.lib.evalModule pkgs ./modules/treefmt.nix); + in { # packages."x86_64-linux".full-iso = self.nixosConfigurations.full-iso.config.system.build.isoImage; - formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-tree; + packages = ( + forAllSystems (pkgs: { + + }) + ); + # for `nix fmt` + formatter = ( + forAllSystems (pkgs: treefmtEval.${pkgs.stdenv.hostPlatform.system}.config.build.wrapper) + ); + # for `nix flake check` + checks = ( + forAllSystems (pkgs: { + formatting = treefmtEval.${pkgs.system}.config.build.check self; + }) + ); nixosConfigurations = { apocalypse = nixpkgs.lib.nixosSystem { diff --git a/modules/treefmt.nix b/modules/treefmt.nix new file mode 100644 index 0000000..ab36cdb --- /dev/null +++ b/modules/treefmt.nix @@ -0,0 +1,6 @@ +{pkgs, ...}: { + # Used to find the project root + projectRootFile = "flake.nix"; + programs.nixfmt.enable = true; + programs.deadnix.enable = true; +} -- cgit v1.3.1