From 9a458c2fd4812502151100b6fadad99ef99bf1bd Mon Sep 17 00:00:00 2001 From: markoburcul Date: Tue, 30 Dec 2025 14:41:52 +0100 Subject: [PATCH] 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 --- flake.nix | 13 ++++++++++++- nix/checksums.nix | 2 +- nix/default.nix | 48 +++++++++++++++++++++++++++++++++++++---------- nix/nimble.nix | 2 +- nix/shell.nix | 1 + nix/zippy.nix | 9 +++++++++ 6 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 nix/zippy.nix diff --git a/flake.nix b/flake.nix index 72eaebef1..e6f3d26d0 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; diff --git a/nix/checksums.nix b/nix/checksums.nix index 510f2b41a..c9c9f3d45 100644 --- a/nix/checksums.nix +++ b/nix/checksums.nix @@ -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="; } diff --git a/nix/default.nix b/nix/default.nix index d78f9935f..95851c01b 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -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; { diff --git a/nix/nimble.nix b/nix/nimble.nix index f9d87da6d..337ecd672 100644 --- a/nix/nimble.nix +++ b/nix/nimble.nix @@ -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="; } diff --git a/nix/shell.nix b/nix/shell.nix index 0db73dc25..fe0b065b4 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -16,6 +16,7 @@ pkgs.mkShell { git cargo rustup + rustc cmake nim-unwrapped-2_0 ]; diff --git a/nix/zippy.nix b/nix/zippy.nix new file mode 100644 index 000000000..ec59dfc07 --- /dev/null +++ b/nix/zippy.nix @@ -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="; +} \ No newline at end of file