From e29ea4efb08d01bf64948370810a7963e7b72c5f Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 20 Aug 2024 03:16:32 -0400 Subject: [PATCH] build(nix): add formatting checks Signed-off-by: seth --- flake.nix | 21 +++++++++++++++++---- nix/checks.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 nix/checks.nix diff --git a/flake.nix b/flake.nix index 24227aca7..2fe36902a 100644 --- a/flake.nix +++ b/flake.nix @@ -54,6 +54,14 @@ nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); in { + checks = forAllSystems ( + system: + let + checks' = nixpkgsFor.${system}.callPackage ./nix/checks.nix { inherit self; }; + in + lib.filterAttrs (_: lib.isDerivation) checks' + ); + devShells = forAllSystems ( system: let @@ -88,12 +96,17 @@ let pkgs = nixpkgsFor.${system}; + # Build a scope from our overlay prismPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs); + + # Grab our packages from it and set the default + packages = { + inherit (prismPackages) prismlauncher-unwrapped prismlauncher; + default = prismPackages.prismlauncher; + }; in - { - inherit (prismPackages) prismlauncher-unwrapped prismlauncher; - default = prismPackages.prismlauncher; - } + # Only output them if they're available on the current system + lib.filterAttrs (_: lib.meta.availableOn pkgs.stdenv.hostPlatform) packages ); }; } diff --git a/nix/checks.nix b/nix/checks.nix new file mode 100644 index 000000000..40a2e272f --- /dev/null +++ b/nix/checks.nix @@ -0,0 +1,42 @@ +{ + runCommand, + deadnix, + llvmPackages_18, + markdownlint-cli, + nixfmt-rfc-style, + statix, + self, +}: +{ + formatting = + runCommand "check-formatting" + { + nativeBuildInputs = [ + deadnix + llvmPackages_18.clang-tools + markdownlint-cli + nixfmt-rfc-style + statix + ]; + } + '' + cd ${self} + + echo "Running clang-format...." + clang-format -i --style='file' --Werror */**.{c,cc,cpp,h,hh,hpp} + + echo "Running deadnix..." + deadnix --fail + + echo "Running markdownlint..." + markdownlint --dot . + + echo "Running nixfmt..." + nixfmt --check . + + echo "Running statix" + statix check . + + touch $out + ''; +}