From 306cc77e052520bbb21c490f11744e8f5253d7ce Mon Sep 17 00:00:00 2001 From: K900 Date: Fri, 9 Aug 2024 18:46:25 +0300 Subject: [PATCH] flake.nix: add nixfmt pre-commit hook --- .gitignore | 1 + flake.lock | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 19 ++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/.gitignore b/.gitignore index 11ed1dd..18425fd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ config.tf.json .terraform.lock.hcl secrets/* !secrets/*.age +.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index 63d346e..dcf93d9 100644 --- a/flake.lock +++ b/flake.lock @@ -278,6 +278,22 @@ "type": "github" } }, + "flake-compat_5": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -385,6 +401,27 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "grapevine": { "inputs": { "attic": "attic", @@ -631,6 +668,22 @@ "type": "github" } }, + "nixpkgs-stable_2": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1723151389, @@ -678,6 +731,29 @@ "type": "github" } }, + "pre-commit-hooks_2": { + "inputs": { + "flake-compat": "flake-compat_5", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable_2" + }, + "locked": { + "lastModified": 1723202784, + "narHash": "sha256-qbhjc/NEGaDbyy0ucycubq4N3//gDFFH3DOmp1D3u1Q=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "c7012d0c18567c889b948781bc74a501e92275d1", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "agenix": "agenix", @@ -691,6 +767,7 @@ ], "nix-gerrit": "nix-gerrit", "nixpkgs": "nixpkgs_2", + "pre-commit-hooks": "pre-commit-hooks_2", "terranix": "terranix" } }, diff --git a/flake.nix b/flake.nix index d99a6e9..1568c01 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,9 @@ repo = "grapevine-fork"; inputs.nixpkgs.follows = "nixpkgs"; }; + + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = @@ -37,6 +40,7 @@ nixpkgs, terranix, colmena, + pre-commit-hooks, ... }@inputs: let @@ -113,6 +117,21 @@ (pkgs.callPackage ./lib/colmena-wrapper.nix { }) ]; + + inherit (inputs.self.checks.${system}.pre-commit) shellHook; + }; + } + ); + + checks = forEachSystem' ( + { system, pkgs, ... }: + { + pre-commit = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks.nixfmt = { + enable = true; + package = pkgs.nixfmt-rfc-style; + }; }; } );