-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
159 lines (140 loc) · 3.75 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
154
155
156
157
158
159
{
inputs = {
# Nix Packages.
nixpkgs = {
url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
# Nix Flake Utilities.
for-all-systems = {
url = "github:Industrial/for-all-systems";
inputs = {
nixpkgs = {
follows = "nixpkgs";
};
};
};
# Git Hooks.
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
# GitHub Actions.
nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
# Nix Format.
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = inputs @ {self, ...}: let
systems = ["x86_64-linux" "aarch64-darwin"];
forAllSystems = inputs.for-all-systems.forAllSystems {
nixpkgs = inputs.nixpkgs;
inherit systems;
};
# Configure Treefmt
treefmtEval = forAllSystems ({pkgs, ...}:
inputs.treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs = {
# Nix
alejandra = {
enable = true;
};
deadnix = {
enable = true;
};
# Github Actions
actionlint = {
enable = true;
};
# Bash
beautysh = {
enable = true;
};
# TypeScript / JSON
biome = {
enable = true;
};
# YAML
yamlfmt = {
enable = true;
};
};
});
# We don't put this in the flake checks so that we can execute flake check
# on pre-commit.
pre-commit-check = forAllSystems ({system, ...}:
inputs.git-hooks.lib.${system}.run {
src = ./..;
hooks = {
# TODO: Move this to Treefmt.
# TOML
check-toml.enable = true;
taplo.enable = true;
# Git
check-merge-conflicts.enable = true;
commitizen = {
enable = true;
stages = ["commit-msg"];
};
# Misc
check-added-large-files.enable = true;
check-case-conflicts.enable = true;
check-executables-have-shebangs.enable = true;
check-shebang-scripts-are-executable.enable = true;
check-symlinks.enable = true;
detect-aws-credentials.enable = true;
detect-private-keys.enable = true;
end-of-file-fixer.enable = true;
fix-byte-order-marker.enable = true;
forbid-new-submodules.enable = true;
trim-trailing-whitespace.enable = true;
# Nix fmt and Flake Check
format-and-check = {
enable = true;
name = "Fmt and Check";
entry = "nix fmt && nix flake check";
pass_filenames = false;
stages = ["pre-commit"];
};
};
});
in {
formatter =
forAllSystems ({system, ...}:
treefmtEval.${system}.config.build.wrapper);
githubActions = let
supportedSystems = ["x86_64-linux"];
in
inputs.nix-github-actions.lib.mkGithubMatrix {
checks = inputs.nixpkgs.lib.getAttrs supportedSystems self.checks;
};
checks = forAllSystems ({system, ...}: {
formatting = treefmtEval.${system}.config.build.check self;
});
devShells = forAllSystems ({
pkgs,
system,
}: {
default = pkgs.mkShell {
shellHook = pre-commit-check.${system}.shellHook;
buildInputs = pre-commit-check.${system}.enabledPackages;
packages = with pkgs; [
direnv
jq
pre-commit
];
};
});
};
}