Skip to content

Commit 16d7f67

Browse files
committed
nix: setup pre commit hooks to format code
1 parent 37a00fd commit 16d7f67

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Nix devshells cached by direnv
12
/.direnv/
23

34
# The directory Mix will write compiled artifacts to.
@@ -26,3 +27,6 @@ memorable-*.tar
2627

2728
# Memorable development databases
2829
/db/
30+
31+
# git-hooks.nix generated configuration
32+
/.pre-commit-config.yaml

flake.lock

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
66
flake-utils.url = "github:numtide/flake-utils";
77
flake-compat.url = "github:edolstra/flake-compat";
8+
9+
git-hooks.url = "github:cachix/git-hooks.nix";
10+
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
811
};
912

1013
outputs =
1114
{
15+
self,
1216
nixpkgs,
1317
flake-utils,
18+
git-hooks,
1419
...
1520
}:
1621
flake-utils.lib.eachDefaultSystem (
@@ -19,7 +24,18 @@
1924
pkgs = nixpkgs.legacyPackages.${system};
2025
in
2126
{
22-
devShell = import ./shell.nix { inherit pkgs; };
27+
checks.pre-commit-check = git-hooks.lib.${system}.run {
28+
src = ./.;
29+
hooks = {
30+
mix-format.enable = true;
31+
nixfmt-rfc-style.enable = true;
32+
};
33+
};
34+
35+
devShell = import ./shell.nix {
36+
inherit pkgs;
37+
preCommitHook = self.checks.${system}.pre-commit-check.shellHook;
38+
};
2339
}
2440
);
2541
}

shell.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
pkgs ? import <nixpkgs> { },
3+
preCommitHook ? "",
34
}:
45

56
pkgs.mkShell {
@@ -8,5 +9,12 @@ pkgs.mkShell {
89
packages = with pkgs; [
910
elixir
1011
elixir-ls
12+
13+
nixfmt-rfc-style
14+
nil
1115
];
16+
17+
shellHook = ''
18+
${preCommitHook}
19+
'';
1220
}

0 commit comments

Comments
 (0)