forked from khadar1020/lana-bank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
236 lines (212 loc) · 7.28 KB
/
Copy pathflake.nix
File metadata and controls
236 lines (212 loc) · 7.28 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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
{
description = "Lana";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
crane.url = "github:ipetkov/crane";
};
outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
}:
flake-utils.lib.eachDefaultSystem
(system: let
overlays = [
(self: super: {
nodejs = super.nodejs_20;
})
(import rust-overlay)
];
pkgs = import nixpkgs {
inherit system overlays;
};
craneLib = crane.mkLib pkgs;
# craneLib = craneLib.crateNameFromCargoToml {cargoToml = "./path/to/Cargo.toml";};
rustSource = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
craneLib.filterCargoSources path type
|| pkgs.lib.hasInfix "/lib/authz/src/rbac.conf" path
|| pkgs.lib.hasInfix "/.sqlx/" path
|| pkgs.lib.hasInfix "/lana/app/migrations/" path
|| pkgs.lib.hasInfix "/lana/notification/src/email/templates/" path;
};
# Function to build cargo artifacts for a specific profile
mkCargoArtifacts = profile:
craneLib.buildDepsOnly {
src = rustSource;
strictDeps = true;
cargoToml = ./Cargo.toml;
pname = "lana-workspace-deps-${profile}";
version = "0.0.0";
CARGO_PROFILE = profile;
SQLX_OFFLINE = true;
cargoExtraArgs = "--features sim-time";
};
# Function to build lana-cli for a specific profile
mkLanaCli = profile: let
cargoArtifacts = mkCargoArtifacts profile;
in
craneLib.buildPackage {
src = rustSource;
strictDeps = true;
cargoToml = ./lana/cli/Cargo.toml;
inherit cargoArtifacts;
doCheck = false;
pname = "lana-cli";
CARGO_PROFILE = profile;
SQLX_OFFLINE = true;
cargoExtraArgs = "-p lana-cli --features sim-time";
};
# Function to build static lana-cli (musl target for containers)
mkLanaCliStatic = profile: let
rustTarget = "x86_64-unknown-linux-musl";
# Build dependencies specifically for the musl target
cargoArtifactsStatic = craneLibMusl.buildDepsOnly {
src = rustSource;
strictDeps = true;
cargoToml = ./Cargo.toml;
pname = "lana-workspace-deps-${profile}-musl";
version = "0.0.0";
CARGO_PROFILE = profile;
SQLX_OFFLINE = true;
CARGO_BUILD_TARGET = rustTarget;
cargoExtraArgs = "--features sim-time,sim-bootstrap --target ${rustTarget}";
# Add musl target dependencies
depsBuildBuild = with pkgs; [
pkgsCross.musl64.stdenv.cc
];
# Environment variables for static linking
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = "${pkgs.pkgsCross.musl64.stdenv.cc}/bin/x86_64-unknown-linux-musl-gcc";
CC_x86_64_unknown_linux_musl = "${pkgs.pkgsCross.musl64.stdenv.cc}/bin/x86_64-unknown-linux-musl-gcc";
TARGET_CC = "${pkgs.pkgsCross.musl64.stdenv.cc}/bin/x86_64-unknown-linux-musl-gcc";
};
in
craneLibMusl.buildPackage {
src = rustSource;
strictDeps = true;
cargoToml = ./lana/cli/Cargo.toml;
cargoArtifacts = cargoArtifactsStatic;
doCheck = false;
pname = "lana-cli-static";
CARGO_PROFILE = profile;
SQLX_OFFLINE = true;
CARGO_BUILD_TARGET = rustTarget;
cargoExtraArgs = "-p lana-cli --features sim-time,sim-bootstrap --target ${rustTarget}";
# Add musl target for static linking
depsBuildBuild = with pkgs; [
pkgsCross.musl64.stdenv.cc
];
# Environment variables for static linking
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = "${pkgs.pkgsCross.musl64.stdenv.cc}/bin/x86_64-unknown-linux-musl-gcc";
CC_x86_64_unknown_linux_musl = "${pkgs.pkgsCross.musl64.stdenv.cc}/bin/x86_64-unknown-linux-musl-gcc";
TARGET_CC = "${pkgs.pkgsCross.musl64.stdenv.cc}/bin/x86_64-unknown-linux-musl-gcc";
};
# Build artifacts and packages for both profiles
debugCargoArtifacts = mkCargoArtifacts "dev";
releaseCargoArtifacts = mkCargoArtifacts "release";
lana-cli-debug = mkLanaCli "dev";
lana-cli-release = mkLanaCli "release";
lana-cli-static = mkLanaCliStatic "release";
meltano = pkgs.callPackage ./meltano.nix {};
mkAlias = alias: command: pkgs.writeShellScriptBin alias command;
rustVersion = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustToolchain = rustVersion.override {
extensions = ["rust-analyzer" "rust-src"];
targets = ["x86_64-unknown-linux-musl"];
};
# Separate toolchain for musl cross-compilation
rustToolchainMusl = rustVersion.override {
extensions = ["rust-src"];
targets = ["x86_64-unknown-linux-musl"];
};
# Create a separate Crane lib for musl builds
craneLibMusl = (crane.mkLib pkgs).overrideToolchain rustToolchainMusl;
nativeBuildInputs = with pkgs;
[
wait4x
rustToolchain
opentofu
alejandra
ytt
sqlx-cli
cargo-nextest
cargo-audit
cargo-watch
cargo-deny
cargo-machete
bacon
typos
postgresql
docker-compose
bats
jq
nodejs
typescript
google-cloud-sdk
pnpm
vendir
netlify-cli
pandoc
nano
podman
podman-compose
cachix
ps
curl
tilt
procps
meltano
]
++ lib.optionals pkgs.stdenv.isLinux [
xvfb-run
cypress
python313Packages.weasyprint
slirp4netns
fuse-overlayfs
util-linux
psmisc
]
++ lib.optionals pkgs.stdenv.isDarwin [
darwin.apple_sdk.frameworks.SystemConfiguration
];
devEnvVars = rec {
OTEL_EXPORTER_OTLP_ENDPOINT = http://localhost:4317;
PGDATABASE = "pg";
PGUSER = "user";
PGPASSWORD = "password";
PGHOST = "127.0.0.1";
DATABASE_URL = "postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:5433/pg?sslmode=disable";
PG_CON = "${DATABASE_URL}";
CUSTODIAN_ENCRYPTION_KEY = "0000000000000000000000000000000000000000000000000000000000000000";
EVENT_SCHEMAS_OUT_DIR = "lana/entity-rollups/schemas";
};
in
with pkgs; {
packages = {
default = lana-cli-debug; # Debug as default
debug = lana-cli-debug;
release = lana-cli-release;
static = lana-cli-static;
inherit meltano;
};
apps.default = flake-utils.lib.mkApp {drv = lana-cli-debug;};
devShells.default = mkShell (devEnvVars
// {
inherit nativeBuildInputs;
shellHook = ''
export MELTANO_PROJECT_ROOT="$(pwd)/meltano"
'';
});
formatter = alejandra;
});
}