From cef3aefabb4ece8eda69c2dc7a35affc36e2cba2 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 28 Sep 2024 23:32:25 +0300 Subject: [PATCH] flake: add formatting check --- flake.nix | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 4813481..987e3e5 100644 --- a/flake.nix +++ b/flake.nix @@ -13,8 +13,8 @@ inherit inputs; specialArgs = {inherit lib;}; } { - # provide overridable systems - # https://github.com/nix-systems/nix-systems + # Allow users to bring their own systems. + # «https://github.com/nix-systems/nix-systems» systems = import inputs.systems; imports = [ ./flake/apps.nix @@ -62,7 +62,6 @@ pkgs, ... }: { - formatter = pkgs.alejandra; devShells = { default = self'.devShells.lsp; nvim-nix = pkgs.mkShell {packages = [config.packages.nix];}; @@ -70,6 +69,21 @@ packages = with pkgs; [nil statix deadnix alejandra]; }; }; + + # Provide the default formatter. `nix fmt` in project root + # will format available files with the correct formatter. + # P.S: Please do not format with nixfmt! It messes with many + # syntax elements and results in unreadable code. + formatter = pkgs.alejandra; + + # Check if codebase is properly formatted. + # This can be initiated with `nix build .#checks..nix-fmt` + # or with `nix flake check` + checks = { + nix-fmt = pkgs.runCommand "nix-fmt-check" {nativeBuildInputs = [pkgs.alejandra];} '' + alejandra --check ${self} < /dev/null | tee $out + ''; + }; }; };