-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflake.nix
153 lines (142 loc) · 4.08 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix.url = "github:numtide/treefmt-nix";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-root.url = "github:srid/flake-root";
nix-direnv.url = "github:nix-community/nix-direnv";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};
outputs = inputs @ {
flake-parts,
nixpkgs,
rust-overlay,
pre-commit-hooks,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.treefmt-nix.flakeModule
inputs.flake-root.flakeModule
];
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
perSystem = { config, self', inputs', pkgs, system, ... }:
let
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
};
};
# Pre-commit hooks configuration
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
treefmt = {
enable = true;
entry = "nix develop .#devShell -c treefmt";
types_or = ["file"];
pass_filenames = false;
};
terraform-fmt = {
enable = true;
entry = "nix develop .#devShell -c terraform fmt";
types = ["terraform"];
};
terragrunt-fmt = {
enable = true;
entry = "nix develop .#devShell -c terragrunt hclfmt";
types = ["hcl"];
};
golangci-lint = {
enable = true;
entry = "nix develop .#devShell -c golangci-lint run";
types = ["go"];
};
};
};
in
{
# Define development shell with pre-commit hooks
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
treefmt
alejandra
rustfmt
nodePackages.prettier
go
terraform
terragrunt
golangci-lint
pre-commit-hooks.packages.${system}.pre-commit
];
# Attach pre-commit hooks to the shell
shellHook = ''
${pre-commit-check.shellHook}
'';
};
# Define the treefmt app
apps.treefmt = {
type = "app";
program = "${pkgs.treefmt}/bin/treefmt";
};
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
alejandra.enable = true;
gofmt.enable = true;
prettier.enable = true;
rustfmt.enable = true;
terraform.enable = true;
terragrunt.enable = true;
};
settings.formatter = {
nix = {
command = "alejandra";
includes = ["*.nix"];
};
go = {
command = "gofmt";
includes = ["*.go"];
excludes = [
"*/internal/*"
"dagger.gen.go"
];
};
prettier = {
command = "prettier";
options = ["--write"];
includes = [
"*.js"
"*.jsx"
"*.ts"
"*.tsx"
"*.json"
"*.md"
"*.markdown"
"*.yaml"
"*.yml"
];
};
rust = {
command = "rustfmt";
includes = ["*.rs"];
};
terraform = {
command = "terraform";
options = ["fmt"];
includes = ["*.tf"];
};
terragrunt = {
command = "terragrunt";
options = ["hclfmt"];
includes = ["*.hcl"];
};
};
};
# Optional: Make pre-commit check available as a check
checks.pre-commit-check = pre-commit-check;
};
};
}