-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathflake.nix
219 lines (190 loc) · 6.36 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
{
description = "Trustix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
buildNodeModules = {
url = "github:adisbladis/buildNodeModules";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-root.url = "github:srid/flake-root";
};
outputs =
{ self
, nixpkgs
, flake-parts
, gomod2nix
, gitignore
, systems
, treefmt-nix
, flake-root
, nix-github-actions
, ...
} @ inputs:
let
inherit (nixpkgs) lib;
in
flake-parts.lib.mkFlake
{ inherit inputs; }
{
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
flake.githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = {
x86_64-linux = self.checks.x86_64-linux;
x86_64-darwin =
let
filteredChecks = [ "reuse" "treefmt" ]; # No point in running on linux _and_ darwin
in
lib.filterAttrs (name: _: ! lib.elem name filteredChecks && ! lib.strings.hasInfix "nixos" name) self.checks.x86_64-darwin;
};
};
flake.nixosModules = {
trustix = import ./nixos self;
};
imports = [
inputs.treefmt-nix.flakeModule
inputs.flake-root.flakeModule
];
perSystem =
{ pkgs
, config
, system
, self'
, ...
}:
let
buildNodeModules = inputs.buildNodeModules.lib.${system};
callPackage = lib.callPackageWith (pkgs
// {
inherit (inputs.gomod2nix.legacyPackages.${system}) buildGoApplication;
inherit (inputs.gitignore.lib) gitignoreSource;
inherit buildNodeModules;
});
in
{
treefmt.imports = [ ./dev/treefmt.nix ];
checks =
# All packages + passthru.tests
(
let
packages' = builtins.removeAttrs (self'.packages) [ "default" ];
in
lib.listToAttrs (
lib.flatten (
lib.mapAttrsToList
(name: value: [ (lib.nameValuePair name value) ] ++ lib.mapAttrsToList (test: drv: lib.nameValuePair "${name}-${test}" drv)
(lib.filterAttrs (name: test: lib.elem system test.meta.platforms) (value.passthru.tests or { }))
)
packages'
)
)
)
# Reuse lint
// {
reuse = pkgs.runCommand "reuse-lint" { nativeBuildInputs = [ pkgs.reuse ]; } ''
cd ${self}
reuse lint
touch $out
'';
}
# Build development shell
// {
shell = self.devShells.${system}.default;
}
# NixOS tests
// (
let
checkArgs = {
inherit pkgs;
inherit system lib;
inherit (self') packages;
};
in
{
# Temporary: Comment out to get CI passing..
# trustix-nixos = import ./packages/trustix/nixos/test.nix checkArgs;
}
)
;
devShells.default = pkgs.mkShell {
buildInputs = [
# Procfile process runner
pkgs.hivemind
# Nix go modules code generator
inputs.gomod2nix.packages.${system}.default
# Protobuf
pkgs.protobuf
pkgs.grpcurl # gRPC CLI
# Go linters
pkgs.golangci-lint # Multi purpose linter
# File system watchers
pkgs.reflex
pkgs.entr
# Docs
pkgs.mdbook
# License management and compliance
pkgs.reuse
# Socket activation testing
pkgs.systemfd
# Dev
pkgs.go
pkgs.nix-eval-jobs
pkgs.sqlite
(pkgs.diffoscope.override {
enableBloat = ! pkgs.stdenv.isDarwin;
})
pkgs.sqlc
pkgs.goose
pkgs.protoc-gen-go
pkgs.protoc-gen-doc
pkgs.protoc-gen-connect-go
pkgs.nodejs
# Link node_modules into $npmRoot/node_modules
buildNodeModules.hooks.linkNodeModulesHook
];
inputsFrom = [ config.flake-root.devShell ];
# Write token used for log submission
env.TRUSTIX_TOKEN = "${./packages/trustix/dev/token-priv}";
env.npmRoot = "./packages/trustix-nix-r13y-web";
shellHook = ''
export TRUSTIX_RPC="unix://$FLAKE_ROOT/state/trustix.socket"
export TRUSTIX_NIX_REPROD_STATE_DIR="$FLAKE_ROOT/state/nix-reprod"
export TRUSTIX_STATE_DIR="$FLAKE_ROOT/state/trustix";
export PATH="$FLAKE_ROOT/packages/trustix-nix-r13y-web/node_modules/.bin:$PATH";
'';
};
packages = {
default = self'.packages.trustix;
trustix = callPackage ./packages/trustix { };
trustix-doc = callPackage ./packages/trustix-doc { };
trustix-nix = callPackage ./packages/trustix-nix { };
trustix-nix-r13y = callPackage ./packages/trustix-nix-r13y { };
trustix-nix-r13y-web = callPackage ./packages/trustix-nix-r13y-web { };
};
};
};
}