diff options
Diffstat (limited to 'pkgs/by-name/si/siyuan/package.nix')
-rw-r--r-- | pkgs/by-name/si/siyuan/package.nix | 100 |
1 files changed, 67 insertions, 33 deletions
diff --git a/pkgs/by-name/si/siyuan/package.nix b/pkgs/by-name/si/siyuan/package.nix index e019f507cceaf..1059a57264398 100644 --- a/pkgs/by-name/si/siyuan/package.nix +++ b/pkgs/by-name/si/siyuan/package.nix @@ -1,29 +1,42 @@ { lib, + stdenv, fetchFromGitHub, buildGoModule, - buildNpmPackage, substituteAll, pandoc, + nodejs, + pnpm_9, electron, + makeWrapper, }: -buildNpmPackage rec { +let + pnpm = pnpm_9; + + platformIds = { + "x86_64-linux" = "linux"; + "aarch64-linux" = "linux-arm64"; + }; + + platformId = platformIds.${stdenv.system} or (throw "Unsupported platform: ${stdenv.system}"); +in +stdenv.mkDerivation (finalAttrs: { pname = "siyuan"; - version = "3.0.11"; + version = "3.1.0"; src = fetchFromGitHub { owner = "siyuan-note"; repo = "siyuan"; - rev = "v${version}"; - hash = "sha256-s82g5os944us85V2TBnm+HNd37vVzNjaOJYrbBrgLSI="; + rev = "v${finalAttrs.version}"; + hash = "sha256-UIPASTSW7YGpxJJHfCq28M/U6CzyqaJiISZGtE0aDPw="; }; kernel = buildGoModule { - name = "${pname}-${version}-kernel"; - inherit src; - sourceRoot = "${src.name}/kernel"; - vendorHash = "sha256-onZBrw0fDsjqXgQF06C40ArxNmsbFDIwD57fJ0jB0ls="; + name = "${finalAttrs.pname}-${finalAttrs.version}-kernel"; + inherit (finalAttrs) src; + sourceRoot = "${finalAttrs.src.name}/kernel"; + vendorHash = "sha256-s4dW43Qy3Lrc5WPpugQpN6BDEFVxqnorXpp40SGFk7I="; patches = [ (substituteAll { @@ -40,34 +53,58 @@ buildNpmPackage rec { substituteInPlace vendor/github.com/88250/gulu/file.go \ --replace-fail "os.Chmod(dest, sourceinfo.Mode())" "os.Chmod(dest, 0644)" ''; - }; - sourceRoot = "${src.name}/app"; + # Set flags and tags as per upstream's Dockerfile + ldflags = [ + "-s" + "-w" + "-X" + "github.com/siyuan-note/siyuan/kernel/util.Mode=prod" + ]; + tags = [ "fts5" ]; + }; - postPatch = '' - ln -s ${./package-lock.json} package-lock.json - # for some reason the default page is broken, use the redirection link automatically - substituteInPlace electron/main.js \ - --replace-fail ' "/stage/build/app/index.html?v=" + new Date().getTime()' '"/stage/build/desktop"' - ''; + nativeBuildInputs = [ + nodejs + pnpm.configHook + makeWrapper + ]; + + pnpmDeps = pnpm.fetchDeps { + inherit (finalAttrs) + pname + version + src + sourceRoot + ; + hash = "sha256-QSaBNs0m13Pfrvl8uUVqRpP3m8PoOBIY5VU5Cg/G2jY="; + }; - npmDepsHash = "sha256-Yv/iOCyry3CNeKPxS206Y5y5mvzPU873PJdi0UQkVLs="; + sourceRoot = "${finalAttrs.src.name}/app"; env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1"; - npmBuildScript = "build:desktop"; + postConfigure = '' + # remove prebuilt pandoc archives + rm -r pandoc + + # link kernel into the correct starting place so that electron-builder can copy it to it's final location + mkdir kernel-${platformId} + ln -s ${finalAttrs.kernel}/bin/kernel kernel-${platformId}/SiYuan-Kernel + ''; + + buildPhase = '' + runHook preBuild - postBuild = '' - substituteInPlace electron-builder-linux.yml \ - --replace-fail '- target: "AppImage"' "" \ - --replace-fail '- target: "tar.gz"' '- target: "dir"' + pnpm build - # add extra fields to resolve the electron provided by nixpkgs - sed -e 1i'electronDist: ${electron}/libexec/electron' \ - -e 1i'electronVersion: ${electron.version}' \ - -i electron-builder-linux.yml + npm exec electron-builder -- \ + --dir \ + --config electron-builder-${platformId}.yml \ + -c.electronDist=${electron}/libexec/electron \ + -c.electronVersion=${electron.version} - npm run dist-linux + runHook postBuild ''; installPhase = '' @@ -76,9 +113,6 @@ buildNpmPackage rec { mkdir -p $out/share/siyuan cp -r build/*-unpacked/{locales,resources{,.pak}} $out/share/siyuan - mkdir $out/share/siyuan/resources/kernel - ln -s ${kernel}/bin/kernel $out/share/siyuan/resources/kernel/SiYuan-Kernel - makeWrapper ${lib.getExe electron} $out/bin/siyuan \ --chdir $out/share/siyuan/resources \ --add-flags $out/share/siyuan/resources/app \ @@ -95,6 +129,6 @@ buildNpmPackage rec { license = lib.licenses.agpl3Plus; mainProgram = "siyuan"; maintainers = with lib.maintainers; [ tomasajt ]; - platforms = lib.platforms.linux; + platforms = lib.attrNames platformIds; }; -} +}) |