Merge pull request #331824 from yzx9/logseq-drawin-support

logseq: add darwin support
This commit is contained in:
kirillrdy 2024-08-13 18:30:53 +10:00 committed by GitHub
commit 5b14f25672
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@
, stdenv
, fetchurl
, appimageTools
, unzip
, makeWrapper
# Notice: graphs will not sync without matching upstream's major electron version
# the specific electron version is set at top-level file to preserve override interface.
@ -13,32 +14,44 @@
}:
stdenv.mkDerivation (finalAttrs: let
inherit (finalAttrs) pname version src appimageContents;
inherit (finalAttrs) pname version src;
inherit (stdenv.hostPlatform) system;
selectSystem = attrs: attrs.${system} or (throw "Unsupported system: ${system}");
suffix = selectSystem {
x86_64-linux = "linux-x64-${version}.AppImage";
x86_64-darwin = "darwin-x64-${version}.zip";
aarch64-darwin = "darwin-arm64-${version}.zip";
};
hash = selectSystem {
x86_64-linux = "sha256-XROuY2RlKnGvK1VNvzauHuLJiveXVKrIYPppoz8fCmc=";
x86_64-darwin = "sha256-0i9ozqBSeV/y8v+YEmQkbY0V6JHOv6tKub4O5Fdx2fQ=";
aarch64-darwin = "sha256-Uvv96XWxpFj14wPH0DwPT+mlf3Z2dy1g/z8iBt5Te7Q=";
};
in {
pname = "logseq";
version = "0.10.9";
src = fetchurl {
url = "https://github.com/logseq/logseq/releases/download/${version}/logseq-linux-x64-${version}.AppImage";
hash = "sha256-XROuY2RlKnGvK1VNvzauHuLJiveXVKrIYPppoz8fCmc=";
name = "${pname}-${version}.AppImage";
inherit hash;
url = "https://github.com/logseq/logseq/releases/download/${version}/logseq-${suffix}";
name = lib.optionalString stdenv.isLinux "${pname}-${version}.AppImage";
};
appimageContents = appimageTools.extract {
inherit pname src version;
};
nativeBuildInputs = [ makeWrapper ]
++ lib.optionals stdenv.isLinux [ autoPatchelfHook ]
++ lib.optionals stdenv.isDarwin [ unzip ];
buildInputs = [ stdenv.cc.cc.lib ];
dontUnpack = true;
dontUnpack = stdenv.isLinux;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ makeWrapper autoPatchelfHook ];
buildInputs = [ stdenv.cc.cc.lib ];
installPhase = ''
runHook preInstall
'' + lib.optionalString stdenv.isLinux (
let
appimageContents = appimageTools.extract { inherit pname src version; };
in
''
mkdir -p $out/bin $out/share/${pname} $out/share/applications
cp -a ${appimageContents}/{locales,resources} $out/share/${pname}
cp -a ${appimageContents}/Logseq.desktop $out/share/applications/${pname}.desktop
@ -55,11 +68,15 @@ in {
substituteInPlace $out/share/applications/${pname}.desktop \
--replace Exec=Logseq Exec=${pname} \
--replace Icon=Logseq Icon=${pname}
'') + lib.optionalString stdenv.isDarwin ''
mkdir -p $out/{Applications/Logseq.app,bin}
cp -R . $out/Applications/Logseq.app
makeWrapper $out/Applications/Logseq.app/Contents/MacOS/Logseq $out/bin/${pname}
'' + ''
runHook postInstall
'';
postFixup = ''
postFixup = lib.optionalString stdenv.isLinux ''
# set the env "LOCAL_GIT_DIRECTORY" for dugite so that we can use the git in nixpkgs
makeWrapper ${electron}/bin/electron $out/bin/${pname} \
--set "LOCAL_GIT_DIRECTORY" ${git} \
@ -76,7 +93,7 @@ in {
license = lib.licenses.agpl3Plus;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
maintainers = [ ];
platforms = [ "x86_64-linux" ];
platforms = [ "x86_64-linux" ] ++ lib.platforms.darwin;
mainProgram = "logseq";
};
})