1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
{
lib,
stdenv,
fetchFromGitHub,
buildGo123Module,
substituteAll,
pandoc,
nodejs,
pnpm_9,
electron,
makeWrapper,
makeDesktopItem,
copyDesktopItems,
nix-update-script,
}:
let
pnpm = pnpm_9;
platformIds = {
"x86_64-linux" = "linux";
"aarch64-linux" = "linux-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" ];
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "siyuan";
version = "3.1.6";
src = fetchFromGitHub {
owner = "siyuan-note";
repo = "siyuan";
rev = "v${finalAttrs.version}";
hash = "sha256-xGxZ6xu8R/JoW4X+drEv943y1jah4ZijHB+RNN6hxig=";
};
kernel = buildGo123Module {
name = "${finalAttrs.pname}-${finalAttrs.version}-kernel";
inherit (finalAttrs) src;
sourceRoot = "${finalAttrs.src.name}/kernel";
vendorHash = "sha256-I57T4/J0pL8/GISi22H1lpE1gkduNXdINvuo+F3YnAs=";
patches = [
(substituteAll {
src = ./set-pandoc-path.patch;
pandoc_path = lib.getExe pandoc;
})
];
# this patch makes it so that file permissions are not kept when copying files using the gulu package
# this fixes a problem where it was copying files from the store and keeping their permissions
# hopefully this doesn't break other functionality
modPostBuild = ''
chmod +w vendor/github.com/88250/gulu
substituteInPlace vendor/github.com/88250/gulu/file.go \
--replace-fail "os.Chmod(dest, sourceinfo.Mode())" "os.Chmod(dest, 0644)"
'';
# Set flags and tags as per upstream's Dockerfile
ldflags = [
"-s"
"-w"
"-X"
"github.com/siyuan-note/siyuan/kernel/util.Mode=prod"
];
tags = [ "fts5" ];
};
nativeBuildInputs = [
nodejs
pnpm.configHook
makeWrapper
copyDesktopItems
];
pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs)
pname
version
src
sourceRoot
;
hash = "sha256-3PdmCbaZZjnTCSpBcvG7nP+zTGamoY/ZXjay7c8Zx5w=";
};
sourceRoot = "${finalAttrs.src.name}/app";
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
postConfigure = ''
# remove prebuilt pandoc archives
rm -r pandoc
# 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
'';
buildPhase = ''
runHook preBuild
pnpm build
npm exec electron-builder -- \
--dir \
--config electron-builder-${platformId}.yml \
-c.electronDist=${electron.dist} \
-c.electronVersion=${electron.version}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/share/siyuan
cp -r build/*-unpacked/{locales,resources{,.pak}} $out/share/siyuan
makeWrapper ${lib.getExe electron} $out/bin/siyuan \
--chdir $out/share/siyuan/resources \
--add-flags $out/share/siyuan/resources/app \
--set ELECTRON_FORCE_IS_PACKAGED 1 \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime}}" \
--inherit-argv0
install -Dm644 src/assets/icon.svg $out/share/icons/hicolor/scalable/apps/siyuan.svg
runHook postInstall
'';
desktopItems = [ desktopEntry ];
passthru = {
inherit (finalAttrs.kernel) goModules; # this tricks nix-update into also updating the kernel goModules FOD
updateScript = nix-update-script { };
};
meta = {
description = "Privacy-first personal knowledge management system that supports complete offline usage, as well as end-to-end encrypted data sync";
homepage = "https://b3log.org/siyuan/";
license = lib.licenses.agpl3Plus;
mainProgram = "siyuan";
maintainers = with lib.maintainers; [ tomasajt ];
platforms = lib.attrNames platformIds;
};
})
|