-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
203 lines (179 loc) · 6.33 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
{
description = "Primer's web frontend.";
inputs = {
hacknix.url = github:hackworthltd/hacknix;
nixpkgs.follows = "hacknix/nixpkgs";
gitignore.url = "github:hercules-ci/gitignore.nix";
gitignore.inputs.nixpkgs.follows = "nixpkgs";
flake-compat.url = github:edolstra/flake-compat;
flake-compat.flake = false;
pre-commit-hooks-nix.url = github:cachix/pre-commit-hooks.nix;
pre-commit-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
# Note: don't override any of primer's Nix flake inputs, or else
# we won't hit its binary cache.
primer.url = github:hackworthltd/primer/fe24bec4fa279a7973d39813c0f5275fe0078d96;
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs@ { flake-parts, ... }:
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. (This should only happen when you `nix run` in a
# modified repo. Hydra builds will always be working from a
# clean git repo, of course.)
version =
let
v = inputs.self.rev or inputs.self.lastModifiedDate;
in
builtins.trace "Nix primer-app version is ${v}" v;
allOverlays = [
inputs.hacknix.overlays.default
inputs.self.overlays.default
];
in
flake-parts.lib.mkFlake { inherit inputs; } {
debug = true;
imports = [
inputs.pre-commit-hooks-nix.flakeModule
inputs.treefmt-nix.flakeModule
];
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = { config, pkgs, system, ... }:
let
primerPackages = inputs.primer.packages.${system};
scripts = pkgs.callPackage nix/pkgs/scripts {
primer-service-rev = inputs.primer.rev;
inherit (primerPackages) primer-service-docker-image primer-sqitch;
};
bump-primer = pkgs.callPackage ./nix/pkgs/bump-primer { };
in
{
# We need a `pkgs` that includes our own overlays within
# `perSystem`. This isn't done by default, so we do this
# workaround. See:
#
# https://github.com/hercules-ci/flake-parts/issues/106#issuecomment-1399041045
_module.args.pkgs = import inputs.nixpkgs
{
inherit system;
config = {
allowUnfree = true;
allowBroken = true;
};
overlays = allOverlays;
};
pre-commit = {
check.enable = true;
settings = {
src = ./.;
hooks = {
treefmt.enable = true;
actionlint.enable = true;
};
};
};
packages =
let
in
{
inherit (primerPackages) run-primer-sqlite primer-openapi-spec primer-sqitch;
inherit bump-primer;
} // (pkgs.lib.optionalAttrs (system == "x86_64-linux") {
inherit (primerPackages) primer-service-docker-image;
});
apps =
let
mkApp = pkg: script: {
type = "app";
program = "${pkg}/bin/${script}";
};
in
(pkgs.lib.mapAttrs (name: pkg: mkApp pkg name) {
inherit (primerPackages) run-primer-sqlite primer-openapi-spec primer-sqitch;
inherit bump-primer;
});
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
prettier.enable = true;
nixpkgs-fmt.enable = true;
};
settings.formatter.prettier = {
excludes = [
"CONTRIBUTING.md"
"DCO.md"
"README.md"
"docs"
"package.json"
"pnpm-lock.yaml"
];
};
};
devShells.default = pkgs.mkShell {
inputsFrom = [
config.treefmt.build.devShell
];
buildInputs = (with pkgs; [
nodejs_18
nodejs_18.pkgs.pnpm
nil
]);
# Make sure the Nix shell includes node_modules's bin dir in
# the path, or else our editors may not see the editor
# tooling that we include in the Node packaging.
shellHook =
let
spec = inputs.self.packages.${system}.primer-openapi-spec;
local-spec = "./primer-api.json";
in
''
export PATH="$(pwd)/node_modules/.bin:$PATH"
pnpm install
rm -f ${local-spec}
ln -s ${spec} ${local-spec}
pnpm generate
'';
};
};
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
{
overlays.default = (final: prev: { });
hydraJobs = {
inherit (inputs.self) packages;
inherit (inputs.self) checks;
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 CI builds";
};
};
ciJobs = inputs.hacknix.lib.flakes.recurseIntoHydraJobs inputs.self.hydraJobs;
};
};
}