bench: Nix build static linux/amd64 nostr-bench
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
This is a Nostr server written using Elixir and PostgreSQL.
|
This is a Nostr server written using Elixir and PostgreSQL.
|
||||||
|
|
||||||
NOTE: Nostr and NIP specs are available in `~/nostr/` and `~/nips/`.
|
NOTE: NIP specs are available in `./docs/nips/`.
|
||||||
|
|
||||||
## Project guidelines
|
## Project guidelines
|
||||||
|
|
||||||
- Use `mix precommit` alias when you are done with all changes and fix any pending issues
|
- Use `mix precommit` alias when you are done with all changes and fix any pending issues
|
||||||
- Use the already included and available `:req` (`Req`) library for HTTP requests, **avoid** `:httpoison`, `:tesla`, and `:httpc`.
|
- Use the already included and available `:req` (`Req`) library for HTTP requests, **avoid** `:httpoison`, `:tesla`, and `:httpc`.
|
||||||
|
- Use semantic prefixes in commit messages (feat:, fix:, docs:, chore:, test:, build:, ci:, bench:, dev:)
|
||||||
|
|
||||||
<!-- usage-rules-start -->
|
<!-- usage-rules-start -->
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,15 @@
|
|||||||
pkgs = import nixpkgs {inherit system;};
|
pkgs = import nixpkgs {inherit system;};
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
parrhesia = pkgs.callPackage ./default.nix {};
|
parrhesia = pkgs.callPackage ./default.nix {};
|
||||||
|
nostrBench = pkgs.callPackage ./nix/nostr-bench.nix {};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
default = parrhesia;
|
default = parrhesia;
|
||||||
inherit parrhesia;
|
inherit parrhesia nostrBench;
|
||||||
}
|
}
|
||||||
// lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
// lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
||||||
|
nostrBenchStaticX86_64Musl = pkgs.callPackage ./nix/nostr-bench.nix {staticX86_64Musl = true;};
|
||||||
|
|
||||||
dockerImage = pkgs.dockerTools.buildLayeredImage {
|
dockerImage = pkgs.dockerTools.buildLayeredImage {
|
||||||
name = "parrhesia";
|
name = "parrhesia";
|
||||||
tag = "latest";
|
tag = "latest";
|
||||||
|
|||||||
2326
nix/nostr-bench-static.Cargo.lock
generated
Normal file
2326
nix/nostr-bench-static.Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,19 +2,38 @@
|
|||||||
lib,
|
lib,
|
||||||
fetchFromGitHub,
|
fetchFromGitHub,
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
}:
|
pkgsCross,
|
||||||
rustPlatform.buildRustPackage rec {
|
runCommand,
|
||||||
pname = "nostr-bench";
|
staticX86_64Musl ? false,
|
||||||
version = "0.4.0";
|
}: let
|
||||||
|
selectedRustPlatform =
|
||||||
|
if staticX86_64Musl
|
||||||
|
then pkgsCross.musl64.rustPlatform
|
||||||
|
else rustPlatform;
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
srcBase = fetchFromGitHub {
|
||||||
owner = "rnostr";
|
owner = "rnostr";
|
||||||
repo = pname;
|
repo = "nostr-bench";
|
||||||
rev = "d3ab701512b7c871707b209ef3f934936e407963";
|
rev = "d3ab701512b7c871707b209ef3f934936e407963";
|
||||||
hash = "sha256-F2qg1veO1iNlVUKf1b/MV+vexiy4Tt+w2aikDDbp7tU=";
|
hash = "sha256-F2qg1veO1iNlVUKf1b/MV+vexiy4Tt+w2aikDDbp7tU=";
|
||||||
};
|
};
|
||||||
|
|
||||||
cargoHash = "sha256-mh9UdYhZl6JVJEeDFnY5BjfcK+PrWBBEn1Qh7/ZX17k=";
|
src =
|
||||||
|
if staticX86_64Musl
|
||||||
|
then
|
||||||
|
runCommand "nostr-bench-static-src" {} ''
|
||||||
|
cp -r ${srcBase} $out
|
||||||
|
chmod -R u+w $out
|
||||||
|
cp ${./nostr-bench-static.Cargo.lock} $out/Cargo.lock
|
||||||
|
''
|
||||||
|
else srcBase;
|
||||||
|
in
|
||||||
|
selectedRustPlatform.buildRustPackage (
|
||||||
|
{
|
||||||
|
pname = "nostr-bench";
|
||||||
|
version = "0.4.0";
|
||||||
|
|
||||||
|
inherit src;
|
||||||
|
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
|
|
||||||
@@ -26,3 +45,12 @@ rustPlatform.buildRustPackage rec {
|
|||||||
platforms = platforms.unix;
|
platforms = platforms.unix;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// lib.optionalAttrs staticX86_64Musl {
|
||||||
|
cargoHash = "sha256-aL8XSBJ8sHl7CGh9SkOoI+WlAHKrdij2DfvZAWIKgKY=";
|
||||||
|
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
|
||||||
|
RUSTFLAGS = "-C target-feature=+crt-static";
|
||||||
|
}
|
||||||
|
// lib.optionalAttrs (!staticX86_64Musl) {
|
||||||
|
cargoHash = "sha256-mh9UdYhZl6JVJEeDFnY5BjfcK+PrWBBEn1Qh7/ZX17k=";
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ Options:
|
|||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- Requires hcloud, ssh, scp, ssh-keygen, git.
|
- Requires hcloud, ssh, scp, ssh-keygen, git.
|
||||||
- Requires docker locally to build portable nostr-bench binary.
|
- Tries nix .#nostrBenchStaticX86_64Musl first; falls back to docker-built portable nostr-bench.
|
||||||
- If --parrhesia-image is omitted, requires nix locally.
|
- If --parrhesia-image is omitted, requires nix locally.
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
@@ -336,38 +336,57 @@ async function ensureLocalPrereqs(opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function buildNostrBenchBinary(tmpDir) {
|
async function buildNostrBenchBinary(tmpDir) {
|
||||||
|
const outPath = path.join(tmpDir, "nostr-bench");
|
||||||
|
|
||||||
|
const staticLinked = (fileOutput) => fileOutput.includes("statically linked") || fileOutput.includes("static-pie linked");
|
||||||
|
|
||||||
|
const copyAndValidateBinary = async (binaryPath, buildMode) => {
|
||||||
|
const fileOut = await runCommand("file", [binaryPath]);
|
||||||
|
|
||||||
|
if (!(fileOut.stdout.includes("/lib64/ld-linux-x86-64.so.2") || staticLinked(fileOut.stdout))) {
|
||||||
|
throw new Error(`Built nostr-bench binary does not look portable: ${fileOut.stdout.trim()}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.copyFileSync(binaryPath, outPath);
|
||||||
|
fs.chmodSync(outPath, 0o755);
|
||||||
|
|
||||||
|
const copiedFileOut = await runCommand("file", [outPath]);
|
||||||
|
console.log(`[local] nostr-bench ready (${buildMode}): ${outPath}`);
|
||||||
|
console.log(`[local] ${copiedFileOut.stdout.trim()}`);
|
||||||
|
|
||||||
|
return { path: outPath, buildMode };
|
||||||
|
};
|
||||||
|
|
||||||
|
if (commandExists("nix")) {
|
||||||
|
try {
|
||||||
|
console.log("[local] building nostr-bench static binary via nix flake output .#nostrBenchStaticX86_64Musl...");
|
||||||
|
|
||||||
|
const nixOut = (
|
||||||
|
await runCommand("nix", ["build", ".#nostrBenchStaticX86_64Musl", "--print-out-paths", "--no-link"], {
|
||||||
|
cwd: ROOT_DIR,
|
||||||
|
})
|
||||||
|
).stdout.trim();
|
||||||
|
|
||||||
|
if (!nixOut) {
|
||||||
|
throw new Error("nix build did not return an output path");
|
||||||
|
}
|
||||||
|
|
||||||
|
const binaryPath = path.join(nixOut, "bin", "nostr-bench");
|
||||||
|
return await copyAndValidateBinary(binaryPath, "nix-flake-musl-static");
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`[local] nix static build unavailable, falling back to docker build: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const srcDir = path.join(tmpDir, "nostr-bench-src");
|
const srcDir = path.join(tmpDir, "nostr-bench-src");
|
||||||
console.log("[local] cloning nostr-bench source...");
|
console.log("[local] cloning nostr-bench source for docker fallback...");
|
||||||
await runCommand("git", ["clone", "--depth", "1", "https://github.com/rnostr/nostr-bench.git", srcDir], {
|
await runCommand("git", ["clone", "--depth", "1", "https://github.com/rnostr/nostr-bench.git", srcDir], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
});
|
});
|
||||||
|
|
||||||
let binaryPath = path.join(srcDir, "target", "x86_64-unknown-linux-musl", "release", "nostr-bench");
|
const binaryPath = path.join(srcDir, "target", "release", "nostr-bench");
|
||||||
let buildMode = "nix-musl-static";
|
|
||||||
|
|
||||||
console.log("[local] building nostr-bench (attempt static musl via nix run cargo)...");
|
console.log("[local] building portable glibc binary in rust:1-bookworm...");
|
||||||
let staticOk = false;
|
|
||||||
|
|
||||||
if (commandExists("nix")) {
|
|
||||||
try {
|
|
||||||
await runCommand(
|
|
||||||
"nix",
|
|
||||||
["run", "nixpkgs#cargo", "--", "build", "--release", "--target", "x86_64-unknown-linux-musl"],
|
|
||||||
{ cwd: srcDir, stdio: "inherit" },
|
|
||||||
);
|
|
||||||
|
|
||||||
const fileOut = await runCommand("file", [binaryPath]);
|
|
||||||
staticOk = fileOut.stdout.includes("statically linked");
|
|
||||||
} catch {
|
|
||||||
staticOk = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!staticOk) {
|
|
||||||
buildMode = "docker-glibc-portable";
|
|
||||||
binaryPath = path.join(srcDir, "target", "release", "nostr-bench");
|
|
||||||
|
|
||||||
console.log("[local] static build unavailable, building portable glibc binary in rust:1-bookworm...");
|
|
||||||
|
|
||||||
await runCommand(
|
await runCommand(
|
||||||
"docker",
|
"docker",
|
||||||
@@ -386,21 +405,7 @@ async function buildNostrBenchBinary(tmpDir) {
|
|||||||
{ stdio: "inherit" },
|
{ stdio: "inherit" },
|
||||||
);
|
);
|
||||||
|
|
||||||
const fileOut = await runCommand("file", [binaryPath]);
|
return await copyAndValidateBinary(binaryPath, "docker-glibc-portable");
|
||||||
if (!(fileOut.stdout.includes("/lib64/ld-linux-x86-64.so.2") || fileOut.stdout.includes("statically linked"))) {
|
|
||||||
throw new Error(`Built nostr-bench binary does not look portable: ${fileOut.stdout.trim()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const outPath = path.join(tmpDir, "nostr-bench");
|
|
||||||
fs.copyFileSync(binaryPath, outPath);
|
|
||||||
fs.chmodSync(outPath, 0o755);
|
|
||||||
|
|
||||||
const fileOut = await runCommand("file", [outPath]);
|
|
||||||
console.log(`[local] nostr-bench ready (${buildMode}): ${outPath}`);
|
|
||||||
console.log(`[local] ${fileOut.stdout.trim()}`);
|
|
||||||
|
|
||||||
return { path: outPath, buildMode };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildParrhesiaArchiveIfNeeded(opts, tmpDir) {
|
async function buildParrhesiaArchiveIfNeeded(opts, tmpDir) {
|
||||||
|
|||||||
Reference in New Issue
Block a user