-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
182 lines (155 loc) · 4.87 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
{
description = "Hackworth Ltd's opinionated generic Nix flake template";
inputs = {
hacknix.url = "github:hackworthltd/hacknix";
nixpkgs.follows = "hacknix/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
gitignore-nix.url = "github:hercules-ci/gitignore.nix";
gitignore-nix.flake = false;
git-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
git-hooks-nix.url = "github:cachix/git-hooks.nix";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
pkgs-by-name-for-flake-parts.url = "github:drupol/pkgs-by-name-for-flake-parts";
};
outputs =
inputs:
let
# A flake can get its git revision via `self.rev` if its working
# tree is clean and its index is empty, so we use that for the
# program version when it's available.
#
# When the working tree is modified or the index is not empty,
# evaluating `self.rev` is an error. However, we *can* use
# `self.lastModifiedDate` in that case, which is at least a bit
# more helpful than returning "unknown" or some other static
# value.
version =
let
v = inputs.self.rev or inputs.self.lastModifiedDate;
in
builtins.trace "Flake version is ${v}" "git-${v}";
allOverlays = [
inputs.hacknix.overlays.default
];
formattingExcludes = [
"CODE_OF_CONDUCT.md"
"LICENSE"
"flake.lock"
];
in
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
debug = true;
systems = [
"x86_64-linux"
"aarch64-darwin"
];
imports = [
inputs.treefmt-nix.flakeModule
inputs.git-hooks-nix.flakeModule
inputs.pkgs-by-name-for-flake-parts.flakeModule
];
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
self'.allowUnfree = true;
self'.allowBroken = true;
overlays = allOverlays;
};
formatter = pkgs.nixfmt-rfc-style;
pre-commit = {
check.enable = true;
settings = {
src = ./.;
hooks = {
treefmt.enable = true;
nixfmt-rfc-style.enable = true;
prettier.enable = true;
actionlint = {
enable = true;
name = "actionlint";
entry = "${pkgs.actionlint}/bin/actionlint";
language = "system";
files = "^.github/workflows/";
};
};
excludes = formattingExcludes;
};
};
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
prettier.enable = true;
nixfmt.enable = true;
};
settings.formatter.prettier.excludes = formattingExcludes;
};
pkgsDirectory = ./nix/pkgs;
devShells.default = pkgs.mkShell {
inputsFrom = [
config.treefmt.build.devShell
config.pre-commit.devShell
];
buildInputs = with pkgs; [
actionlint
nixd
nixfmt-rfc-style
nodejs
nodePackages.prettier
vscode-langservers-extracted
act
docker
git
];
shellHook = ''
${config.pre-commit.installationScript}
'';
};
};
flake =
let
# See above, we need to use our own `pkgs` within the flake.
pkgs = import inputs.nixpkgs {
system = "x86_64-linux";
config = {
allowUnfree = true;
allowBroken = true;
};
overlays = allOverlays;
};
in
{
hydraJobs = {
inherit (inputs.self) checks;
inherit (inputs.self) packages;
inherit (inputs.self) devShells;
required = pkgs.releaseTools.aggregate {
name = "required-nix-ci";
constituents = builtins.map builtins.attrValues (
with inputs.self.hydraJobs;
[
packages.x86_64-linux
packages.aarch64-darwin
checks.x86_64-linux
checks.aarch64-darwin
]
);
meta.description = "Required Nix CI builds";
};
};
ciJobs = pkgs.lib.flakes.recurseIntoHydraJobs inputs.self.hydraJobs;
};
};
}