From 437d3e574d63aa7bf5ffcebe92ca8effdb2c7ef4 Mon Sep 17 00:00:00 2001 From: yzx9 Date: Tue, 6 Aug 2024 10:40:12 +0800 Subject: [PATCH] logseq: add darwin support --- pkgs/by-name/lo/logseq/package.nix | 51 ++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/pkgs/by-name/lo/logseq/package.nix b/pkgs/by-name/lo/logseq/package.nix index 124c2d011716..2ede057a2fc7 100644 --- a/pkgs/by-name/lo/logseq/package.nix +++ b/pkgs/by-name/lo/logseq/package.nix @@ -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"; }; })