From 4d3bd5338fe9e959a5861f740bd92a34b355feb3 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Mon, 16 Dec 2024 20:54:28 +0900 Subject: [PATCH] nix: implement flake checks Signed-off-by: Ophestra Umiker --- flake.nix | 48 +++++++++++++++++++++++++++++++++++++++++++++++- nixos.nix | 1 - options.nix | 1 - 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 52757a1..7418c97 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,52 @@ { nixosModules.fortify = import ./nixos.nix; + checks = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + + inherit (pkgs) + runCommandLocal + nixfmt-rfc-style + deadnix + statix + ; + in + { + check-formatting = + runCommandLocal "check-formatting" { nativeBuildInputs = [ nixfmt-rfc-style ]; } + '' + cd ${./.} + + echo "running nixfmt..." + nixfmt --check . + + touch $out + ''; + + check-lint = + runCommandLocal "check-lint" + { + nativeBuildInputs = [ + deadnix + statix + ]; + } + '' + cd ${./.} + + echo "running deadnix..." + deadnix --fail + + echo "running statix..." + statix check . + + touch $out + ''; + } + ); + packages = forAllSystems ( system: let @@ -56,7 +102,7 @@ }; modules = [ ./options.nix ]; }; - cleanEval = lib.filterAttrsRecursive (n: v: n != "_module") eval; + cleanEval = lib.filterAttrsRecursive (n: _: n != "_module") eval; in pkgs.nixosOptionsDoc { inherit (cleanEval) options; }; docText = pkgs.runCommand "fortify-module-docs.md" { } '' diff --git a/nixos.nix b/nixos.nix index 2009c96..cd4cf98 100644 --- a/nixos.nix +++ b/nixos.nix @@ -10,7 +10,6 @@ let mkIf mkDefault mapAttrs - mapAttrsToList mergeAttrsList imap1 foldr diff --git a/options.nix b/options.nix index adf19f4..616b24c 100644 --- a/options.nix +++ b/options.nix @@ -31,7 +31,6 @@ in let inherit (types) str - enum bool package anything