+4
.gitignore
+4
.gitignore
+118
flake.lock
+118
flake.lock
···
1
+
{
2
+
"nodes": {
3
+
"devshell": {
4
+
"inputs": {
5
+
"nixpkgs": [
6
+
"nixpkgs"
7
+
]
8
+
},
9
+
"locked": {
10
+
"lastModified": 1741473158,
11
+
"narHash": "sha256-kWNaq6wQUbUMlPgw8Y+9/9wP0F8SHkjy24/mN3UAppg=",
12
+
"owner": "numtide",
13
+
"repo": "devshell",
14
+
"rev": "7c9e793ebe66bcba8292989a68c0419b737a22a0",
15
+
"type": "github"
16
+
},
17
+
"original": {
18
+
"owner": "numtide",
19
+
"repo": "devshell",
20
+
"type": "github"
21
+
}
22
+
},
23
+
"flake-parts": {
24
+
"inputs": {
25
+
"nixpkgs-lib": "nixpkgs-lib"
26
+
},
27
+
"locked": {
28
+
"lastModified": 1759362264,
29
+
"narHash": "sha256-wfG0S7pltlYyZTM+qqlhJ7GMw2fTF4mLKCIVhLii/4M=",
30
+
"owner": "hercules-ci",
31
+
"repo": "flake-parts",
32
+
"rev": "758cf7296bee11f1706a574c77d072b8a7baa881",
33
+
"type": "github"
34
+
},
35
+
"original": {
36
+
"owner": "hercules-ci",
37
+
"repo": "flake-parts",
38
+
"type": "github"
39
+
}
40
+
},
41
+
"nixpkgs": {
42
+
"locked": {
43
+
"lastModified": 1759552314,
44
+
"narHash": "sha256-QTcSe1EDWq/wImPgF0bBJfYGHzHKy5T+nU6dXxozLWE=",
45
+
"owner": "NixOS",
46
+
"repo": "nixpkgs",
47
+
"rev": "9e85d025c16ae56e9f123631a4e332b4cb0c14b6",
48
+
"type": "github"
49
+
},
50
+
"original": {
51
+
"owner": "NixOS",
52
+
"repo": "nixpkgs",
53
+
"type": "github"
54
+
}
55
+
},
56
+
"nixpkgs-lib": {
57
+
"locked": {
58
+
"lastModified": 1754788789,
59
+
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
60
+
"owner": "nix-community",
61
+
"repo": "nixpkgs.lib",
62
+
"rev": "a73b9c743612e4244d865a2fdee11865283c04e6",
63
+
"type": "github"
64
+
},
65
+
"original": {
66
+
"owner": "nix-community",
67
+
"repo": "nixpkgs.lib",
68
+
"type": "github"
69
+
}
70
+
},
71
+
"root": {
72
+
"inputs": {
73
+
"devshell": "devshell",
74
+
"flake-parts": "flake-parts",
75
+
"nixpkgs": "nixpkgs",
76
+
"systems": "systems",
77
+
"treefmt-nix": "treefmt-nix"
78
+
}
79
+
},
80
+
"systems": {
81
+
"locked": {
82
+
"lastModified": 1681028828,
83
+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
84
+
"owner": "nix-systems",
85
+
"repo": "default",
86
+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
87
+
"type": "github"
88
+
},
89
+
"original": {
90
+
"owner": "nix-systems",
91
+
"repo": "default",
92
+
"type": "github"
93
+
}
94
+
},
95
+
"treefmt-nix": {
96
+
"inputs": {
97
+
"nixpkgs": [
98
+
"nixpkgs"
99
+
]
100
+
},
101
+
"locked": {
102
+
"lastModified": 1758728421,
103
+
"narHash": "sha256-ySNJ008muQAds2JemiyrWYbwbG+V7S5wg3ZVKGHSFu8=",
104
+
"owner": "numtide",
105
+
"repo": "treefmt-nix",
106
+
"rev": "5eda4ee8121f97b218f7cc73f5172098d458f1d1",
107
+
"type": "github"
108
+
},
109
+
"original": {
110
+
"owner": "numtide",
111
+
"repo": "treefmt-nix",
112
+
"type": "github"
113
+
}
114
+
}
115
+
},
116
+
"root": "root",
117
+
"version": 7
118
+
}
+48
flake.nix
+48
flake.nix
···
1
+
{
2
+
description = "Siyuan: A privacy-first, self-hosted, FOSS PKMS.";
3
+
4
+
inputs = {
5
+
systems.url = "github:nix-systems/default";
6
+
nixpkgs.url = "github:NixOS/nixpkgs";
7
+
flake-parts.url = "github:hercules-ci/flake-parts";
8
+
9
+
treefmt-nix = {
10
+
url = "github:numtide/treefmt-nix";
11
+
inputs.nixpkgs.follows = "nixpkgs";
12
+
};
13
+
devshell = {
14
+
url = "github:numtide/devshell";
15
+
inputs.nixpkgs.follows = "nixpkgs";
16
+
};
17
+
};
18
+
19
+
outputs = inputs @ {flake-parts, ...}:
20
+
flake-parts.lib.mkFlake {inherit inputs;} {
21
+
imports = [
22
+
inputs.treefmt-nix.flakeModule
23
+
#inputs.devshell.flakeModule
24
+
];
25
+
systems = import inputs.systems;
26
+
perSystem = {
27
+
config,
28
+
self',
29
+
inputs',
30
+
pkgs,
31
+
system,
32
+
...
33
+
}: let
34
+
siyuan-drv = pkgs.callPackage ./package.nix {};
35
+
in {
36
+
packages.default = siyuan-drv;
37
+
38
+
treefmt = {
39
+
programs.alejandra.enable = true;
40
+
};
41
+
42
+
apps.default = {
43
+
type = "app";
44
+
program = siyuan-drv + "/bin/siyuan";
45
+
};
46
+
};
47
+
};
48
+
}
+162
package.nix
+162
package.nix
···
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
+
makeWrapper,
13
+
makeDesktopItem,
14
+
copyDesktopItems,
15
+
nix-update-script,
16
+
}: let
17
+
pnpm = pnpm_10;
18
+
19
+
platformIds = {
20
+
"x86_64-linux" = "linux";
21
+
"aarch64-linux" = "linux-arm64";
22
+
};
23
+
24
+
platformId = platformIds.${stdenv.system} or (throw "Unsupported platform: ${stdenv.system}");
25
+
26
+
desktopEntry = makeDesktopItem {
27
+
name = "siyuan";
28
+
desktopName = "SiYuan";
29
+
comment = "Refactor your thinking";
30
+
icon = "siyuan";
31
+
exec = "siyuan %U";
32
+
categories = ["Utility"];
33
+
};
34
+
35
+
fs = lib.fileset;
36
+
sourceFiles = fs.difference (fs.gitTracked ./.) (
37
+
fs.unions [
38
+
(fs.maybeMissing ./result)
39
+
./flake.nix
40
+
./package.nix
41
+
./flake.lock
42
+
]
43
+
);
44
+
in
45
+
stdenv.mkDerivation (finalAttrs: {
46
+
pname = "siyuan";
47
+
version = (builtins.fromJSON (builtins.readFile ./app/package.json)).version;
48
+
49
+
src = fs.toSource {
50
+
root = ./.;
51
+
fileset = sourceFiles;
52
+
};
53
+
54
+
kernel = buildGoModule {
55
+
name = "${finalAttrs.pname}-${finalAttrs.version}-kernel";
56
+
inherit (finalAttrs) src;
57
+
sourceRoot = "${finalAttrs.src.name}/kernel";
58
+
vendorHash = "sha256-GRKBZe9cd2/sYstiCD/f/ckF0G1GYBPBc8FSFmjw3Mo=";
59
+
60
+
# this patch makes it so that file permissions are not kept when copying files using the gulu package
61
+
# this fixes a problem where it was copying files from the store and keeping their permissions
62
+
# hopefully this doesn't break other functionality
63
+
modPostBuild = ''
64
+
chmod +w vendor/github.com/88250/gulu
65
+
substituteInPlace vendor/github.com/88250/gulu/file.go \
66
+
--replace-fail "os.Chmod(dest, sourceinfo.Mode())" "os.Chmod(dest, 0644)"
67
+
'';
68
+
69
+
ldflags = [
70
+
# Set flags and tags as per upstream's Dockerfile
71
+
"-s"
72
+
"-w"
73
+
"-X"
74
+
"github.com/siyuan-note/siyuan/kernel/util.Mode=prod"
75
+
76
+
# Set variable for pandoc
77
+
"-X util.PandocBinPath=${lib.getExe pandoc}"
78
+
];
79
+
tags = ["fts5"];
80
+
};
81
+
82
+
nativeBuildInputs = [
83
+
nodejs
84
+
pnpm.configHook
85
+
makeWrapper
86
+
copyDesktopItems
87
+
];
88
+
89
+
pnpmDeps = pnpm.fetchDeps {
90
+
inherit
91
+
(finalAttrs)
92
+
pname
93
+
version
94
+
src
95
+
sourceRoot
96
+
;
97
+
fetcherVersion = 1;
98
+
hash = "sha256-vBeOImzsZ/6FtA0DkHsAO3UI/V/MaNDQ6dGNZrdO43U=";
99
+
};
100
+
101
+
sourceRoot = "${finalAttrs.src.name}/app";
102
+
103
+
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
104
+
105
+
postConfigure = ''
106
+
# link kernel into the correct starting place so that electron-builder can copy it to it's final location
107
+
mkdir kernel-${platformId}
108
+
ln -s ${finalAttrs.kernel}/bin/kernel kernel-${platformId}/SiYuan-Kernel
109
+
'';
110
+
111
+
buildPhase = ''
112
+
runHook preBuild
113
+
114
+
pnpm build
115
+
116
+
npm exec electron-builder -- \
117
+
--dir \
118
+
--config electron-builder-${platformId}.yml \
119
+
-c.electronDist=${electron.dist} \
120
+
-c.electronVersion=${electron.version}
121
+
122
+
runHook postBuild
123
+
'';
124
+
125
+
installPhase = ''
126
+
runHook preInstall
127
+
128
+
mkdir -p $out/share/siyuan
129
+
cp -r build/*-unpacked/{locales,resources{,.pak}} $out/share/siyuan
130
+
131
+
makeWrapper ${lib.getExe electron} $out/bin/siyuan \
132
+
--chdir $out/share/siyuan/resources \
133
+
--add-flags $out/share/siyuan/resources/app \
134
+
--set ELECTRON_FORCE_IS_PACKAGED 1 \
135
+
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
136
+
--inherit-argv0
137
+
138
+
install -Dm644 src/assets/icon.svg $out/share/icons/hicolor/scalable/apps/siyuan.svg
139
+
140
+
runHook postInstall
141
+
'';
142
+
143
+
desktopItems = [desktopEntry];
144
+
145
+
passthru = {
146
+
inherit (finalAttrs.kernel) goModules; # this tricks nix-update into also updating the kernel goModules FOD
147
+
updateScript = nix-update-script {
148
+
extraArgs = [
149
+
"--version-regex"
150
+
"^v(\\d+\\.\\d+\\.\\d+)$"
151
+
];
152
+
};
153
+
};
154
+
155
+
meta = {
156
+
description = "Privacy-first personal knowledge management system that supports complete offline usage, as well as end-to-end encrypted data sync";
157
+
homepage = "https://b3log.org/siyuan/";
158
+
license = lib.licenses.agpl3Plus;
159
+
mainProgram = "siyuan";
160
+
platforms = lib.attrNames platformIds;
161
+
};
162
+
})