-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
171 lines (161 loc) · 5.26 KB
/
Copy pathflake.nix
File metadata and controls
171 lines (161 loc) · 5.26 KB
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
# Copyright 2026 Edgeless Systems GmbH
# SPDX-License-Identifier: BUSL-1.1
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
treefmt-nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import ./overlays/nixpkgs.nix) ];
config.allowUnfreePredicate = pkg: (pkg.pname or "") == "collateral-proxy";
};
inherit (pkgs) lib;
version = lib.trim (builtins.readFile ./version.txt);
image = "ghcr.io/edgelesssys/collateral-proxy";
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
collateral-proxy = pkgs.buildGoModule {
pname = "collateral-proxy";
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./go.mod
./go.sum
(lib.fileset.fileFilter (file: lib.hasSuffix ".go" file.name) ./.)
];
};
proxyVendor = true;
vendorHash = "sha256-GrNc8vmx8p2Cb0FeGyeVKlxYve5KvhZpID/A9MLi/Sw=";
subPackages = [ "." ];
env.CGO_ENABLED = 0;
ldflags = [
"-s"
"-X main.version=v${version}"
];
# Race detector needs cgo.
preCheck = "export CGO_ENABLED=1";
checkPhase = ''
runHook preCheck
go test -race ./...
runHook postCheck
'';
meta = {
description = "Read-through caching forward proxy for attestation collateral (AMD KDS, Intel PCS, NVIDIA RIM).";
license = lib.licenses.bsl11;
mainProgram = "collateral-proxy";
};
};
# OCI image published to ${image}.
container = pkgs.dockerTools.buildImage {
name = "collateral-proxy";
tag = "v${version}";
copyToRoot = with pkgs.dockerTools; [ caCertificates ];
config.Entrypoint = [ (lib.getExe collateral-proxy) ];
};
# Push the container image and echo the pinned reference ${image}:<tag>@sha256:<digest> to stdout.
push = pkgs.writeShellApplication {
name = "push-collateral-proxy";
runtimeInputs = with pkgs; [
crane
gzip
];
text = ''
trap 'echo "push-collateral-proxy: failed (exit $?) at line $LINENO: $BASH_COMMAND" >&2' ERR
tag="''${1:-dev}"
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
echo "push-collateral-proxy: pushing ${image}:$tag" >&2
gunzip < "${container}" > "$tmp"
crane push "$tmp" "${image}:$tag" >&2
digest=$(crane digest "${image}:$tag")
echo "${image}:$tag@$digest"
'';
};
# Render the deployment manifest to stdout.
render-k8s-resources = pkgs.writeShellApplication {
name = "render-k8s-resources";
runtimeInputs = [
pkgs.gnugrep
pkgs.gnused
];
text = ''
trap 'echo "render-k8s-resources: failed (exit $?) at line $LINENO: $BASH_COMMAND" >&2' ERR
if [[ $# -ne 1 ]]; then
echo "usage: render-k8s-resources ${image}:<tag>@sha256:<digest>" >&2
exit 1
fi
ref=$1
template=${./collateral-proxy.yml}
if ! grep -q '%%pin%%' "$template"; then
echo "render-k8s-resources: template $template is missing the %%pin%% placeholder" >&2
exit 1
fi
sed "s|%%pin%%|$ref|" "$template"
'';
};
# Lint the working tree: `nix run .#lint`. Extra args pass through, e.g. `nix run .#lint -- --fix`.
lint = pkgs.writeShellApplication {
name = "lint";
runtimeInputs = [
pkgs.golangci-lint
pkgs.go
];
text = ''exec golangci-lint run "$@"'';
};
# Scan for known vulnerabilities: `nix run .#govulncheck`.
govulncheck = pkgs.writeShellApplication {
name = "govulncheck";
runtimeInputs = [
pkgs.govulncheck
pkgs.go
];
text = "exec govulncheck ./...";
};
in
{
packages = {
default = collateral-proxy;
inherit
collateral-proxy
container
push
render-k8s-resources
lint
govulncheck
;
};
formatter = treefmtEval.config.build.wrapper;
# `nix flake check` runs formatters and tests.
checks = {
formatting = treefmtEval.config.build.check self;
# Building the package runs `go test -race ./...` in its checkPhase.
tests = collateral-proxy;
};
devShells.default = pkgs.mkShell {
packages = with pkgs; [
go
golangci-lint
gotools
gopls
crane
govulncheck
];
};
}
);
}