Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
245 lines (208 loc) · 7.37 KB
/
Copy pathflake.nix
File metadata and controls
245 lines (208 loc) · 7.37 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
237
238
239
240
241
242
243
244
245
{
description = "Development and build environment for kellnr";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
nixpkgs,
flake-utils,
crane,
rust-overlay,
...
}:
flake-utils.lib.eachSystem [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ] (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
inherit (pkgs) lib;
# Rust toolchain with llvm-tools for coverage
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "llvm-tools-preview" ];
};
# Crane library for Rust builds
craneLib = (crane.mkLib pkgs).overrideToolchain (_: rustToolchain);
# Build the UI with buildNpmPackage
# NOTE: When package-lock.json changes, the npmDepsHash must be updated.
# For Dependabot PRs, the hash is auto-updated by the dependabot-nix-hash workflow.
# For manual updates, run: nix run nixpkgs#prefetch-npm-deps -- ui/package-lock.json
uiAssets = pkgs.buildNpmPackage {
pname = "kellnr-ui";
version = "0.1.0";
src = ./ui;
npmDepsHash = "sha256-kaFNWyvIjZPtQwTtnGVlW4AxBskfZUs88gXV7A8Ma5c=";
buildPhase = ''
npm run build
'';
installPhase = ''
cp -r dist $out
'';
nodejs = pkgs.nodejs_22;
};
# Source filtering for Rust
rustFilter =
path: type:
(craneLib.filterCargoSources path type) || (lib.hasInfix "crates/embedded-resources/static" path);
src = lib.cleanSourceWith {
src = craneLib.path ./.;
filter = rustFilter;
};
# Common Rust build arguments
commonArgs = {
inherit src;
strictDeps = true;
pname = "kellnr";
nativeBuildInputs = [
pkgs.cmake
pkgs.pkg-config
]
++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [
pkgs.rustPlatform.bindgenHook
];
buildInputs = [
pkgs.openssl.dev
]
++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
pkgs.libiconv
];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
OPENSSL_DIR = "${pkgs.openssl.dev}";
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
OPENSSL_NO_VENDOR = "1";
};
# Build dependencies separately for caching
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Playwright version sync check (tests/package.json vs nixpkgs)
testsPackageJson = builtins.fromJSON (builtins.readFile ./tests/package.json);
testsPlaywrightVersion =
let
raw = testsPackageJson.devDependencies."@playwright/test";
in
lib.removePrefix "~" (lib.removePrefix "^" raw);
nixpkgsPlaywrightVersion = pkgs.playwright-driver.version;
playwrightVersionsMatch = testsPlaywrightVersion == nixpkgsPlaywrightVersion;
# Build the full package
kellnr = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
doCheck = false;
# Copy UI assets before building
preBuild = ''
mkdir -p crates/embedded-resources/static
cp -r ${uiAssets}/* crates/embedded-resources/static/
'';
}
);
in
{
checks = {
inherit kellnr;
fmt = craneLib.cargoFmt { inherit src; };
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--workspace --all-targets -- --deny warnings";
}
);
};
packages = {
default = kellnr;
inherit kellnr uiAssets;
};
apps.default = flake-utils.lib.mkApp {
drv = kellnr;
};
devShells.default = craneLib.devShell {
inputsFrom = [ kellnr ];
packages =
with pkgs;
[
# Rust tools
rust-analyzer
cargo-nextest
cargo-machete
cdxgen
cargo-llvm-cov
# Node.js for UI development
nodejs_24
# Database tools
sea-orm-cli
# Dev utilities
just
lazygit
jq
curl
gnused
# Nix tools
nixpkgs-fmt
statix
# Testing
python3
playwright-driver.browsers
]
++ lib.optionals stdenv.hostPlatform.isLinux [
];
shellHook = ''
echo "Kellnr Development Environment"
echo "==============================="
echo "Rust version: $(rustc --version)"
echo "Node.js version: $(node --version)"
echo ""
echo "Commands:"
echo " just build - Build kellnr"
echo " just run - Run kellnr locally"
echo " just test - Run tests"
echo " just npm-dev - Run UI dev server"
echo " just sbom - Generate SBOM (CycloneDX)"
echo ""
# LLVM tools for cargo-llvm-cov
export LLVM_COV="${pkgs.llvmPackages.bintools-unwrapped}/bin/llvm-cov"
export LLVM_PROFDATA="${pkgs.llvmPackages.bintools-unwrapped}/bin/llvm-profdata"
# Playwright setup for NixOS
# Use pre-patched browsers from nixpkgs instead of downloading
export PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}"
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
echo "Playwright browsers: $PLAYWRIGHT_BROWSERS_PATH"
echo "Nixpkgs playwright version: ${nixpkgsPlaywrightVersion}"
${
if playwrightVersionsMatch then
''
echo "tests/package.json @playwright/test version: ${testsPlaywrightVersion} (matches)"
''
else
''
echo ""
echo "WARNING: Playwright version mismatch!"
echo " Nixpkgs playwright-driver: ${nixpkgsPlaywrightVersion}"
echo " tests/package.json @playwright/test: ${testsPlaywrightVersion}"
echo " Update tests/package.json so @playwright/test matches the nixpkgs version,"
echo " otherwise the bundled browsers will not be compatible with your tests."
echo ""
''
}
alias c=cargo
alias j=just
alias lg=lazygit
''
+ lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
export DYLD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$DYLD_LIBRARY_PATH"
'';
};
}
);
}