From 002c74ca1bff4e7d13a4b76242aae2bb985aeb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Tue, 15 Oct 2024 22:05:55 +0200 Subject: [PATCH] feat(flake): switch to treefmt-nix This allows me to remove all checks and replace them with treefmt-nix --- flake-modules/checks.nix | 26 -------------------------- flake-modules/default.nix | 17 +++++++++++++---- flake.lock | 6 ++++-- flake.nix | 5 +++++ 4 files changed, 22 insertions(+), 32 deletions(-) delete mode 100644 flake-modules/checks.nix diff --git a/flake-modules/checks.nix b/flake-modules/checks.nix deleted file mode 100644 index 206d2e0..0000000 --- a/flake-modules/checks.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ lib, ... }: -{ - perSystem = - { pkgs, self', ... }: - { - checks = - let - src = builtins.path { - path = ../.; - name = "configuration.nix"; - }; - runCmdInSrc = - name: cmd: - pkgs.runCommandNoCC name { } '' - cd ${src} - ${cmd} - mkdir $out - ''; - in - { - fmt = runCmdInSrc "fmt-src" "${lib.getExe self'.formatter} --check ."; - lint = runCmdInSrc "lint-src" "${lib.getExe pkgs.statix} check ."; - typos = runCmdInSrc "typos-src" "${lib.getExe pkgs.typos} ."; - }; - }; -} diff --git a/flake-modules/default.nix b/flake-modules/default.nix index f028f92..050721e 100644 --- a/flake-modules/default.nix +++ b/flake-modules/default.nix @@ -4,7 +4,8 @@ let in { imports = [ - ./checks.nix + inputs.treefmt-nix.flakeModule + ./devshells.nix ./docs.nix ./example-vm.nix @@ -15,11 +16,19 @@ in ]; perSystem = - { system, pkgs, ... }: + { system, ... }: { _module.args.pkgs = import inputs.nixpkgs { inherit system overlays; }; - # Nix files formatter (run `nix fmt`) - formatter = pkgs.nixfmt-rfc-style; + # Setup formatters + treefmt = { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + rustfmt.enable = true; + statix.enable = true; + typos.enable = true; + }; + }; }; } diff --git a/flake.lock b/flake.lock index d5c5661..caefd60 100644 --- a/flake.lock +++ b/flake.lock @@ -289,7 +289,9 @@ "unstable" ], "nuschtosSearch": [], - "treefmt-nix": "treefmt-nix" + "treefmt-nix": [ + "treefmt-nix" + ] }, "locked": { "lastModified": 1728829992, @@ -314,6 +316,7 @@ "nixvim": "nixvim", "stylix": "stylix", "systems": "systems", + "treefmt-nix": "treefmt-nix", "unstable": "unstable" } }, @@ -368,7 +371,6 @@ "treefmt-nix": { "inputs": { "nixpkgs": [ - "nixvim", "nixpkgs" ] }, diff --git a/flake.nix b/flake.nix index 31cb5e1..1b963db 100644 --- a/flake.nix +++ b/flake.nix @@ -35,6 +35,7 @@ nixpkgs.follows = "unstable"; home-manager.follows = "home-manager"; flake-parts.follows = "flake-parts"; + treefmt-nix.follows = "treefmt-nix"; # disable optional inputs flake-compat.follows = ""; nix-darwin.follows = ""; @@ -47,6 +48,10 @@ url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; # For deduplication systems.url = "github:nix-systems/default"; };