1{ lib
2, stdenv
3, fetchurl
4, appimageTools
5, makeWrapper
6# graphs will not sync without matching upstream's major electron version
7, electron_25
8, git
9, nix-update-script
10}:
11
12stdenv.mkDerivation (finalAttrs: let
13 inherit (finalAttrs) pname version src appimageContents;
14
15in {
16 pname = "logseq";
17 version = "0.9.20";
18
19 src = fetchurl {
20 url = "https://github.com/logseq/logseq/releases/download/${version}/logseq-linux-x64-${version}.AppImage";
21 hash = "sha256-iT0Gc/ePx1tUNTPoE2Ol+dHUmbS4CkneZbyraRBx5Ak=";
22 name = "${pname}-${version}.AppImage";
23 };
24
25 appimageContents = appimageTools.extract {
26 inherit pname src version;
27 };
28
29 dontUnpack = true;
30 dontConfigure = true;
31 dontBuild = true;
32
33 nativeBuildInputs = [ makeWrapper ];
34
35 installPhase = ''
36 runHook preInstall
37
38 mkdir -p $out/bin $out/share/${pname} $out/share/applications
39 cp -a ${appimageContents}/{locales,resources} $out/share/${pname}
40 cp -a ${appimageContents}/Logseq.desktop $out/share/applications/${pname}.desktop
41
42 # remove the `git` in `dugite` because we want the `git` in `nixpkgs`
43 chmod +w -R $out/share/${pname}/resources/app/node_modules/dugite/git
44 chmod +w $out/share/${pname}/resources/app/node_modules/dugite
45 rm -rf $out/share/${pname}/resources/app/node_modules/dugite/git
46 chmod -w $out/share/${pname}/resources/app/node_modules/dugite
47
48 mkdir -p $out/share/pixmaps
49 ln -s $out/share/${pname}/resources/app/icons/logseq.png $out/share/pixmaps/${pname}.png
50
51 substituteInPlace $out/share/applications/${pname}.desktop \
52 --replace Exec=Logseq Exec=${pname} \
53 --replace Icon=Logseq Icon=${pname}
54
55 runHook postInstall
56 '';
57
58 postFixup = ''
59 # set the env "LOCAL_GIT_DIRECTORY" for dugite so that we can use the git in nixpkgs
60 makeWrapper ${electron_25}/bin/electron $out/bin/${pname} \
61 --set "LOCAL_GIT_DIRECTORY" ${git} \
62 --add-flags $out/share/${pname}/resources/app \
63 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
64 --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ stdenv.cc.cc.lib ]}"
65 '';
66
67 passthru.updateScript = nix-update-script { };
68
69 meta = with lib; {
70 description = "A local-first, non-linear, outliner notebook for organizing and sharing your personal knowledge base";
71 homepage = "https://github.com/logseq/logseq";
72 changelog = "https://github.com/logseq/logseq/releases/tag/${version}";
73 license = licenses.agpl3Plus;
74 maintainers = with maintainers; [ ];
75 platforms = [ "x86_64-linux" ];
76 };
77})