-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathflake.nix
203 lines (181 loc) · 6.57 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 = "DDN Engine";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = { self, nixpkgs, flake-utils, crane, rust-overlay }:
flake-utils.lib.eachDefaultSystem (localSystem:
let
version = pkgs.lib.strings.fileContents ./nix/version;
targetSystems = flake-utils.lib.defaultSystems;
dockerArchitectures = {
"x86_64-linux" = "amd64";
"aarch64-linux" = "arm64";
};
pkgs = import nixpkgs {
system = localSystem;
overlays = [ rust-overlay.overlays.default ];
};
rust = pkgs.lib.attrsets.genAttrs targetSystems (crossSystem: import ./nix/rust.nix {
inherit nixpkgs rust-overlay crane localSystem crossSystem;
});
binaries = [
"engine"
"custom-connector"
"dev-auth-webhook"
];
binaryPackages = {
};
defaultBinary = "engine";
dockerConfig = {
"engine" = {
ExposedPorts = { "3000/tcp" = { }; };
};
"ddn-engine-local-dev" = {
ExposedPorts = { "3000/tcp" = { }; };
};
"custom-connector" = {
ExposedPorts = { "8102/tcp" = { }; };
};
"dev-auth-webhook" = {
ExposedPorts = { "3050/tcp" = { }; };
};
};
# for adding extra packages inside the Docker container
dockerExtraContents = {
"engine" = [ pkgs.cacert ]; # so local dev can use SSH
"ddn-engine-local-dev" = [ pkgs.cacert ]; # so local dev can use SSH
"multitenant-engine" = [ pkgs.cacert pkgs.bash pkgs.coreutils ]; # to run sleep in a healthcheck, we should remove this soon
"artifact-server" = [ pkgs.curl pkgs.bash ]; # to run healthcheck, we should remove this soon
};
in
{
formatter = pkgs.nixpkgs-fmt;
# Generate packages in a tree structure.
#
# The path is of the form:
#
# local system -> binary name -> target system -> output
#
# For example, to cross-compile the engine to aarch64-linux on a
# x86_64-linux machine, you will want to access:
#
# targets.x86_64-linux.engine.aarch64-linux.binary
#
# Docker images are named "docker", and live next to the binaries. They
# are not provided for all systems; if there is no Docker image, the
# value will be `null`.
#
# The tree looks something like this:
#
# targets
# - x86_64-linux
# - engine
# - x86_64-linux
# - binary
# - docker
# - aarch64-linux
# - binary
# - docker
# - x86_64-darwin
# - binary
# - docker = null
# - aarch64-darwin
# - binary
# - docker = null
# - custom-connector
# - ...
# - aarch64-linux
# - ...
# - x86_64-darwin
# - ...
# - aarch64-darwin
# - ...
targets = pkgs.lib.attrsets.genAttrs binaries (binaryName:
pkgs.lib.attrsets.genAttrs targetSystems (targetSystem: {
binary = rust.${targetSystem}.callPackage ./nix/app.nix {
inherit version;
pname = binaryName;
packageName = binaryPackages.${binaryName} or binaryName;
};
docker =
if dockerArchitectures ? ${targetSystem}
then
pkgs.callPackage ./nix/docker.nix
{
package = self.targets.${localSystem}.${binaryName}.${targetSystem}.binary;
architecture = dockerArchitectures.${targetSystem};
image-name = "build.internal/${binaryName}-${targetSystem}";
extraConfig = dockerConfig.${binaryName} or { };
extraContents = dockerExtraContents.${binaryName} or [ ];
}
else null;
})
);
packages =
# binaries for the local system
pkgs.lib.attrsets.genAttrs binaries (binaryName: self.targets.${localSystem}.${binaryName}.${localSystem}.binary) // {
# `nix build` will build the default binary
default = self.packages.${localSystem}.${defaultBinary};
# a handy script to publish Docker images
publish-multi-arch-docker-image = pkgs.writeShellApplication {
name = "publish-multi-arch-docker-image";
runtimeInputs = with pkgs; [ coreutils skopeo ];
text = builtins.readFile ./.github/scripts/deploy-multi-arch.sh;
};
# a handy script to publish Docker images
publish-single-arch-docker-image = pkgs.writeShellApplication {
name = "publish-single-arch-docker-image";
runtimeInputs = with pkgs; [ coreutils skopeo ];
text = builtins.readFile ./.github/scripts/deploy-single-arch.sh;
};
};
# build an app per binary
apps = pkgs.lib.attrsets.genAttrs binaries
(binaryName:
flake-utils.lib.mkApp {
drv = self.packages.${localSystem}.${binaryName};
name = binaryName;
}
) // {
# the default app is the app wrapping the default binary
default = self.apps.${localSystem}.${defaultBinary};
};
devShells = {
default = pkgs.mkShell {
# include dependencies of the default package
inputsFrom = [ self.packages.${localSystem}.default ];
# build-time inputs
nativeBuildInputs = [
# Development
pkgs.just
pkgs.moreutils
pkgs.nixpkgs-fmt
pkgs.nodejs_22
pkgs.git
# Rust
pkgs.bacon
pkgs.cargo-audit
pkgs.cargo-edit
pkgs.cargo-expand
pkgs.cargo-flamegraph
pkgs.cargo-insta
pkgs.cargo-machete
pkgs.cargo-nextest
pkgs.cargo-watch
rust.${localSystem}.rustToolchain
];
};
};
});
}