Skip to content

Commit

Permalink
Configure pre-commit-hooks via shell.nix
Browse files Browse the repository at this point in the history
This configures a git pre-commit hook as described in [1]. For
now this only enables `stylish-haskell`.

The way this works is that the code added to `shellHook` generates
a `.pre-commit-config.yaml` and configures the hook with git.

PS: If you are using some `direnv` based solution such as lorri
you might want to add `eval $shellHook` to your `.envrc` file.

[1] https://github.com/cachix/pre-commit-hooks.nix#getting-started
  • Loading branch information
gilligan committed Oct 26, 2020
1 parent d1870f5 commit dcc4415
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions shell.nix
Expand Up @@ -6,6 +6,13 @@ let
pyEnv = pkgs.python3.withPackages (ps: [ packageSet.sphinxcontrib-haddock.sphinxcontrib-domaintools ps.sphinx ps.sphinx_rtd_theme ]);
# Called from Cabal to generate the Haskell source for the metatheory package
agdaWithStdlib = agdaPackages.agda.withPackages [ agdaPackages.standard-library ];
# Configure project pre-commit hooks
pre-commit-check = pkgs.nix-pre-commit-hooks.run {
src = ./.;
hooks = {
stylish-haskell.enable = true;
};
};
in haskell.packages.shellFor {
nativeBuildInputs = [
# From nixpkgs
Expand Down Expand Up @@ -58,13 +65,15 @@ in haskell.packages.shellFor {
# we have a local passwords store that we use for deployments etc.
PASSWORD_STORE_DIR = toString ./. + "/secrets";

shellHook =
shellHook = ''
${pre-commit-check.shellHook}
''
# Work around https://github.com/NixOS/nix/issues/3345, which makes
# tests etc. run single-threaded in a nix-shell.
# Sets the affinity to cores 0-1000 for $$ (current PID in bash)
# Only necessary for linux - darwin doesn't even expose thread
# affinity APIs!
pkgs.lib.optionalString pkgs.stdenv.isLinux ''
taskset -pc 0-1000 $$
+ pkgs.lib.optionalString pkgs.stdenv.isLinux ''
${pkgs.utillinux}/bin/taskset -pc 0-1000 $$
'';
}

0 comments on commit dcc4415

Please sign in to comment.