refactor nix and add nimbleDeps package

This commit is contained in:
Ivan Folgueira Bande 2026-02-11 21:13:27 +01:00
parent f02b0b0297
commit 9f07a74210
No known key found for this signature in database
GPG Key ID: 3C117481F89E24A7
2 changed files with 76 additions and 44 deletions

View File

@ -12,9 +12,6 @@
zerokitRln,
}:
assert pkgs.lib.assertMsg ((src.submodules or true) == true)
"Unable to build without submodules. Append '?submodules=1#' to the URI.";
let
inherit (pkgs) stdenv lib writeScriptBin callPackage;
@ -28,13 +25,22 @@ let
copyWakunode2 = lib.elem "wakunode2" targets;
hasKnownInstallTarget = copyLibwaku || copyLiblogosdelivery || copyWakunode2;
nimbleDeps = callPackage ./deps.nix {
inherit src version revision;
};
in stdenv.mkDerivation {
pname = "logos-messaging-nim";
pname = "logos-message-delivery";
inherit src;
version = "${version}-${revision}";
inherit src;
env = {
ANDROID_SDK_ROOT="${pkgs.androidPkgs.sdk}";
ANDROID_NDK_HOME="${pkgs.androidPkgs.ndk}";
NIMFLAGS = "-d:disableMarchNative -d:git_revision_override=${revision}";
XDG_CACHE_HOME = "/tmp";
};
# Runtime dependencies
buildInputs = with pkgs; [
openssl gmp zip
];
@ -44,17 +50,11 @@ in stdenv.mkDerivation {
# Fix for Nim compiler calling 'git rev-parse' and 'lsb_release'.
fakeGit = writeScriptBin "git" "echo ${version}";
in with pkgs; [
cmake which zerokitRln nim-unwrapped-2_2 fakeGit
cmake which zerokitRln nim-unwrapped-2_2 fakeGit nimbleDeps
] ++ lib.optionals stdenv.isDarwin [
pkgs.darwin.cctools gcc # Necessary for libbacktrace
];
# Environment variables required for Android builds
ANDROID_SDK_ROOT = "${pkgs.androidPkgs.sdk}";
ANDROID_NDK_HOME = "${pkgs.androidPkgs.ndk}";
NIMFLAGS = "-d:disableMarchNative -d:git_revision_override=${revision}";
XDG_CACHE_HOME = "/tmp";
makeFlags = targets ++ [
"V=${toString verbosity}"
"QUICK_AND_DIRTY_COMPILER=${if quickAndDirty then "1" else "0"}"
@ -65,36 +65,13 @@ in stdenv.mkDerivation {
];
configurePhase = ''
patchShebangs . vendor/nimbus-build-system > /dev/null
export NIMBLE_DIR=$NIX_BUILD_TOP/nimbledeps
cp -r ${nimbleDeps}/nimbledeps $NIMBLE_DIR
cp ${nimbleDeps}/nimble.paths ./
chmod 775 -R $NIMBLE_DIR
# Fix relative paths to absolute paths
sed -i "s|./nimbledeps|$NIMBLE_DIR|g" nimble.paths
# build_nim.sh guards "rm -rf dist/checksums" with NIX_BUILD_TOP != "/build",
# but on macOS the nix sandbox uses /private/tmp/... so the check fails and
# dist/checksums (provided via preBuild) gets deleted. Fix the check to skip
# the removal whenever NIX_BUILD_TOP is set (i.e. any nix build).
substituteInPlace vendor/nimbus-build-system/scripts/build_nim.sh \
--replace 'if [[ "''${NIX_BUILD_TOP}" != "/build" ]]; then' \
'if [[ -z "''${NIX_BUILD_TOP}" ]]; then'
make nimbus-build-system-paths
make nimbus-build-system-nimble-dir
'';
# For the Nim v2.2.4 built with NBS we added sat and zippy
preBuild = lib.optionalString (!useSystemNim) ''
pushd vendor/nimbus-build-system/vendor/Nim
mkdir dist
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
'';
installPhase = if abidir != null then ''
@ -141,8 +118,8 @@ in stdenv.mkDerivation {
'';
meta = with pkgs.lib; {
description = "NWaku derivation to build libwaku for mobile targets using Android NDK and Rust.";
homepage = "https://github.com/status-im/nwaku";
description = "Logos-message-delivery derivation.";
homepage = "https://github.com/logos-messaging/logos-messaging-nim";
license = licenses.mit;
platforms = stableSystems;
};

55
nix/deps.nix Normal file
View File

@ -0,0 +1,55 @@
{ pkgs, stdenv, src, version, revision }:
stdenv.mkDerivation {
pname = "logos-delivery-nimble-deps";
version = "${version}-${revision}";
inherit src;
nativeBuildInputs = with pkgs; [
jq rsync git nimble cacert moreutils
];
configurePhase = ''
export XDG_CACHE_HOME=$TMPDIR
export NIMBLE_DIR=$NIX_BUILD_TOP/nimbledir
export HOME=$TMPDIR
'';
buildPhase = ''
nimble --version
nimble --silent --localdeps setup
nimble --silent --localdeps install -y --depsOnly
'';
installPhase = ''
mkdir -p $out/nimbledeps
cp nimble.paths $out/nimble.paths
rsync -ra \
--prune-empty-dirs \
--include='*/' \
--include='*.json' \
--include='*.nim' \
--include='*.nimble' \
--exclude='*' \
$NIMBLE_DIR/pkgs2 $out/nimbledeps
'';
fixupPhase = ''
# Replace build path with deterministic $out.
sed "s|$NIMBLE_DIR|./nimbledeps|g" $out/nimble.paths \
| sort | sponge $out/nimble.paths
# Nimble does not maintain order of files list.
for META_FILE in $(find $out -name nimblemeta.json); do
jq '.metaData.files |= sort' $META_FILE | sponge $META_FILE
done
'';
# Make this a fixed-output derivation to allows internet access for Nimble.
outputHash = "sha256-OnirsXLj4HMVTbk+b4fcC+1K9MSMJyae6I7JO16WDno=";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
}