From 2269a48d076825704991c7fd82e9a621556697d7 Mon Sep 17 00:00:00 2001 From: CnTeng Date: Wed, 27 May 2026 20:03:32 +0800 Subject: [PATCH] silverbullet: build from source --- .../override-public-version.patch | 55 +++++++++ pkgs/by-name/si/silverbullet/package.nix | 105 +++++++++--------- pkgs/by-name/si/silverbullet/update.sh | 8 ++ 3 files changed, 115 insertions(+), 53 deletions(-) create mode 100644 pkgs/by-name/si/silverbullet/override-public-version.patch create mode 100755 pkgs/by-name/si/silverbullet/update.sh diff --git a/pkgs/by-name/si/silverbullet/override-public-version.patch b/pkgs/by-name/si/silverbullet/override-public-version.patch new file mode 100644 index 000000000000..9a1d7adf945f --- /dev/null +++ b/pkgs/by-name/si/silverbullet/override-public-version.patch @@ -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 { + return new Promise((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); ++ } + }); + } + diff --git a/pkgs/by-name/si/silverbullet/package.nix b/pkgs/by-name/si/silverbullet/package.nix index a19b6933f0e4..7233001a3c63 100644 --- a/pkgs/by-name/si/silverbullet/package.nix +++ b/pkgs/by-name/si/silverbullet/package.nix @@ -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; }; }) diff --git a/pkgs/by-name/si/silverbullet/update.sh b/pkgs/by-name/si/silverbullet/update.sh new file mode 100755 index 000000000000..bc71173f4548 --- /dev/null +++ b/pkgs/by-name/si/silverbullet/update.sh @@ -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