build: pin nostr-bench submodule in nix and cloud bench pipeline
This commit is contained in:
16
devenv.lock
16
devenv.lock
@@ -87,11 +87,27 @@
|
||||
"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": {
|
||||
"inputs": {
|
||||
"devenv": "devenv",
|
||||
"git-hooks": "git-hooks",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"nostr-bench-src": "nostr-bench-src",
|
||||
"pre-commit-hooks": [
|
||||
"git-hooks"
|
||||
]
|
||||
|
||||
@@ -73,7 +73,9 @@ in {
|
||||
vips.overrideAttrs (oldAttrs: {
|
||||
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
|
||||
with pkgs;
|
||||
[
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
inputs:
|
||||
nixpkgs:
|
||||
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.
|
||||
# allowUnfree: true
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
description = "Parrhesia Nostr relay";
|
||||
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
inputs.self.submodules = true;
|
||||
|
||||
outputs = {nixpkgs, ...}: let
|
||||
systems = [
|
||||
|
||||
Submodule nix/nostr-bench updated: d3ab701512...8561b84864
9
nix/nostr-bench-static.Cargo.lock
generated
9
nix/nostr-bench-static.Cargo.lock
generated
@@ -321,6 +321,12 @@ version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
|
||||
|
||||
[[package]]
|
||||
name = "bech32"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445"
|
||||
|
||||
[[package]]
|
||||
name = "bitcoin_hashes"
|
||||
version = "0.11.0"
|
||||
@@ -1249,6 +1255,7 @@ version = "0.19.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "377785e61e0da6a13226a4244e8c28b9a858aa0a5ed10830109f61ade1c2a3f2"
|
||||
dependencies = [
|
||||
"bech32",
|
||||
"bitcoin_hashes",
|
||||
"getrandom",
|
||||
"instant",
|
||||
@@ -1262,7 +1269,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nostr-bench"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0-parrhesia"
|
||||
dependencies = [
|
||||
"actix",
|
||||
"actix-web",
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
{
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
rustPlatform,
|
||||
pkgsCross,
|
||||
runCommand,
|
||||
staticX86_64Musl ? false,
|
||||
nostrBenchSrc ? ./nostr-bench,
|
||||
}: let
|
||||
selectedRustPlatform =
|
||||
if staticX86_64Musl
|
||||
then pkgsCross.musl64.rustPlatform
|
||||
else rustPlatform;
|
||||
|
||||
srcBase = fetchFromGitHub {
|
||||
owner = "rnostr";
|
||||
repo = "nostr-bench";
|
||||
rev = "d3ab701512b7c871707b209ef3f934936e407963";
|
||||
hash = "sha256-F2qg1veO1iNlVUKf1b/MV+vexiy4Tt+w2aikDDbp7tU=";
|
||||
};
|
||||
# Keep the submodule path as-is so devenv can evaluate it correctly.
|
||||
# `lib.cleanSource` treats submodule contents as untracked in this context.
|
||||
srcBase = nostrBenchSrc;
|
||||
|
||||
src =
|
||||
if staticX86_64Musl
|
||||
@@ -31,7 +28,7 @@ in
|
||||
selectedRustPlatform.buildRustPackage (
|
||||
{
|
||||
pname = "nostr-bench";
|
||||
version = "0.4.0";
|
||||
version = "0.5.0-parrhesia";
|
||||
|
||||
inherit src;
|
||||
|
||||
@@ -46,11 +43,11 @@ in
|
||||
};
|
||||
}
|
||||
// lib.optionalAttrs staticX86_64Musl {
|
||||
cargoHash = "sha256-aL8XSBJ8sHl7CGh9SkOoI+WlAHKrdij2DfvZAWIKgKY=";
|
||||
cargoHash = "sha256-098BUjDLiezoFXs7fF+w7NQM+DPPfHMo1HGx3nV2UZM=";
|
||||
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
|
||||
RUSTFLAGS = "-C target-feature=+crt-static";
|
||||
}
|
||||
// lib.optionalAttrs (!staticX86_64Musl) {
|
||||
cargoHash = "sha256-mh9UdYhZl6JVJEeDFnY5BjfcK+PrWBBEn1Qh7/ZX17k=";
|
||||
cargoHash = "sha256-x2pnxJL2nwni4cpSaUerDOfhdcTKJTyABYjPm96dAC0=";
|
||||
}
|
||||
)
|
||||
|
||||
@@ -35,6 +35,7 @@ const ESTIMATE_WINDOW_MINUTES = 30;
|
||||
const ESTIMATE_WINDOW_HOURS = ESTIMATE_WINDOW_MINUTES / 60;
|
||||
const ESTIMATE_WINDOW_LABEL = `${ESTIMATE_WINDOW_MINUTES}m`;
|
||||
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 SEED_TOLERANCE_RATIO = 0.01;
|
||||
const SEED_MAX_ROUNDS = 8;
|
||||
@@ -684,6 +685,32 @@ async function buildNostrBenchBinary(tmpDir) {
|
||||
|
||||
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 binaryLooksPortable = (fileOutput) =>
|
||||
@@ -736,12 +763,24 @@ async function buildNostrBenchBinary(tmpDir) {
|
||||
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 {
|
||||
const fileSummary = await validatePortableBinary(cachedBinaryPath);
|
||||
fs.chmodSync(cachedBinaryPath, 0o755);
|
||||
|
||||
const version = await readVersionIfRunnable(cachedBinaryPath, fileSummary, "cache-reuse");
|
||||
const metadata = readCacheMetadata();
|
||||
|
||||
console.log(`[local] reusing cached nostr-bench: ${cachedBinaryPath}`);
|
||||
if (metadata?.build_mode) {
|
||||
@@ -772,6 +811,8 @@ async function buildNostrBenchBinary(tmpDir) {
|
||||
writeCacheMetadata({
|
||||
build_mode: buildMode,
|
||||
built_at: new Date().toISOString(),
|
||||
source_fingerprint: sourceFingerprint,
|
||||
source_path: path.relative(ROOT_DIR, NOSTR_BENCH_SUBMODULE_DIR),
|
||||
binary_path: cachedBinaryPath,
|
||||
file_summary: copiedFileOut.stdout.trim(),
|
||||
version,
|
||||
@@ -813,10 +854,8 @@ async function buildNostrBenchBinary(tmpDir) {
|
||||
}
|
||||
|
||||
const srcDir = path.join(tmpDir, "nostr-bench-src");
|
||||
console.log("[local] cloning nostr-bench source for docker fallback...");
|
||||
await runCommand("git", ["clone", "--depth", "1", "https://github.com/rnostr/nostr-bench.git", srcDir], {
|
||||
stdio: "inherit",
|
||||
});
|
||||
console.log(`[local] preparing nostr-bench source from ${path.relative(ROOT_DIR, NOSTR_BENCH_SUBMODULE_DIR)} for docker fallback...`);
|
||||
fs.cpSync(NOSTR_BENCH_SUBMODULE_DIR, srcDir, { recursive: true });
|
||||
|
||||
const binaryPath = path.join(srcDir, "target", "release", "nostr-bench");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user