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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
{
lib,
stdenvNoCC,
buildNpmPackage,
fetchFromGitHub,
python3,
nodejs,
node-gyp,
runCommand,
nixosTests,
immich-machine-learning,
# build-time deps
glib,
pkg-config,
makeWrapper,
curl,
cacert,
unzip,
# runtime deps
ffmpeg-headless,
imagemagick,
libraw,
libheif,
vips,
perl,
}:
let
buildNpmPackage' = buildNpmPackage.override { inherit nodejs; };
sources = lib.importJSON ./sources.json;
inherit (sources) version;
buildLock = {
sources =
builtins.map
(p: {
name = p.pname;
inherit (p) version;
inherit (p.src) rev;
})
[
imagemagick
libheif
libraw
];
packages = [ ];
};
# The geodata website is not versioned, so we use the internet archive
geodata =
runCommand "immich-geodata"
{
outputHash = "sha256-imqSfzXaEMNo9T9tZr80sr/89n19kiFc8qwidFzRUaY=";
outputHashMode = "recursive";
nativeBuildInputs = [
cacert
curl
unzip
];
meta.license = lib.licenses.cc-by-40;
}
''
mkdir $out
url="https://web.archive.org/web/20240724153050/http://download.geonames.org/export/dump"
curl -Lo ./cities500.zip "$url/cities500.zip"
curl -Lo $out/admin1CodesASCII.txt "$url/admin1CodesASCII.txt"
curl -Lo $out/admin2Codes.txt "$url/admin2Codes.txt"
curl -Lo $out/ne_10m_admin_0_countries.geojson \
https://raw.githubusercontent.com/nvkelso/natural-earth-vector/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_10m_admin_0_countries.geojson
unzip ./cities500.zip -d $out/
echo "2024-07-24T15:30:50Z" > $out/geodata-date.txt
'';
src = fetchFromGitHub {
owner = "immich-app";
repo = "immich";
rev = "v${version}";
inherit (sources) hash;
};
openapi = buildNpmPackage' {
pname = "immich-openapi-sdk";
inherit version;
src = "${src}/open-api/typescript-sdk";
inherit (sources.components."open-api/typescript-sdk") npmDepsHash;
installPhase = ''
runHook preInstall
npm config delete cache
npm prune --omit=dev --omit=optional
mkdir -p $out
mv package.json package-lock.json node_modules build $out/
runHook postInstall
'';
};
web = buildNpmPackage' {
pname = "immich-web";
inherit version;
src = "${src}/web";
inherit (sources.components.web) npmDepsHash;
preBuild = ''
rm node_modules/@immich/sdk
ln -s ${openapi} node_modules/@immich/sdk
# Rollup does not find the dependency otherwise
ln -s node_modules/@immich/sdk/node_modules/@oazapfts node_modules/
'';
installPhase = ''
runHook preInstall
cp -r build $out
runHook postInstall
'';
};
node-addon-api = stdenvNoCC.mkDerivation rec {
pname = "node-addon-api";
version = "8.0.0";
src = fetchFromGitHub {
owner = "nodejs";
repo = "node-addon-api";
rev = "v${version}";
hash = "sha256-k3v8lK7uaEJvcaj1sucTjFZ6+i5A6w/0Uj9rYlPhjCE=";
};
installPhase = ''
mkdir $out
cp -r *.c *.h *.gyp *.gypi index.js package-support.json package.json tools $out/
'';
};
vips' = vips.overrideAttrs (prev: {
mesonFlags = prev.mesonFlags ++ [ "-Dtiff=disabled" ];
});
in
buildNpmPackage' {
pname = "immich";
inherit version;
src = "${src}/server";
inherit (sources.components.server) npmDepsHash;
nativeBuildInputs = [
pkg-config
python3
makeWrapper
glib
node-gyp
];
buildInputs = [
ffmpeg-headless
imagemagick
libraw
libheif
vips' # Required for sharp
];
# Required because vips tries to write to the cache dir
makeCacheWritable = true;
preBuild = ''
cd node_modules/sharp
mkdir node_modules
ln -s ${node-addon-api} node_modules/node-addon-api
${lib.getExe nodejs} install/check
rm -r node_modules
cd ../..
rm -r node_modules/@img/sharp*
'';
installPhase = ''
runHook preInstall
npm config delete cache
npm prune --omit=dev
mkdir -p $out/build
mv package.json package-lock.json node_modules dist resources $out/
ln -s ${web} $out/build/www
ln -s ${geodata} $out/build/geodata
echo '${builtins.toJSON buildLock}' > $out/build/build-lock.json
makeWrapper ${lib.getExe nodejs} $out/bin/admin-cli --add-flags $out/dist/main --add-flags cli
makeWrapper ${lib.getExe nodejs} $out/bin/server --add-flags $out/dist/main --chdir $out \
--set IMMICH_BUILD_DATA $out/build --set NODE_ENV production \
--suffix PATH : "${
lib.makeBinPath [
perl
ffmpeg-headless
]
}"
runHook postInstall
'';
passthru = {
tests = {
inherit (nixosTests) immich;
};
machine-learning = immich-machine-learning;
inherit
src
sources
web
geodata
;
updateScript = ./update.sh;
};
meta = {
description = "Self-hosted photo and video backup solution";
homepage = "https://immich.app/";
license = lib.licenses.agpl3Only;
maintainers = with lib.maintainers; [ jvanbruegge ];
platforms = lib.platforms.linux;
mainProgram = "server";
};
}
|