Skip to content

Commit 323cbfd

Browse files
authored
affine: add affine building from source (NixOS#358160)
2 parents 4d5b774 + e3f98e1 commit 323cbfd

File tree

3 files changed

+385
-66
lines changed

3 files changed

+385
-66
lines changed

maintainers/maintainer-list.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24515,6 +24515,12 @@
2451524515
github = "peterablehmann";
2451624516
githubId = 36541313;
2451724517
};
24518+
xiaoxiangmoe = {
24519+
name = "ZHAO JinXiang";
24520+
email = "[email protected]";
24521+
github = "xiaoxiangmoe";
24522+
githubId = 8111351;
24523+
};
2451824524
xinyangli = {
2451924525
email = "[email protected]";
2452024526
matrix = "@me:xinyang.life";
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
copyDesktopItems,
3+
electron,
4+
fetchFromGitHub,
5+
fetchurl,
6+
lib,
7+
makeDesktopItem,
8+
makeWrapper,
9+
stdenvNoCC,
10+
unzip,
11+
buildType ? "stable",
12+
commandLineArgs ? "",
13+
}:
14+
let
15+
hostPlatform = stdenvNoCC.hostPlatform;
16+
nodePlatform = hostPlatform.parsed.kernel.name; # nodejs's `process.platform`
17+
nodeArch = # nodejs's `process.arch`
18+
{
19+
"x86_64" = "x64";
20+
"aarch64" = "arm64";
21+
}
22+
.${hostPlatform.parsed.cpu.name}
23+
or (throw "affine-bin(${buildType}): unsupported CPU family ${hostPlatform.parsed.cpu.name}");
24+
in
25+
stdenvNoCC.mkDerivation (
26+
finalAttrs:
27+
(
28+
{
29+
# https://github.com/toeverything/AFFiNE/releases/tag/v0.18.1
30+
version = "0.18.1";
31+
githubSourceCode = fetchFromGitHub {
32+
owner = "toeverything";
33+
repo = "AFFiNE";
34+
rev = "8b066a4b398aace25a20508a8e3c1a381721971f";
35+
hash = "sha256-TWwojG3lqQlQFX3BKoFjJ27a3T/SawXgNDO6fP6gW4k=";
36+
};
37+
productName = if buildType == "stable" then "AFFiNE" else "AFFiNE-" + buildType;
38+
binName = lib.toLower finalAttrs.productName;
39+
pname = "${finalAttrs.binName}-bin";
40+
meta =
41+
{
42+
description = "Workspace with fully merged docs, whiteboards and databases";
43+
longDescription = ''
44+
AFFiNE is an open-source, all-in-one workspace and an operating
45+
system for all the building blocks that assemble your knowledge
46+
base and much more -- wiki, knowledge management, presentation
47+
and digital assets
48+
'';
49+
homepage = "https://affine.pro/";
50+
license = lib.licenses.mit;
51+
maintainers = with lib.maintainers; [
52+
richar
53+
redyf
54+
xiaoxiangmoe
55+
];
56+
platforms = [
57+
"aarch64-darwin"
58+
"x86_64-darwin"
59+
"x86_64-linux"
60+
];
61+
sourceProvenance = [ lib.sourceTypes.binaryBytecode ];
62+
}
63+
// lib.optionalAttrs hostPlatform.isLinux {
64+
mainProgram = finalAttrs.binName;
65+
};
66+
67+
src = (
68+
let
69+
inherit (finalAttrs) version;
70+
affinePrebuiltBinariesHashes = {
71+
darwin-arm64 = "I8lOO97MNLkha0utWPAP4EKv9HiPMWpLi2ibvXjzjhdl7abgSPmMKbv1dGHxMzgMzGbDzhzKqzhYtJI+0Asfzw==";
72+
darwin-x64 = "LZdd7yHJx9Hx0Po8NQgeDp0BhIyXGr0QsbF6bWP5pS08c4fdtE9UzNPfJGfzz/snTkWfKMQZop0Ea4fYGosr1Q==";
73+
linux-x64 = "+impaFLuvcfpj4QjHwjZ06+fUpsxxRlk4eWO6+E4xkBMrV43gwZGeSeAw2pMgXogRGb/Oy6XUoA7o8tTQt9J6A==";
74+
};
75+
platform = if hostPlatform.isLinux then "linux" else "macos";
76+
in
77+
fetchurl {
78+
# example: https://github.com/toeverything/AFFiNE/releases/download/v0.18.1/affine-0.18.1-stable-darwin-arm64.zip
79+
url = "https://github.com/toeverything/AFFiNE/releases/download/v${version}/affine-${version}-${buildType}-${platform}-${nodeArch}.zip";
80+
sha512 = affinePrebuiltBinariesHashes."${nodePlatform}-${nodeArch}";
81+
}
82+
);
83+
84+
nativeBuildInputs =
85+
[
86+
unzip
87+
]
88+
++ lib.optionals hostPlatform.isLinux [
89+
copyDesktopItems
90+
makeWrapper
91+
];
92+
93+
installPhase =
94+
let
95+
inherit (finalAttrs) binName productName;
96+
in
97+
if hostPlatform.isDarwin then
98+
''
99+
runHook preInstall
100+
101+
mkdir -p $out/Applications
102+
cd ..
103+
mv ${productName}.app $out/Applications
104+
105+
runHook postInstall
106+
''
107+
else
108+
''
109+
runHook preInstall
110+
111+
mkdir --parents $out/lib/${binName}/
112+
mv ./{resources,LICENSE*} $out/lib/${binName}/
113+
install -Dm644 "${finalAttrs.githubSourceCode}/packages/frontend/apps/electron/resources/icons/icon_${buildType}_64x64.png" $out/share/icons/hicolor/64x64/apps/${binName}.png
114+
115+
makeWrapper "${electron}/bin/electron" $out/bin/${binName} \
116+
--inherit-argv0 \
117+
--add-flags $out/lib/${binName}/resources/app.asar \
118+
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
119+
--add-flags ${lib.escapeShellArg commandLineArgs}
120+
121+
runHook postInstall
122+
'';
123+
}
124+
// lib.optionalAttrs hostPlatform.isLinux {
125+
desktopItems =
126+
let
127+
inherit (finalAttrs) binName productName;
128+
in
129+
[
130+
(makeDesktopItem {
131+
name = binName;
132+
desktopName = productName;
133+
comment = "AFFiNE Desktop App";
134+
exec = "${binName} %U";
135+
terminal = false;
136+
icon = binName;
137+
startupWMClass = binName;
138+
categories = [ "Utility" ];
139+
mimeTypes = [ "x-scheme-handler/${binName}" ];
140+
})
141+
];
142+
}
143+
)
144+
)

0 commit comments

Comments
 (0)