From 37f1c553b419cfb2d69e12ffd66f501b34805170 Mon Sep 17 00:00:00 2001 From: Crony Akatsuki Date: Sun, 17 Mar 2024 15:06:04 +0100 Subject: [PATCH] Add pre-commit gofmt hook. --- .gitignore | 1 + flake.lock | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 4 +- shell.nix | 8 ++++ 4 files changed, 138 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 369bee7..3122962 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ env files /gomod2nix-template .direnv +.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index f5b7a74..539a3b7 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "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-utils": { "inputs": { "systems": "systems" @@ -18,6 +34,45 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703887061, + "narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "gomod2nix": { "inputs": { "flake-utils": [ @@ -57,11 +112,66 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1704874635, + "narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1704842529, + "narHash": "sha256-OTeQA+F8d/Evad33JMfuXC89VMetQbsU4qcaePchGr4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "eabe8d3eface69f5bb16c18f8662a702f50c20d5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1708018599, + "narHash": "sha256-M+Ng6+SePmA8g06CmUZWi1AjG2tFBX9WCXElBHEKnyM=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "5df5a70ad7575f6601d91f0efec95dd9bc619431", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", "gomod2nix": "gomod2nix", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" } }, "systems": { @@ -78,6 +188,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 1d8de62..fe57114 100644 --- a/flake.nix +++ b/flake.nix @@ -6,8 +6,9 @@ inputs.gomod2nix.url = "github:nix-community/gomod2nix"; inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs"; inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils"; + inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; - outputs = { self, nixpkgs, flake-utils, gomod2nix }: + outputs = { self, nixpkgs, flake-utils, gomod2nix, pre-commit-hooks }: (flake-utils.lib.eachDefaultSystem (system: let @@ -23,6 +24,7 @@ }; devShells.default = callPackage ./shell.nix { inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix; + inherit pre-commit-hooks; }; }) ); diff --git a/shell.nix b/shell.nix index d4f21a8..5cde177 100644 --- a/shell.nix +++ b/shell.nix @@ -11,12 +11,20 @@ ) , mkGoEnv ? pkgs.mkGoEnv , gomod2nix ? pkgs.gomod2nix +, pre-commit-hooks }: let goEnv = mkGoEnv { pwd = ./.; }; + pre-commit-check = pre-commit-hooks.lib.${pkgs.system}.run { + src = ./.; + hooks = { + gofmt.enable = true; + }; + }; in pkgs.mkShell { + inherit (pre-commit-check) shellHook; packages = [ goEnv gomod2nix