-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
161 lines (141 loc) · 4.12 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs = { self, nixpkgs, rust-overlay, crane, flake-utils, advisory-db, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" ];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type:
(builtins.match ".*proto$" path != null)
|| (craneLib.filterCargoSources path type);
};
commonArgs = {
inherit src;
nativeBuildInputs = with pkgs; [
clang
llvmPackages.libclang.lib
pkg-config
protobuf
rustToolchain
] ++ pkgs.lib.optional stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
Security
]);
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
pname = "buildkite-keda-scaler-deps";
});
bin = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
image = pkgs.dockerTools.buildImage {
name = "buildkite-keda-scaler";
tag = "latest";
created = "now";
copyToRoot = with pkgs.dockerTools; [
usrBinEnv
binSh
caCertificates
bin
];
config = {
Entrypoint = [
"${bin}/bin/buildkite-keda-scaler"
];
ExposedPorts = {
"9090/tcp" = { };
};
};
};
clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
});
format = craneLib.cargoFmt {
inherit src;
};
audit = craneLib.cargoAudit {
inherit src advisory-db;
};
ciUploadImage = pkgs.writeShellApplication {
name = "ci-upload-image";
runtimeInputs = with pkgs; [
skopeo
];
text = ''
function dry_run() {
if [[ "''${DRY_RUN:-false}" == "true" ]]; then
echo "[dry-run] $*"
else
"$@"
fi
}
archive="$1"
dest="$2"
tag="$3"
archs=("x86_64")
echo "Skopeo version: $(skopeo --version)"
echo "Uploading image: $archive to $dest"
if [[ ! -f "$archive" ]]; then
echo "Image archive doesn't exist: $archive"
exit 1
fi
images=()
for arch in "''${archs[@]}"; do
echo "Uploading image for $arch"
dry_run skopeo --insecure-policy copy "docker-archive:$archive" "docker://$dest:$tag-$arch"
images+=("$dest:$tag-$arch")
done
dry_run buildah manifest create "$dest:$tag" "''${images[@]}"
dry_run buildah manifest push --all "$dest:$tag"
'';
};
in
{
formatter = pkgs.nixpkgs-fmt;
checks = {
inherit clippy format audit;
};
packages = {
default = bin;
deps = cargoArtifacts;
image = image;
};
devShells = {
default = pkgs.mkShell (commonArgs // { });
ci = pkgs.mkShell {
buildInputs = with pkgs; [
buildah
skopeo
ciUploadImage
];
};
};
}
);
}