diff --git a/.gitignore b/.gitignore index d9994623..c91c0c25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .direnv result* +.pre-commit-config.yaml # python __pycache__ diff --git a/flake-parts/devShells/default.nix b/flake-parts/devShells/default.nix index 445cf2e6..35261723 100644 --- a/flake-parts/devShells/default.nix +++ b/flake-parts/devShells/default.nix @@ -2,9 +2,14 @@ perSystem = { pkgs , self' + , config , ... }: { devShells.default = pkgs.mkShell { + inputsFrom = [ + config.pre-commit.devShell + config.treefmt.build.devShell + ]; packages = [ pkgs.tea self'.packages.tea-create-pr diff --git a/flake-parts/formatting.nix b/flake-parts/formatting.nix index 15cbff2c..d4263a03 100644 --- a/flake-parts/formatting.nix +++ b/flake-parts/formatting.nix @@ -3,9 +3,10 @@ , ... }: { imports = [ + inputs.pre-commit-hooks-nix.flakeModule inputs.treefmt-nix.flakeModule ]; - perSystem = { pkgs, ... }: { + perSystem = { pkgs, config, ... }: { treefmt.projectRootFile = "flake.nix"; treefmt.flakeCheck = true; treefmt.flakeFormatter = true; @@ -36,5 +37,16 @@ ]; includes = [ "*.py" ]; }; + + # activated in devShells via inputsFrom = [config.pre-commit.devShell]; + pre-commit.settings.hooks.format-all = { + name = "format-all"; + enable = true; + pass_filenames = true; + entry = toString (pkgs.writeScript "treefmt" '' + #!${pkgs.bash}/bin/bash + ${config.treefmt.build.wrapper}/bin/treefmt --clear-cache --fail-on-change "$@" + ''); + }; }; } diff --git a/flake-parts/pre-commit.nix b/flake-parts/pre-commit.nix deleted file mode 100644 index fd579e9f..00000000 --- a/flake-parts/pre-commit.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ ... }: { - pre-commit.settings.hooks.alejandra.enable = true; - pre-commit.settings.hooks.shellcheck.enable = true; -} diff --git a/flake.lock b/flake.lock index 23167f53..48db459e 100644 --- a/flake.lock +++ b/flake.lock @@ -20,6 +20,22 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -40,6 +56,45 @@ "type": "github" } }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixlib": { "locked": { "lastModified": 1688259758, @@ -92,15 +147,85 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1689261696, + "narHash": "sha256-LzfUtFs9MQRvIoQ3MfgSuipBVMXslMPH/vZ+nM40LkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "df1eee2aa65052a18121ed4971081576b25d6b5c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks-nix": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1690464206, + "narHash": "sha256-38V4kmOh6ikpfGiAS+Kt2H/TA2DubSqE66veP/jmB4Q=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "9289996dcac62fd45836db7c07b87d2521eb526d", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "disko": "disko", "flake-parts": "flake-parts", "nixos-generators": "nixos-generators", "nixpkgs": "nixpkgs", + "pre-commit-hooks-nix": "pre-commit-hooks-nix", "treefmt-nix": "treefmt-nix" } }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { "inputs": { "nixpkgs": [ diff --git a/flake.nix b/flake.nix index 9e9f9057..a3d66e71 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,7 @@ flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix"; }; outputs = inputs @ { flake-parts, ... }: