diff --git a/.gitignore b/.gitignore index 556661c42d..ee16bc3aa7 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,8 @@ tags /*.vkey /*.cert +.pre-commit-config.yaml + # For now require that users generate their own hie.yaml /hie.yaml diff --git a/flake.lock b/flake.lock index e3333b5f10..6ff6c4b36c 100644 --- a/flake.lock +++ b/flake.lock @@ -150,6 +150,22 @@ "type": "github" } }, + "flake-compat_3": { + "flake": false, + "locked": { + "lastModified": 1747046372, + "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -208,6 +224,27 @@ "type": "gitlab" } }, + "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" + } + }, "hackage-for-stackage": { "flake": false, "locked": { @@ -762,6 +799,22 @@ "type": "github" } }, + "nixpkgs_4": { + "locked": { + "lastModified": 1759070547, + "narHash": "sha256-JVZl8NaVRYb0+381nl7LvPE+A774/dRpif01FKLrYFQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "647e5c14cbd5067f44ac86b74f014962df460840", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "old-ghc-nix": { "flake": false, "locked": { @@ -779,6 +832,26 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_3", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1760663237, + "narHash": "sha256-BflA6U4AM1bzuRMR8QqzPXqh8sWVCNDzOdsxXEguJIc=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "ca5b894d3e3e151ffc1db040b6ce4dcc75d31c37", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "CHaP": "CHaP", @@ -790,6 +863,7 @@ "incl": "incl", "iohkNix": "iohkNix", "nixpkgs": "nixpkgs_3", + "pre-commit-hooks": "pre-commit-hooks", "wasm-nixpkgs": [ "ghc-wasm-meta", "nixpkgs" diff --git a/flake.nix b/flake.nix index bcadb53131..214b51bd75 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,7 @@ nixpkgs.url = "github:NixOS/nixpkgs/4284c2b73c8bce4b46a6adf23e16d9e2ec8da4bb"; iohkNix.url = "github:input-output-hk/iohk-nix"; flake-utils.url = "github:hamishmack/flake-utils/hkm/nested-hydraJobs"; + pre-commit-hooks.url = "github:cachix/git-hooks.nix"; incl.url = "github:divnix/incl"; # non-flake nix compatibility flake-compat = { @@ -77,6 +78,30 @@ proto-js-bundle-drv = import ./nix/proto-to-js.nix {pkgs = nixpkgs;}; wasm-typedoc-drv = import ./nix/typedoc.nix {pkgs = nixpkgs;}; + pre-commit-check = inputs.pre-commit-hooks.lib.${nixpkgs.system}.run { + src = ./.; + hooks = { + alejandra.enable = true; + cabal-gild = { + enable = true; + entry = let + script = nixpkgs.writeShellScript "precommit-cabal-gild" '' + for file in "$@"; do + cabal-gild --io="$file" + done + ''; + in + builtins.toString script; + files = "\\.cabal$"; + }; + prettify = { + enable = true; + entry = "scripts/githooks/haskell-style-lint"; + types = ["haskell"]; + }; + }; + }; + # We use cabalProject' to ensure we don't build the plan for # all systems. cabalProject = nixpkgs.haskell-nix.cabalProject' ({config, ...}: { @@ -104,6 +129,7 @@ secure: True active-repositories: hackage.haskell.org, cardano-haskell-packages-local ''; + shell.packages = p: [ # Packages in this repo p.cardano-api @@ -133,6 +159,8 @@ # Skip cross compilers for the shell shell.crossPlatforms = _: []; shell.shellHook = '' + export PATH="${nixpkgs.nix}/bin:$PATH" + ${pre-commit-check.shellHook} export LD_LIBRARY_PATH="${nixpkgs.snappy}/lib:$LD_LIBRARY_PATH" export PATH="$(git rev-parse --show-toplevel)/scripts/devshell:$PATH" '';