-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathflake.nix
More file actions
307 lines (280 loc) · 13.2 KB
/
Copy pathflake.nix
File metadata and controls
307 lines (280 loc) · 13.2 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-utils.url = "github:numtide/flake-utils";
plutus.url = "github:IntersectMBO/plutus/1.63.0.0";
# cardano-node-flake.url = "github:input-output-hk/cardano-node/9.1.1";
};
outputs =
{ self
, flake-utils
, nixpkgs
, plutus
# , cardano-node-flake
, ...
} @ inputs:
(flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config = {
# Explicitly set WebKitGTK ABI version to avoid evaluation warning
# WebKitGTK has multiple ABI versions (4.0, 4.1, 6.0) and Nix requires explicit selection
webkitgtk.abi = "4.1";
};
};
uplc = plutus.packages.${system}.uplc;
# secp256k1 with static library and required modules for JNI builds
secp256k1Static = pkgs.secp256k1.overrideAttrs (old: {
dontDisableStatic = true;
configureFlags = (old.configureFlags or [ ]) ++ [
"--enable-experimental"
"--enable-module-schnorrsig"
"--enable-module-extrakeys"
"--enable-module-ecdh"
];
});
# Common JVM options for both app and sbt JVM
commonDevJvmOpts = [
# Memory settings - use percentage of physical RAM for portability
"-XX:InitialRAMPercentage=25.0" # Initial heap: 25% of physical RAM
"-XX:MaxRAMPercentage=75.0" # Max heap: 75% of physical RAM
"-Xss64m" # Stack size for deep recursive calls in compiler
# Enable native access for BLST JNI library (required for Java 22+)
"--enable-native-access=ALL-UNNAMED"
# Enable experimental features for Java 23
"-XX:+UnlockExperimentalVMOptions" # Allow use of experimental VM options
# Garbage Collection - ZGC for ultra-low latency
# "-XX:+UseZGC" # Use Z Garbage Collector (concurrent, low-latency)
"-XX:+UseG1GC" # Use G1 Garbage Collector (stable, good for large heaps)
# Memory optimizations
"-XX:+UseStringDeduplication" # Deduplicate identical strings to save memory
"-XX:+OptimizeStringConcat" # Optimize string concatenation operations
# Code cache settings for better JIT performance
"-XX:ReservedCodeCacheSize=512m" # Reserve more space for compiled native code
"-XX:InitialCodeCacheSize=64m" # Start with larger initial code cache
# Compilation settings
"-XX:+TieredCompilation" # Use tiered compilation (C1 + C2 compilers)
# Memory efficiency
"-XX:+UseCompressedOops" # Use 32-bit pointers on 64-bit JVM (saves memory)
# Java 23 preview features
"--enable-preview" # Enable preview language features
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
# Linux-specific optimizations (not available on macOS)
"-XX:+UseTransparentHugePages" # Use OS huge pages for better memory performance
];
# cardano-cli = cardano-node-flake.packages.${system}.cardano-cli;
in
{
devShells = {
default =
let
jdk = pkgs.openjdk25;
graalvm = pkgs.graalvmPackages.graalvm-ce;
metals = pkgs.metals.override { jre = graalvm; };
bloop = pkgs.bloop.override { jre = graalvm; };
sbt = pkgs.sbt.override { jre = jdk; };
visualvm = pkgs.visualvm.override { jdk = jdk; };
# App-specific JVM options (runtime performance focused)
appJvmOpts = commonDevJvmOpts ++ [
# JIT compiler optimizations for better runtime performance
"-XX:MaxInlineLevel=15" # Allow deeper method inlining (Scala benefits from this)
"-XX:MaxInlineSize=270" # Allow larger methods to be inlined
"-XX:CompileThreshold=1000" # Compile methods to native code after 1000 invocations
];
# SBT-specific JVM options (optimized for long-running sbtn server)
sbtJvmOpts = commonDevJvmOpts ++ [
# NOTE: Do NOT use -XX:TieredStopAtLevel=1 here!
# While it speeds up initial startup, it prevents C2 JIT optimization
# which makes subsequent compilations 30-50% slower in long-running sbtn server
# JIT settings optimized for compilation workloads
"-XX:CompileThreshold=1000" # Compile hot methods after 1000 invocations
"-XX:+AlwaysPreTouch" # Pre-touch heap pages to avoid GC pauses during compilation
# SBT-specific optimizations
"-Dsbt.boot.lock=false" # Disable boot lock file (faster concurrent sbt instances)
"-Dsbt.turbo=true" # Enable turbo mode for faster task execution
"-Dsbt.supershell=false" # Disable supershell for cleaner output and slight speedup
];
in
pkgs.mkShell {
JAVA_HOME = "${jdk}";
JAVA_OPTS = builtins.concatStringsSep " " appJvmOpts;
SBT_OPTS = builtins.concatStringsSep " " sbtJvmOpts;
# Fixes issues with Node.js 20+ and OpenSSL 3 during webpack build
NODE_OPTIONS = "--openssl-legacy-provider";
# This fixes bash prompt/autocomplete issues with subshells (i.e. in VSCode) under `nix develop`/direnv
buildInputs = [ pkgs.bashInteractive ];
packages = with pkgs; [
git
gh
jdk
sbt
mill
metals
scalafmt
scalafix
coursier
bloop
niv
nixpkgs-fmt
nodejs
yarn
uplc
async-profiler
visualvm
llvm
clang
libsodium
secp256k1
blst
pandoc
texliveSmall
# cardano-cli
];
shellHook = ''
unlink plutus-conformance 2>/dev/null || true
ln -s ${plutus}/plutus-conformance plutus-conformance
echo "${pkgs.secp256k1}"
echo "${pkgs.libsodium}"
echo "${pkgs.async-profiler}"
# IMPORTANT: blst must NOT be in DYLD_LIBRARY_PATH/LD_LIBRARY_PATH
# Root cause: blst-java (JVM) bundles its own JNI native library with SWIG-generated
# symbols (e.g., new_P1__SWIG_2). The nix blst package is the raw C library without
# these JNI symbols. On macOS, JNI uses dlsym(RTLD_DEFAULT) which searches ALL loaded
# libraries for symbols. If nix blst is in the library path, its symbols conflict with
# blst-java's, causing UnsatisfiedLinkError for SWIG JNI functions.
# Solution: Keep blst in LIBRARY_PATH only (for Scala Native compile-time linking).
export DYLD_LIBRARY_PATH="${pkgs.secp256k1}/lib:${pkgs.libsodium}/lib:$DYLD_LIBRARY_PATH"
export LIBRARY_PATH="${pkgs.blst}/lib:${pkgs.secp256k1}/lib:${pkgs.libsodium}/lib:$LIBRARY_PATH"
export LD_LIBRARY_PATH="${pkgs.secp256k1}/lib:${pkgs.libsodium}/lib:$LD_LIBRARY_PATH"
# For Scala Native tests, provide blst path separately (used by build.sbt)
export BLST_NATIVE_LIB_PATH="${pkgs.blst}/lib"
'';
};
bench =
let
jdk = pkgs.openjdk25;
sbt = pkgs.sbt.override { jre = jdk; };
# Common JVM options for both app and sbt JVM
# App-specific JVM options (runtime performance focused)
appJvmOpts = commonDevJvmOpts ++ [
# JIT compiler optimizations for better runtime performance
"-XX:MaxInlineLevel=15" # Allow deeper method inlining (Scala benefits from this)
"-XX:MaxInlineSize=270" # Allow larger methods to be inlined
"-XX:CompileThreshold=1000" # Compile methods to native code after 1000 invocations
];
in
pkgs.mkShell {
JAVA_HOME = "${jdk}";
JAVA_OPTS = builtins.concatStringsSep " " appJvmOpts;
buildInputs = [ pkgs.bashInteractive ];
packages = with pkgs; [
git
jdk
sbt
];
};
ci =
let
# JDK 21: Scala 3.8+ requires JDK 17+ to run the compiler (3.3 LTS still
# supports JDK 8+). ci-jvm cross-builds on 3.8.4, so the CI shell must be >= 17.
jdk = pkgs.openjdk21;
sbt = pkgs.sbt.override { jre = jdk; };
# Common JVM options for CI environment (Java 21 - more conservative settings)
ciCommonJvmOpts = [
# Memory settings - fixed heap to avoid OOM on 16GB GitHub Actions runners.
# MaxRAMPercentage=75% gives ~12GB heap, leaving too little for Node.js
# (Scala.js tests), Nix, and OS — causing the OOM killer to SIGTERM the runner.
"-Xms2g" # Initial heap: 2GB
"-Xmx7g" # Max heap: 7GB (leaves ~9GB for Node.js, Nix, OS on 16GB runner)
"-Xss64m" # Stack size for deep recursive calls in compiler
# Garbage Collection - G1GC for stability
"-XX:+UseG1GC" # Use G1 Garbage Collector (stable, good for large heaps)
# Memory optimizations
"-XX:+UseStringDeduplication" # Deduplicate identical strings to save memory
# Code cache settings - enabled for better JIT performance
"-XX:ReservedCodeCacheSize=512m" # Reserve space for compiled native code
"-XX:InitialCodeCacheSize=64m" # Start with larger initial code cache
# Compilation settings
"-XX:+TieredCompilation" # Use tiered compilation (C1 + C2 compilers)
# Memory efficiency
"-XX:+UseCompressedOops" # Use 32-bit pointers on 64-bit JVM (saves memory)
];
# CI SBT-specific options (prioritize build speed for single-run builds)
ciSbtJvmOpts = ciCommonJvmOpts ++ [
# For CI single-run builds, TieredStopAtLevel=1 is acceptable since there's
# no warm JVM benefit. For builds > 15 min, consider removing this flag.
# "-XX:TieredStopAtLevel=1" # Stop at C1 compiler (faster CI startup)
# "-XX:CompileThreshold=1500" # Higher threshold for native compilation
# CI-specific optimizations
"-Dsbt.boot.lock=false" # Disable boot lock (faster in containerized CI)
"-Dsbt.supershell=false" # Disable supershell for cleaner CI logs
];
in
pkgs.mkShell {
JAVA_HOME = "${jdk}";
JAVA_OPTS = builtins.concatStringsSep " " ciCommonJvmOpts;
SBT_OPTS = builtins.concatStringsSep " " ciSbtJvmOpts;
# Fixes issues with Node.js 20+ and OpenSSL 3 during webpack build
# Limit Node.js heap to avoid OOM when running Scala.js tests alongside JVM
NODE_OPTIONS = "--openssl-legacy-provider --max-old-space-size=2048";
# Fix locale warnings in CI
LC_ALL = "C";
LOCALE_ARCHIVE = pkgs.lib.optionalString pkgs.stdenv.isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive";
packages = with pkgs; [
jdk
sbt
nodejs
uplc
llvm
libsodium
secp256k1
blst
];
shellHook = ''
unlink plutus-conformance 2>/dev/null || true
ln -s ${plutus}/plutus-conformance plutus-conformance
# IMPORTANT: blst must NOT be in LD_LIBRARY_PATH (same issue as macOS DYLD_LIBRARY_PATH)
# See default shell comment for detailed explanation of blst-java JNI symbol conflict.
export LIBRARY_PATH="${pkgs.blst}/lib:${pkgs.secp256k1}/lib:${pkgs.libsodium}/lib:$LIBRARY_PATH"
export LD_LIBRARY_PATH="${pkgs.secp256k1}/lib:${pkgs.libsodium}/lib:$LD_LIBRARY_PATH"
# For Scala Native tests, provide blst path separately (used by build.sbt)
export BLST_NATIVE_LIB_PATH="${pkgs.blst}/lib"
'';
};
ci-secp =
let
jdk = pkgs.openjdk11;
sbt = pkgs.sbt.override { jre = jdk; };
in
pkgs.mkShell {
JAVA_HOME = "${jdk}";
SECP256K1_HOME = "${secp256k1Static}";
packages = [
jdk
sbt
pkgs.clang
secp256k1Static
];
};
};
})
);
nixConfig = {
extra-substituters = [
"https://cache.iog.io"
"https://iohk.cachix.org"
"https://cache.nixos.org/"
"https://nix-community.cachix.org"
];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
"iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo="
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
allow-import-from-derivation = true;
experimental-features = [ "nix-command" "flakes" ];
accept-flake-config = true;
};
}