diff --git a/flake.nix b/flake.nix index a975417..d1b66a4 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,10 @@ }) ]; pkgs = import nixpkgs {inherit system overlays;}; - package = import ./nix/package.nix {inherit self nix-filter pkgs;}; + package = import ./nix/package.nix { + inherit self pkgs; + nix-filter = nix-filter.lib; + }; in { packages.${system} = rec { tlaternet-templates = package.package; @@ -35,5 +38,10 @@ devShells.${system} = { default = package.shell; }; + + checks.${system} = import ./nix/checks.nix { + inherit self pkgs; + nix-filter = nix-filter.lib; + }; }; } diff --git a/nix/checks.nix b/nix/checks.nix new file mode 100644 index 0000000..eb39744 --- /dev/null +++ b/nix/checks.nix @@ -0,0 +1,61 @@ +{ + self, + nix-filter, + pkgs, +}: let + inherit (builtins) removeAttrs; + inherit (pkgs.lib) concatStringsSep; + + mkNodeCheck = { + buildInputs ? [], + checkCommands, + ... + } @ attrs: let + extraAttrs = removeAttrs attrs ["buildInputs"]; + in + self.packages.${pkgs.system}.default.overrideAttrs (old: + { + src = nix-filter { + root = self; + + include = [ + ../package.json + ../tsconfig.json + ../.eslintrc.json + ../.parcelrc + ../.posthtmlrc + ../.prettierrc + + nix-filter.isDirectory + (nix-filter.matchExt "ts") + (nix-filter.matchExt "tsx") + (nix-filter.matchExt "html") + (nix-filter.matchExt "scss") + ]; + }; + + buildInputs = old.buildInputs ++ buildInputs; + + checkPhase = '' + mkdir -p $out + ${concatStringsSep "\n" (map (command: "${command} > $out/check.log") checkCommands)} + ''; + + doCheck = true; + dontBuild = true; + dontInstall = true; + } + // extraAttrs); +in { + style = mkNodeCheck { + checkCommands = [ + "npm run style" + ]; + }; + + types = mkNodeCheck { + checkCommands = [ + "npm run check" + ]; + }; +} diff --git a/nix/package.nix b/nix/package.nix index dfaa6c9..42317fb 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -3,6 +3,8 @@ nix-filter, pkgs, }: let + inherit (pkgs.lib) cleanSource; + node_modules_attrs = { # Dependencies that should be available in the node build buildInputs = with pkgs; [ @@ -21,7 +23,7 @@ in { package = pkgs.npmlock2nix.build { inherit buildInputs node_modules_attrs; - src = pkgs.lib.cleanSource self; + src = cleanSource self; buildCommands = ["npm run build-dist"]; @@ -33,7 +35,7 @@ in { shell = pkgs.npmlock2nix.shell { inherit buildInputs node_modules_attrs; - src = nix-filter.lib { + src = nix-filter { root = self; include = [ "package.json"