siyuan: support darwin (#521546)

This commit is contained in:
Toma
2026-05-24 13:40:53 +00:00
committed by GitHub
+59 -32
View File
@@ -6,7 +6,7 @@
replaceVars,
pandoc,
nodejs,
pnpm_9,
pnpm_10,
fetchPnpmDeps,
pnpmConfigHook,
electron,
@@ -15,24 +15,22 @@
copyDesktopItems,
nix-update-script,
xdg-utils,
darwin,
}:
let
inherit (stdenv.hostPlatform) isLinux isDarwin system;
pnpm = pnpm_10;
platformIds = {
"x86_64-linux" = "linux";
"aarch64-linux" = "linux-arm64";
"x86_64-darwin" = "darwin";
"aarch64-darwin" = "darwin-arm64";
};
platformId = platformIds.${stdenv.system} or (throw "Unsupported platform: ${stdenv.system}");
desktopEntry = makeDesktopItem {
name = "siyuan";
desktopName = "SiYuan";
comment = "Refactor your thinking";
icon = "siyuan";
exec = "siyuan %U";
categories = [ "Utility" ];
};
platformId = platformIds.${system} or (throw "Unsupported platform: ${system}");
in
stdenv.mkDerivation (finalAttrs: {
pname = "siyuan";
@@ -69,9 +67,7 @@ stdenv.mkDerivation (finalAttrs: {
# Set flags and tags as per upstream's Dockerfile
ldflags = [
"-s"
"-w"
"-X"
"github.com/siyuan-note/siyuan/kernel/util.Mode=prod"
"-X 'github.com/siyuan-note/siyuan/kernel/util.Mode=prod'"
];
tags = [ "fts5" ];
};
@@ -85,9 +81,14 @@ stdenv.mkDerivation (finalAttrs: {
nativeBuildInputs = [
nodejs
pnpmConfigHook
pnpm_9
pnpm
]
++ lib.optionals isLinux [
makeWrapper
copyDesktopItems
]
++ lib.optionals isDarwin [
darwin.autoSignDarwinBinariesHook
];
pnpmDeps = fetchPnpmDeps {
@@ -98,9 +99,9 @@ stdenv.mkDerivation (finalAttrs: {
sourceRoot
postPatch
;
pnpm = pnpm_9;
inherit pnpm;
fetcherVersion = 3;
hash = "sha256-GAbP9H+c+JXymH0/vpeYOJrkkFJGVyKcpJYFeyRLSKc=";
hash = "sha256-M2Fdie0XK2Pck/fP7Djxb7XNAQXpJO2i2kSJrDj1G0E=";
};
sourceRoot = "${finalAttrs.src.name}/app";
@@ -114,6 +115,9 @@ stdenv.mkDerivation (finalAttrs: {
# 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
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
'';
buildPhase = ''
@@ -121,19 +125,36 @@ stdenv.mkDerivation (finalAttrs: {
pnpm build
npm exec electron-builder -- \
--dir \
--config electron-builder-${platformId}.yml \
-c.electronDist=${electron.dist} \
-c.electronVersion=${electron.version}
electronBuilderArgs=(
--dir
--config electron-builder-${platformId}.yml
-c.electronDist=electron-dist
-c.electronVersion=${electron.version}
-c.mac.identity=null
)
npm exec electron-builder -- "''${electronBuilderArgs[@]}"
runHook postBuild
'';
installPhase = ''
runHook preInstall
''
+ lib.optionalString isDarwin ''
mkdir -p $out/Applications $out/bin
cp -R build/mac*/*.app $out/Applications/SiYuan.app
cat > $out/bin/siyuan << EOF
#!${stdenv.shell}
exec open -na "$out/Applications/SiYuan.app" --args "\$@"
EOF
chmod +x $out/bin/siyuan
''
+ lib.optionalString isLinux ''
mkdir -p $out/share/siyuan
cp -r build/*-unpacked/{locales,resources{,.pak}} $out/share/siyuan
makeWrapper ${lib.getExe electron} $out/bin/siyuan \
@@ -145,20 +166,26 @@ stdenv.mkDerivation (finalAttrs: {
--inherit-argv0
install -Dm644 src/assets/icon.svg $out/share/icons/hicolor/scalable/apps/siyuan.svg
''
+ ''
runHook postInstall
'';
desktopItems = [ desktopEntry ];
desktopItems = lib.optional isLinux (makeDesktopItem {
name = "siyuan";
desktopName = "SiYuan";
comment = "Refactor your thinking";
icon = "siyuan";
exec = "siyuan %U";
categories = [ "Utility" ];
});
passthru = {
inherit (finalAttrs.kernel) goModules; # this tricks nix-update into also updating the kernel goModules FOD
updateScript = nix-update-script {
extraArgs = [
"--version-regex"
"^v(\\d+\\.\\d+\\.\\d+)$"
];
};
passthru.updateScript = nix-update-script {
extraArgs = [
"--version-regex"
"^v(\\d+\\.\\d+\\.\\d+)$"
"--subpackage=kernel"
];
};
meta = {