diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..9b255720 --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +use_flake() { + watch_file flake.nix + watch_file flake.lock + eval "$(nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile")" +} + +use flake diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1844a52f..55474335 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -12,4 +12,3 @@ jobs: with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - run: nix flake check - - run: nix fmt -- -c . diff --git a/.gitignore b/.gitignore index 2d81b42f..c5eb498e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .tmp result +.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index b8cf4a81..ade241fd 100644 --- a/flake.lock +++ b/flake.lock @@ -22,6 +22,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-utils": { "locked": { "lastModified": 1676283394, @@ -37,6 +53,42 @@ "type": "github" } }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "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" + } + }, "nixpkgs": { "locked": { "lastModified": 1677342105, @@ -53,6 +105,22 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1673800717, + "narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, "poetry2nix": { "inputs": { "flake-utils": [ @@ -78,11 +146,36 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1677722096, + "narHash": "sha256-7mjVMvCs9InnrRybBfr5ohqcOz+pyEX8m22C1XsDilg=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "61a3511668891c68ebd19d40122150b98dc2fe3b", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "beautysh": "beautysh", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" } }, "utils": { diff --git a/flake.nix b/flake.nix index 8c6be371..8ad71473 100644 --- a/flake.nix +++ b/flake.nix @@ -7,10 +7,14 @@ inputs.beautysh.url = "github:lovesegfault/beautysh"; inputs.beautysh.inputs.nixpkgs.follows = "nixpkgs"; + inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; + outputs = { self, nixpkgs, flake-utils, + pre-commit-hooks, ... } @ inputs: with nixpkgs.lib; @@ -62,9 +66,23 @@ }; extractRustAnalyzerPkg = pkgs.callPackage extractRustAnalyzer {}; in { - checks = import ./tests/checks.nix { - inherit pkgs; - makeNixvim = self.legacyPackages."${system}".makeNixvim; + checks = + (import ./tests/checks.nix { + inherit pkgs; + makeNixvim = self.legacyPackages."${system}".makeNixvim; + }) + // { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + alejandra.enable = true; + }; + }; + }; + devShells = { + default = pkgs.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + }; }; packages = { docs = pkgs.callPackage (import ./docs.nix) {