build: pin nostr-bench submodule in nix and cloud bench pipeline

This commit is contained in:
2026-03-20 17:07:35 +01:00
parent 6b59fa6328
commit 8f22eb2097
8 changed files with 83 additions and 18 deletions

View File

@@ -87,11 +87,27 @@
"type": "github" "type": "github"
} }
}, },
"nostr-bench-src": {
"flake": false,
"locked": {
"lastModified": 1774020724,
"owner": "serpent213",
"repo": "nostr-bench",
"rev": "8561b84864ce1269b26304808c64219471999caf",
"type": "github"
},
"original": {
"owner": "serpent213",
"repo": "nostr-bench",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"devenv": "devenv", "devenv": "devenv",
"git-hooks": "git-hooks", "git-hooks": "git-hooks",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nostr-bench-src": "nostr-bench-src",
"pre-commit-hooks": [ "pre-commit-hooks": [
"git-hooks" "git-hooks"
] ]

View File

@@ -73,7 +73,9 @@ in {
vips.overrideAttrs (oldAttrs: { vips.overrideAttrs (oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [mozjpeg]; buildInputs = oldAttrs.buildInputs ++ [mozjpeg];
}); });
nostr-bench = pkgs.callPackage ./nix/nostr-bench.nix {}; nostr-bench = pkgs.callPackage ./nix/nostr-bench.nix {
nostrBenchSrc = inputs.nostr-bench-src;
};
in in
with pkgs; with pkgs;
[ [

View File

@@ -2,6 +2,9 @@
inputs: inputs:
nixpkgs: nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling url: github:cachix/devenv-nixpkgs/rolling
nostr-bench-src:
url: github:serpent213/nostr-bench
flake: false
# If you're using non-OSS software, you can set allowUnfree to true. # If you're using non-OSS software, you can set allowUnfree to true.
# allowUnfree: true # allowUnfree: true

View File

@@ -2,6 +2,7 @@
description = "Parrhesia Nostr relay"; description = "Parrhesia Nostr relay";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.self.submodules = true;
outputs = {nixpkgs, ...}: let outputs = {nixpkgs, ...}: let
systems = [ systems = [

View File

@@ -321,6 +321,12 @@ version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
[[package]]
name = "bech32"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445"
[[package]] [[package]]
name = "bitcoin_hashes" name = "bitcoin_hashes"
version = "0.11.0" version = "0.11.0"
@@ -1249,6 +1255,7 @@ version = "0.19.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "377785e61e0da6a13226a4244e8c28b9a858aa0a5ed10830109f61ade1c2a3f2" checksum = "377785e61e0da6a13226a4244e8c28b9a858aa0a5ed10830109f61ade1c2a3f2"
dependencies = [ dependencies = [
"bech32",
"bitcoin_hashes", "bitcoin_hashes",
"getrandom", "getrandom",
"instant", "instant",
@@ -1262,7 +1269,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-bench" name = "nostr-bench"
version = "0.4.0" version = "0.5.0-parrhesia"
dependencies = [ dependencies = [
"actix", "actix",
"actix-web", "actix-web",

View File

@@ -1,22 +1,19 @@
{ {
lib, lib,
fetchFromGitHub,
rustPlatform, rustPlatform,
pkgsCross, pkgsCross,
runCommand, runCommand,
staticX86_64Musl ? false, staticX86_64Musl ? false,
nostrBenchSrc ? ./nostr-bench,
}: let }: let
selectedRustPlatform = selectedRustPlatform =
if staticX86_64Musl if staticX86_64Musl
then pkgsCross.musl64.rustPlatform then pkgsCross.musl64.rustPlatform
else rustPlatform; else rustPlatform;
srcBase = fetchFromGitHub { # Keep the submodule path as-is so devenv can evaluate it correctly.
owner = "rnostr"; # `lib.cleanSource` treats submodule contents as untracked in this context.
repo = "nostr-bench"; srcBase = nostrBenchSrc;
rev = "d3ab701512b7c871707b209ef3f934936e407963";
hash = "sha256-F2qg1veO1iNlVUKf1b/MV+vexiy4Tt+w2aikDDbp7tU=";
};
src = src =
if staticX86_64Musl if staticX86_64Musl
@@ -31,7 +28,7 @@ in
selectedRustPlatform.buildRustPackage ( selectedRustPlatform.buildRustPackage (
{ {
pname = "nostr-bench"; pname = "nostr-bench";
version = "0.4.0"; version = "0.5.0-parrhesia";
inherit src; inherit src;
@@ -46,11 +43,11 @@ in
}; };
} }
// lib.optionalAttrs staticX86_64Musl { // lib.optionalAttrs staticX86_64Musl {
cargoHash = "sha256-aL8XSBJ8sHl7CGh9SkOoI+WlAHKrdij2DfvZAWIKgKY="; cargoHash = "sha256-098BUjDLiezoFXs7fF+w7NQM+DPPfHMo1HGx3nV2UZM=";
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
RUSTFLAGS = "-C target-feature=+crt-static"; RUSTFLAGS = "-C target-feature=+crt-static";
} }
// lib.optionalAttrs (!staticX86_64Musl) { // lib.optionalAttrs (!staticX86_64Musl) {
cargoHash = "sha256-mh9UdYhZl6JVJEeDFnY5BjfcK+PrWBBEn1Qh7/ZX17k="; cargoHash = "sha256-x2pnxJL2nwni4cpSaUerDOfhdcTKJTyABYjPm96dAC0=";
} }
) )

View File

@@ -35,6 +35,7 @@ const ESTIMATE_WINDOW_MINUTES = 30;
const ESTIMATE_WINDOW_HOURS = ESTIMATE_WINDOW_MINUTES / 60; const ESTIMATE_WINDOW_HOURS = ESTIMATE_WINDOW_MINUTES / 60;
const ESTIMATE_WINDOW_LABEL = `${ESTIMATE_WINDOW_MINUTES}m`; const ESTIMATE_WINDOW_LABEL = `${ESTIMATE_WINDOW_MINUTES}m`;
const BENCH_BUILD_DIR = path.join(ROOT_DIR, "_build", "bench"); const BENCH_BUILD_DIR = path.join(ROOT_DIR, "_build", "bench");
const NOSTR_BENCH_SUBMODULE_DIR = path.join(ROOT_DIR, "nix", "nostr-bench");
const NOSTREAM_REDIS_IMAGE = "redis:7.0.5-alpine3.16"; const NOSTREAM_REDIS_IMAGE = "redis:7.0.5-alpine3.16";
const SEED_TOLERANCE_RATIO = 0.01; const SEED_TOLERANCE_RATIO = 0.01;
const SEED_MAX_ROUNDS = 8; const SEED_MAX_ROUNDS = 8;
@@ -684,6 +685,32 @@ async function buildNostrBenchBinary(tmpDir) {
fs.mkdirSync(cacheDir, { recursive: true }); fs.mkdirSync(cacheDir, { recursive: true });
if (!fs.existsSync(path.join(NOSTR_BENCH_SUBMODULE_DIR, "Cargo.toml"))) {
throw new Error(
`nostr-bench source not found at ${NOSTR_BENCH_SUBMODULE_DIR}. Run: git submodule update --init --recursive nix/nostr-bench`,
);
}
const resolveSourceFingerprint = async () => {
let revision = "unknown";
let dirty = false;
try {
revision = (await runCommand("git", ["-C", NOSTR_BENCH_SUBMODULE_DIR, "rev-parse", "HEAD"])).stdout.trim();
dirty = (await runCommand("git", ["-C", NOSTR_BENCH_SUBMODULE_DIR, "status", "--porcelain"])).stdout.trim().length > 0;
} catch {
// Fallback for non-git checkouts of the submodule source.
const lockPath = path.join(NOSTR_BENCH_SUBMODULE_DIR, "Cargo.lock");
const lockMtime = fs.existsSync(lockPath) ? fs.statSync(lockPath).mtimeMs : 0;
revision = `mtime-${Math.trunc(lockMtime)}`;
dirty = false;
}
return dirty ? `${revision}-dirty` : revision;
};
const sourceFingerprint = await resolveSourceFingerprint();
const staticLinked = (fileOutput) => fileOutput.includes("statically linked") || fileOutput.includes("static-pie linked"); const staticLinked = (fileOutput) => fileOutput.includes("statically linked") || fileOutput.includes("static-pie linked");
const binaryLooksPortable = (fileOutput) => const binaryLooksPortable = (fileOutput) =>
@@ -736,12 +763,24 @@ async function buildNostrBenchBinary(tmpDir) {
return null; return null;
} }
const metadata = readCacheMetadata();
if (!metadata?.source_fingerprint) {
console.log("[local] cached nostr-bench has no source fingerprint, rebuilding");
return null;
}
if (metadata.source_fingerprint !== sourceFingerprint) {
console.log(
`[local] nostr-bench source changed (${metadata.source_fingerprint} -> ${sourceFingerprint}), rebuilding cache`,
);
return null;
}
try { try {
const fileSummary = await validatePortableBinary(cachedBinaryPath); const fileSummary = await validatePortableBinary(cachedBinaryPath);
fs.chmodSync(cachedBinaryPath, 0o755); fs.chmodSync(cachedBinaryPath, 0o755);
const version = await readVersionIfRunnable(cachedBinaryPath, fileSummary, "cache-reuse"); const version = await readVersionIfRunnable(cachedBinaryPath, fileSummary, "cache-reuse");
const metadata = readCacheMetadata();
console.log(`[local] reusing cached nostr-bench: ${cachedBinaryPath}`); console.log(`[local] reusing cached nostr-bench: ${cachedBinaryPath}`);
if (metadata?.build_mode) { if (metadata?.build_mode) {
@@ -772,6 +811,8 @@ async function buildNostrBenchBinary(tmpDir) {
writeCacheMetadata({ writeCacheMetadata({
build_mode: buildMode, build_mode: buildMode,
built_at: new Date().toISOString(), built_at: new Date().toISOString(),
source_fingerprint: sourceFingerprint,
source_path: path.relative(ROOT_DIR, NOSTR_BENCH_SUBMODULE_DIR),
binary_path: cachedBinaryPath, binary_path: cachedBinaryPath,
file_summary: copiedFileOut.stdout.trim(), file_summary: copiedFileOut.stdout.trim(),
version, version,
@@ -813,10 +854,8 @@ async function buildNostrBenchBinary(tmpDir) {
} }
const srcDir = path.join(tmpDir, "nostr-bench-src"); const srcDir = path.join(tmpDir, "nostr-bench-src");
console.log("[local] cloning nostr-bench source for docker fallback..."); console.log(`[local] preparing nostr-bench source from ${path.relative(ROOT_DIR, NOSTR_BENCH_SUBMODULE_DIR)} for docker fallback...`);
await runCommand("git", ["clone", "--depth", "1", "https://github.com/rnostr/nostr-bench.git", srcDir], { fs.cpSync(NOSTR_BENCH_SUBMODULE_DIR, srcDir, { recursive: true });
stdio: "inherit",
});
const binaryPath = path.join(srcDir, "target", "release", "nostr-bench"); const binaryPath = path.join(srcDir, "target", "release", "nostr-bench");