Skip to content

Commit f0ca557

Browse files
committed
feat(flakeModules): Add git-hook module and use it to configure pre-commit
1 parent 652487f commit f0ca557

File tree

5 files changed

+104
-39
lines changed

5 files changed

+104
-39
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ matrix-*.json
1313
shardMatrix.json
1414

1515
.vscode
16+
17+
# Pre Commit
18+
.pre-commit-config.yaml

checks/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
{
33
imports = [
44
./packages-ci-matrix.nix
5+
./pre-commit.nix
56
];
67
}

checks/pre-commit.nix

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{ inputs, ... }:
2+
{
3+
flake.flakeModules.git-hooks =
4+
{ config, ... }:
5+
{
6+
imports = [
7+
# Import git-hooks flake-parts module
8+
# docs: https://flake.parts/options/git-hooks-nix
9+
inputs.git-hooks-nix.flakeModule
10+
];
11+
12+
config = {
13+
perSystem =
14+
{ ... }:
15+
{
16+
# impl: https://github.com/cachix/git-hooks.nix/blob/master/flake-module.nix
17+
pre-commit = {
18+
# Add flake `checks` output
19+
check.enable = true;
20+
21+
# Enable commonly used formatters
22+
settings.hooks = {
23+
# Basic whitespace formatting
24+
editorconfig-checker.enable = true;
25+
26+
# *.nix formatting
27+
nixfmt-rfc-style.enable = true;
28+
29+
# *.rs formatting
30+
rustfmt.enable = true;
31+
32+
# *.{js,jsx,ts,tsx,css,html,md,json} formatting
33+
prettier = {
34+
enable = true;
35+
args = [
36+
"--check"
37+
"--list-different=false"
38+
"--log-level=warn"
39+
"--ignore-unknown"
40+
"--write"
41+
];
42+
};
43+
};
44+
};
45+
};
46+
};
47+
};
48+
}

flake.nix

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
./checks
226226
./modules
227227
./packages
228+
./shells
228229
];
229230
systems = [
230231
"x86_64-linux"
@@ -233,18 +234,12 @@
233234
"aarch64-darwin"
234235
];
235236
perSystem =
236-
{
237-
system,
238-
pkgs,
239-
inputs',
240-
...
241-
}:
237+
{ pkgs, system, ... }:
242238
{
243239
_module.args.pkgs = import nixpkgs {
244240
inherit system;
245241
config.allowUnfree = true;
246242
};
247-
devShells.default = import ./shells/default.nix { inherit pkgs flake inputs'; };
248243
devShells.ci = import ./shells/ci.nix { inherit pkgs; };
249244
};
250245
flake.lib.create =

shells/default.nix

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,54 @@
1+
{ inputs, ... }:
12
{
2-
pkgs,
3-
flake,
4-
inputs',
5-
...
6-
}:
7-
let
8-
repl = pkgs.writeShellApplication {
9-
name = "repl";
10-
text = ''
11-
nix repl --file "$REPO_ROOT/repl.nix";
12-
'';
13-
};
14-
in
15-
pkgs.mkShell {
16-
packages = with pkgs; [
17-
inputs'.agenix.packages.agenix
18-
inputs'.nixos-anywhere.packages.nixos-anywhere
19-
figlet
20-
just
21-
jq
22-
nix-eval-jobs
23-
nixos-rebuild
24-
nix-output-monitor
25-
repl
26-
rage
27-
inputs'.dlang-nix.packages.dmd
28-
inputs'.dlang-nix.packages.dub
29-
act
3+
imports = [
4+
(import ../checks/pre-commit.nix {
5+
inherit inputs;
6+
}).flake.flakeModules.git-hooks
307
];
318

32-
shellHook = ''
33-
export REPO_ROOT="$PWD"
34-
figlet -t "${flake.description}"
35-
'';
9+
perSystem =
10+
{
11+
pkgs,
12+
inputs',
13+
config,
14+
...
15+
}:
16+
{
17+
devShells.default =
18+
let
19+
repl = pkgs.writeShellApplication {
20+
name = "repl";
21+
text = ''
22+
nix repl --file "$REPO_ROOT/repl.nix";
23+
'';
24+
};
25+
in
26+
pkgs.mkShell {
27+
packages =
28+
with pkgs;
29+
[
30+
inputs'.agenix.packages.agenix
31+
inputs'.nixos-anywhere.packages.nixos-anywhere
32+
figlet
33+
just
34+
jq
35+
nix-eval-jobs
36+
nixos-rebuild
37+
nix-output-monitor
38+
repl
39+
rage
40+
inputs'.dlang-nix.packages.dub
41+
]
42+
++ pkgs.lib.optionals (pkgs.stdenv.system == "x86_64-linux") [
43+
inputs'.dlang-nix.packages.dmd
44+
];
45+
46+
shellHook =
47+
''
48+
export REPO_ROOT="$PWD"
49+
figlet -t "Metacraft Nixos Modules"
50+
''
51+
+ config.pre-commit.installationScript;
52+
};
53+
};
3654
}

0 commit comments

Comments
 (0)