|
1 | 1 | { |
2 | 2 | lib, |
3 | | - callPackage, |
4 | | - nix-gitignore, |
| 3 | + stdenv, |
| 4 | + makeWrapper, |
5 | 5 |
|
6 | | - pyproject-nix, |
7 | | - pyproject-build-systems, |
8 | | - uv2nix, |
| 6 | + clang, |
| 7 | + cmake, |
| 8 | + git, |
| 9 | + k, |
| 10 | + boost, |
| 11 | + mpfr, |
| 12 | + openssl, |
| 13 | + gmp, |
| 14 | + secp256k1, |
| 15 | + which, |
9 | 16 |
|
10 | | - python |
| 17 | + komet-node-pyk, |
| 18 | + rev ? null |
11 | 19 | }: |
12 | | -let |
13 | | - pyproject-util = callPackage pyproject-nix.build.util {}; |
14 | | - pyproject-packages = callPackage pyproject-nix.build.packages { |
15 | | - inherit python; |
16 | | - }; |
| 20 | +stdenv.mkDerivation { |
| 21 | + pname = "komet-node"; |
| 22 | + version = if (rev != null) then rev else "dirty"; |
17 | 23 |
|
18 | | - # load a uv workspace from a workspace root |
19 | | - workspace = uv2nix.lib.workspace.loadWorkspace { |
20 | | - workspaceRoot = lib.cleanSource (nix-gitignore.gitignoreSourcePure [ |
21 | | - ../../.gitignore |
22 | | - ".github/" |
23 | | - "result*" |
24 | | - # do not include submodule directories that might be initilized empty or non-existent due to nix/git |
25 | | - # otherwise cachix build might not match the version that is requested by `kup` |
26 | | - # TODO: for new projects, add your submodule directories that are not required for nix builds here! |
27 | | - # e.g., `"/docs/external-computation"` with `external-computation` being a git submodule directory |
28 | | - # "/docs/external-computation" |
29 | | - ] ../.. |
30 | | - ); |
31 | | - }; |
| 24 | + outputs = [ |
| 25 | + "bin" |
| 26 | + # contains kdist artifacts (the compiled K semantics) |
| 27 | + "out" |
| 28 | + # this empty `dev` output is required as we otherwise get cyclic dependencies between `bin` and `out` |
| 29 | + # this is due to a setup-hook creating references in a new directory `nix-support` in either `out` or `dev` |
| 30 | + "dev" |
| 31 | + ]; |
32 | 32 |
|
33 | | - # create overlay |
34 | | - lockFileOverlay = workspace.mkPyprojectOverlay { |
35 | | - # prefer "wheel" over "sdist" due to maintance overhead |
36 | | - # there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix |
37 | | - sourcePreference = "wheel"; |
38 | | - }; |
| 33 | + # The K sources for every kdist target (`soroban-semantics.*` from the `komet` |
| 34 | + # dependency and `komet-node.*` from this project) ship inside `komet-node-pyk`, |
| 35 | + # so there are no sources to unpack here; the build only needs a working |
| 36 | + # directory to place the kdist output into. |
| 37 | + dontUnpack = true; |
| 38 | + |
| 39 | + buildInputs = [ |
| 40 | + clang |
| 41 | + cmake |
| 42 | + git |
| 43 | + boost |
| 44 | + mpfr |
| 45 | + openssl |
| 46 | + gmp |
| 47 | + secp256k1 |
| 48 | + komet-node-pyk |
| 49 | + k |
| 50 | + ]; |
| 51 | + |
| 52 | + nativeBuildInputs = [ makeWrapper ]; |
| 53 | + |
| 54 | + dontUseCmakeConfigure = true; |
39 | 55 |
|
40 | | - buildSystemsOverlay = import ./build-systems-overlay.nix; |
41 | | - |
42 | | - # construct package set |
43 | | - pythonSet = pyproject-packages.overrideScope (lib.composeManyExtensions [ |
44 | | - # make build tools available by default as these are not necessarily specified in python lock files |
45 | | - pyproject-build-systems.overlays.default |
46 | | - # include all packages from the python lock file |
47 | | - lockFileOverlay |
48 | | - # add build system overrides to certain python packages |
49 | | - buildSystemsOverlay |
50 | | - ]); |
51 | | -in pyproject-util.mkApplication { |
52 | | - # default dependancy group enables no optional dependencies and no dependency-groups |
53 | | - venv = pythonSet.mkVirtualEnv "komet-node-env" workspace.deps.default; |
54 | | - package = pythonSet.komet-node; |
| 56 | + enableParallelBuilding = true; |
| 57 | + |
| 58 | + # `kdist` writes the compiled semantics under `$XDG_CACHE_HOME/kdist-<hash>/`. |
| 59 | + # Build the same targets the Makefile's `kdist-build` does. The `komet-node.*` |
| 60 | + # targets pull in `soroban-semantics.source` as a dependency automatically. |
| 61 | + # |
| 62 | + # Cap concurrency at 2 (matching the Makefile's `kdist-build`): each LLVM/Haskell |
| 63 | + # `kompile` job links a large generated interpreter and peaks at several GB of |
| 64 | + # RAM, so an unbounded `-j$NIX_BUILD_CORES` can OOM the builder on machines with |
| 65 | + # many cores but limited memory. |
| 66 | + buildPhase = '' |
| 67 | + runHook preBuild |
| 68 | + XDG_CACHE_HOME=$(pwd) ${ |
| 69 | + lib.optionalString |
| 70 | + (stdenv.isAarch64 && stdenv.isDarwin) |
| 71 | + "APPLE_SILICON=true" |
| 72 | + } kdist -v build -j2 'soroban-semantics.*' 'komet-node.*' |
| 73 | + runHook postBuild |
| 74 | + ''; |
| 75 | + |
| 76 | + installPhase = '' |
| 77 | + runHook preInstall |
| 78 | + mkdir -p $bin/bin |
| 79 | + mkdir -p $out/kdist |
| 80 | +
|
| 81 | + cp -r ./kdist-*/* $out/kdist/ |
| 82 | +
|
| 83 | + # Wrap the `komet-node` entrypoint so that, at runtime, it finds the compiled |
| 84 | + # semantics via `KDIST_DIR` and the K tools (krun/kore) via `PATH`. |
| 85 | + makeWrapper ${komet-node-pyk}/bin/komet-node $bin/bin/komet-node \ |
| 86 | + --prefix PATH : ${lib.makeBinPath [ which k ]} \ |
| 87 | + --set KDIST_DIR $out/kdist |
| 88 | + runHook postInstall |
| 89 | + ''; |
| 90 | + |
| 91 | + meta = { |
| 92 | + description = "Local development testnet for Stellar based on K semantics"; |
| 93 | + mainProgram = "komet-node"; |
| 94 | + }; |
55 | 95 | } |
0 commit comments