silverbullet: build from source (#521289)

This commit is contained in:
Marcin Serwin
2026-06-19 18:50:45 +00:00
committed by GitHub
3 changed files with 115 additions and 53 deletions
@@ -0,0 +1,55 @@
diff --git a/build/build_plugs.ts b/build/build_plugs.ts
index e72beaaa..e0660eef 100644
--- a/build/build_plugs.ts
+++ b/build/build_plugs.ts
@@ -42,41 +42,15 @@ export async function buildPlugsAndLibraries(options?: {
export function updateVersionFile(): Promise<void> {
return new Promise<void>((resolve, reject) => {
- const gitProcess = spawn("git", ["describe", "--tags", "--long"], {
- stdio: ["ignore", "pipe", "pipe"],
- });
-
- let stdout = "";
-
- gitProcess.stdout?.on("data", (data) => {
- stdout += data.toString();
- });
-
- gitProcess.on("close", async (code) => {
- let commitVersion = stdout.trim();
-
- if (!commitVersion || code !== 0) {
- // Probably no valid .git repo, fallback to GITHUB_SHA env var (used in CI)
- commitVersion = `${version}-${process.env.GITHUB_SHA || "unknown"}`;
- }
-
- const versionFilePath = "./public_version.ts";
- // Write version to file with date in YYYY-MM-DDTHH-MM-SSZ format attached to the version
- const versionContent = `export const publicVersion = "${commitVersion}-${new Date()
- .toISOString()
- .split(".")[0]
- .replaceAll(":", "-")
- .concat("Z")}";`;
-
- try {
- await writeFile(versionFilePath, versionContent, "utf-8");
- resolve();
- } catch (err) {
- reject(err);
- }
- });
-
- gitProcess.on("error", reject);
+ const versionFilePath = "./public_version.ts";
+ const versionContent = `export const publicVersion = "@version@";`;
+
+ try {
+ writeFile(versionFilePath, versionContent, "utf-8");
+ resolve();
+ } catch (err) {
+ reject(err);
+ }
});
}
+52 -53
View File
@@ -1,75 +1,74 @@
{
autoPatchelfHook,
common-updater-scripts,
fetchzip,
lib,
nixosTests,
stdenv,
stdenvNoCC,
writeShellScript,
fetchFromGitHub,
buildNpmPackage,
buildGoModule,
replaceVars,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
buildGoModule (finalAttrs: {
pname = "silverbullet";
version = "2.6.1";
version = "2.9.0";
src =
finalAttrs.passthru.sources.${stdenv.hostPlatform.system}
or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
src = fetchFromGitHub {
owner = "silverbulletmd";
repo = "silverbullet";
rev = finalAttrs.version;
hash = "sha256-XQ0OKkiQrrmwmdGXk3dcim/2qosenF3EG2lkglQQ/iY=";
};
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
vendorHash = "sha256-8zZlhVptJq8y3k2DBghJ0lPNcIcaZYkrxN67b6dNBPs=";
buildInputs = [ stdenv.cc.cc.lib ];
subPackages = [ "." ];
frontend = buildNpmPackage {
pname = "silverbullet-frontend";
inherit (finalAttrs) version src;
npmDepsHash = "sha256-Twcv3I3scF09onJQdYsc1zOFzMFPOEyPF7VPYa7LBko=";
patches = [
(replaceVars ./override-public-version.patch { inherit (finalAttrs) version; })
];
postBuild = ''
npm run build:plug-compile
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r client_bundle public_version.ts $out/
runHook postInstall
'';
};
preBuild = ''
cp -r ${finalAttrs.frontend}/client_bundle .
cp ${finalAttrs.frontend}/public_version.ts .
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp $src/silverbullet $out/bin/
install -Dm755 "$GOPATH/bin/silverbullet" $out/bin/silverbullet
runHook postInstall
'';
passthru = {
sources = {
"x86_64-linux" = fetchzip {
url = "https://github.com/silverbulletmd/silverbullet/releases/download/${finalAttrs.version}/silverbullet-server-linux-x86_64.zip";
hash = "sha256-m0bQ3J99WZ9CBrA7M2i7Sh/lOI5c+z/an+9bNfQZW4c=";
stripRoot = false;
};
"aarch64-linux" = fetchzip {
url = "https://github.com/silverbulletmd/silverbullet/releases/download/${finalAttrs.version}/silverbullet-server-linux-aarch64.zip";
hash = "sha256-BqTKMCpifX3Y5kFWQb/9exAjjTc/KeUhYtsHSR850qE=";
stripRoot = false;
};
"x86_64-darwin" = fetchzip {
url = "https://github.com/silverbulletmd/silverbullet/releases/download/${finalAttrs.version}/silverbullet-server-darwin-x86_64.zip";
hash = "sha256-sqvB9kEpMimcH/rtOc7lBMptu3Cdu6M3z85TfD9QuZ4=";
stripRoot = false;
};
"aarch64-darwin" = fetchzip {
url = "https://github.com/silverbulletmd/silverbullet/releases/download/${finalAttrs.version}/silverbullet-server-darwin-aarch64.zip";
hash = "sha256-K/4w4jsa+RIYQA9cW2U/oycJx7PfUzcdG6WjZswRLU0=";
stripRoot = false;
};
};
updateScript = writeShellScript "update-silverbullet" ''
NEW_VERSION="$1"
for platform in ${lib.escapeShellArgs finalAttrs.meta.platforms}; do
${lib.getExe' common-updater-scripts "update-source-version"} "silverbullet" "$NEW_VERSION" --ignore-same-version --source-key="sources.$platform"
done
'';
tests = {
inherit (nixosTests) silverbullet;
};
};
passthru.updateScript = ./update.sh;
meta = {
changelog = "https://github.com/silverbulletmd/silverbullet/blob/${finalAttrs.version}/website/CHANGELOG.md";
description = "Open-source, self-hosted, offline-capable Personal Knowledge Management (PKM) web application";
homepage = "https://silverbullet.md";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ aorith ];
maintainers = with lib.maintainers; [
aorith
CnTeng
];
mainProgram = "silverbullet";
platforms = builtins.attrNames finalAttrs.passthru.sources;
};
})
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix-update common-updater-scripts
set -euo pipefail
nix-update silverbullet --src-only --override-filename
update-source-version silverbullet --source-key=frontend.npmDeps --ignore-same-version
update-source-version silverbullet --source-key=goModules --ignore-same-version