nix: add libwaku target, fix compiling Nim using NBS

Use Nim built by NBS otherwise it doesn't work for both libwaku and
wakucanary.

Referenced issue:
* https://github.com/status-im/status-go/issues/7152
This commit is contained in:
Marko Burčul 2025-12-30 14:41:52 +01:00
parent dafdee9f5f
commit 9a458c2fd4
No known key found for this signature in database
GPG Key ID: FC4CD2F9A040D54A
6 changed files with 62 additions and 13 deletions

View File

@ -1,5 +1,5 @@
{
description = "NWaku build flake";
description = "Logos Messaging Nim build flake";
nixConfig = {
extra-substituters = [ "https://nix-cache.status.im/" ];
@ -54,10 +54,21 @@
zerokitRln = zerokit.packages.${system}.rln-android-arm64;
};
libwaku= pkgs.callPackage ./nix/default.nix {
inherit stableSystems;
src = self;
targets = ["libwaku"];
# We are not able to compile the code with nim-unwrapped-2_0
useSystemNim = false;
zerokitRln = zerokit.packages.${system}.rln;
};
wakucanary = pkgs.callPackage ./nix/default.nix {
inherit stableSystems;
src = self;
targets = ["wakucanary"];
# We are not able to compile the code with nim-unwrapped-2_0
useSystemNim = false;
zerokitRln = zerokit.packages.${system}.rln;
};

View File

@ -8,5 +8,5 @@ in pkgs.fetchFromGitHub {
repo = "checksums";
rev = tools.findKeyValue "^ +ChecksumsStableCommit = \"([a-f0-9]+)\".*$" sourceFile;
# WARNING: Requires manual updates when Nim compiler version changes.
hash = "sha256-Bm5iJoT2kAvcTexiLMFBa9oU5gf7d4rWjo3OiN7obWQ=";
hash = "sha256-JZhWqn4SrAgNw/HLzBK0rrj3WzvJ3Tv1nuDMn83KoYY=";
}

View File

@ -23,7 +23,7 @@ let
in stdenv.mkDerivation rec {
pname = "nwaku";
pname = "logos-messaging-nim";
version = "1.0.0-${revision}";
@ -72,6 +72,19 @@ in stdenv.mkDerivation rec {
"USE_SYSTEM_NIM=${if useSystemNim then "1" else "0"}"
];
postPatch = ''
cat > scripts/build_rln.sh << 'EOF'
#!/usr/bin/env bash
set -e
build_dir=$1
rln_version=$2
output_filename=$3
# Just copy the library we already have
cp ${zerokitRln}/target/release/librln.a "$output_filename"
EOF
chmod +x scripts/build_rln.sh
'';
configurePhase = ''
patchShebangs . vendor/nimbus-build-system > /dev/null
make nimbus-build-system-paths
@ -80,17 +93,25 @@ in stdenv.mkDerivation rec {
preBuild = ''
ln -s waku.nimble waku.nims
${lib.optionalString (!useSystemNim) ''
pushd vendor/nimbus-build-system/vendor/Nim
mkdir dist
cp -r ${callPackage ./nimble.nix {}} dist/nimble
cp -r ${callPackage ./checksums.nix {}} dist/checksums
cp -r ${callPackage ./csources.nix {}} csources_v2
mkdir -p dist/nimble/vendor/sat
mkdir -p dist/nimble/vendor/checksums
mkdir -p dist/nimble/vendor/zippy
cp -r ${callPackage ./nimble.nix {}}/. dist/nimble
cp -r ${callPackage ./checksums.nix {}}/. dist/checksums
cp -r ${callPackage ./csources.nix {}}/. csources_v2
cp -r ${callPackage ./sat.nix {}}/. dist/nimble/vendor/sat
cp -r ${callPackage ./checksums.nix {}}/. dist/nimble/vendor/checksums
cp -r ${callPackage ./zippy.nix {}}/. dist/nimble/vendor/zippy
chmod 777 -R dist/nimble csources_v2
popd
cp -r ${zerokitRln}/target vendor/zerokit/
find vendor/zerokit/target
# FIXME
cp vendor/zerokit/target/*/release/librln.a librln_v${zerokitRln.version}.a
''}
'';
installPhase = if abidir != null then ''
@ -99,8 +120,15 @@ in stdenv.mkDerivation rec {
echo '${androidManifest}' > $out/jni/AndroidManifest.xml
cd $out && zip -r libwaku.aar *
'' else ''
mkdir -p $out/bin
cp -r build/* $out/bin
mkdir -p $out/bin $out/include
# Copy library files
cp build/*.so $out/bin/ 2>/dev/null || true
cp build/*.a $out/bin/ 2>/dev/null || true
cp build/*.dylib $out/bin/ 2>/dev/null || true
# Copy the header file
cp library/libwaku.h $out/include/
'';
meta = with pkgs.lib; {

View File

@ -8,5 +8,5 @@ in pkgs.fetchFromGitHub {
repo = "nimble";
rev = tools.findKeyValue "^ +NimbleStableCommit = \"([a-f0-9]+)\".*$" sourceFile;
# WARNING: Requires manual updates when Nim compiler version changes.
hash = "sha256-MVHf19UbOWk8Zba2scj06PxdYYOJA6OXrVyDQ9Ku6Us=";
hash = "sha256-8iutVgNzDtttZ7V+7S11KfLEuwhKA9TsgS51mlUI08k=";
}

View File

@ -16,6 +16,7 @@ pkgs.mkShell {
git
cargo
rustup
rustc
cmake
nim-unwrapped-2_0
];

9
nix/zippy.nix Normal file
View File

@ -0,0 +1,9 @@
{ pkgs }:
pkgs.fetchFromGitHub {
owner = "guzba";
repo = "zippy";
rev = "a99f6a7d8a8e3e0213b3cad0daf0ea974bf58e3f";
# WARNING: Requires manual updates when Nim compiler version changes.
hash = "sha256-e2ma2Oyp0dlNx8pJsdZl5o5KnaoAX87tqfY0RLG3DZs=";
}