A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
1# Based on nixpkgs:pkgs/by-name/si/siyuan/package.nix
2{
3 lib,
4 stdenv,
5 fetchFromGitHub,
6 buildGoModule,
7 replaceVars,
8 pandoc,
9 nodejs,
10 pnpm_10,
11 electron,
12 makeBinaryWrapper,
13 makeDesktopItem,
14 copyDesktopItems,
15 nix-update-script,
16 xdg-utils,
17}: let
18 pnpm = pnpm_10;
19
20 platformIds = {
21 "x86_64-linux" = "linux";
22 "aarch64-linux" = "linux-arm64";
23 };
24
25 platformId = platformIds.${stdenv.system} or (throw "Unsupported platform: ${stdenv.system}");
26
27 desktopEntry = makeDesktopItem {
28 name = "siyuan";
29 desktopName = "SiYuan";
30 comment = "Refactor your thinking";
31 icon = "siyuan";
32 exec = "siyuan %U";
33 categories = ["Utility"];
34 };
35
36 fs = lib.fileset;
37 sourceFiles = fs.difference (fs.gitTracked ./.) (
38 fs.unions [
39 (fs.maybeMissing ./result)
40 ./flake.nix
41 ./package.nix
42 ./flake.lock
43 ]
44 );
45in
46 stdenv.mkDerivation (finalAttrs: {
47 pname = "siyuan";
48 version = (builtins.fromJSON (builtins.readFile ./app/package.json)).version;
49
50 src = fs.toSource {
51 root = ./.;
52 fileset = sourceFiles;
53 };
54
55 kernel = buildGoModule {
56 name = "${finalAttrs.pname}-${finalAttrs.version}-kernel";
57 inherit (finalAttrs) src;
58 sourceRoot = "${finalAttrs.src.name}/kernel";
59 vendorHash = "sha256-ZUSfehCqHUZyWHHisulg4x9v+YtnoktqaLDR7SjeGQo=";
60
61 # this patch makes it so that file permissions are not kept when copying files using the gulu package
62 # this fixes a problem where it was copying files from the store and keeping their permissions
63 # hopefully this doesn't break other functionality
64 modPostBuild = ''
65 chmod +w vendor/github.com/88250/gulu
66 substituteInPlace vendor/github.com/88250/gulu/file.go \
67 --replace-fail "os.Chmod(dest, sourceinfo.Mode())" "os.Chmod(dest, 0644)"
68 '';
69
70 ldflags = [
71 # Set flags and tags as per upstream's Dockerfile
72 "-s"
73 "-w"
74 "-X"
75 "github.com/siyuan-note/siyuan/kernel/util.Mode=prod"
76
77 # Set variable for pandoc
78 "-X util.PandocBinPath=${lib.getExe pandoc}"
79 ];
80 tags = ["fts5"];
81 };
82
83 nativeBuildInputs = [
84 nodejs
85 pnpm.configHook
86 makeBinaryWrapper
87 copyDesktopItems
88 ];
89
90 pnpmDeps = pnpm.fetchDeps {
91 inherit
92 (finalAttrs)
93 pname
94 version
95 src
96 sourceRoot
97 ;
98 fetcherVersion = 1;
99 hash = "sha256-jKao033BT3voiVyYabHGxnJRoSietOwdvwc44B8sYns=";
100 };
101
102 sourceRoot = "${finalAttrs.src.name}/app";
103
104 env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
105
106 postConfigure = ''
107 # link kernel into the correct starting place so that electron-builder can copy it to it's final location
108 mkdir kernel-${platformId}
109 ln -s ${finalAttrs.kernel}/bin/kernel kernel-${platformId}/SiYuan-Kernel
110 '';
111
112 buildPhase = ''
113 runHook preBuild
114
115 pnpm build
116
117 npm exec electron-builder -- \
118 --dir \
119 --config electron-builder-${platformId}.yml \
120 -c.electronDist=${electron.dist} \
121 -c.electronVersion=${electron.version}
122
123 runHook postBuild
124 '';
125
126 installPhase = ''
127 runHook preInstall
128
129 mkdir -p $out/share/siyuan
130 cp -r build/*-unpacked/{locales,resources{,.pak}} $out/share/siyuan
131
132 makeBinaryWrapper ${lib.getExe electron} $out/bin/siyuan \
133 --chdir $out/share/siyuan/resources \
134 --add-flags $out/share/siyuan/resources/app \
135 --set ELECTRON_FORCE_IS_PACKAGED 1 \
136 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
137 --suffix PATH : ${lib.makeBinPath [xdg-utils]} \
138 --inherit-argv0
139
140 install -Dm644 src/assets/icon.svg $out/share/icons/hicolor/scalable/apps/siyuan.svg
141
142 runHook postInstall
143 '';
144
145 desktopItems = [desktopEntry];
146
147 passthru = {
148 inherit (finalAttrs.kernel) goModules; # this tricks nix-update into also updating the kernel goModules FOD
149 updateScript = nix-update-script {
150 extraArgs = [
151 "--version-regex"
152 "^v(\\d+\\.\\d+\\.\\d+)$"
153 ];
154 };
155 };
156
157 meta = {
158 description = "Privacy-first personal knowledge management system that supports complete offline usage, as well as end-to-end encrypted data sync";
159 homepage = "https://b3log.org/siyuan/";
160 license = lib.licenses.agpl3Plus;
161 mainProgram = "siyuan";
162 platforms = lib.attrNames platformIds;
163 };
164 })