-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathpackage.nix
More file actions
263 lines (232 loc) · 7.59 KB
/
Copy pathpackage.nix
File metadata and controls
263 lines (232 loc) · 7.59 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
{
name,
variant,
icon ? null,
policies ? {},
enablePrivateDesktopEntry ? false,
lib,
stdenv,
config,
wrapGAppsHook3,
autoPatchelfHook,
ffmpeg_7,
alsa-lib,
curl,
dbus-glib,
gtk3,
libXtst,
libva,
libGL,
pciutils,
pipewire,
adwaita-icon-theme,
undmg,
writeText,
fetchurl,
fetchzip,
makeDesktopItem,
copyDesktopItems,
patchelfUnstable, # have to use patchelfUnstable to support --no-clobber-old-sections
applicationName ?
"Zen Browser"
+ (
if name == "beta"
then " (Beta)"
else if name == "twilight"
then " (Twilight)"
else if name == "twilight-official"
then " (Twilight)"
else ""
),
}: let
binaryName = "zen-${name}";
libName = "zen-bin-${variant.version}";
mozillaPlatforms = {
x86_64-linux = "linux-x86_64";
aarch64-linux = "linux-aarch64";
aarch64-darwin = "darwin-aarch64";
};
firefoxPolicies =
(config.firefox.policies or {})
// policies;
policiesJson = writeText "firefox-policies.json" (builtins.toJSON {policies = firefoxPolicies;});
pname = "zen-${name}-bin-unwrapped";
desktopIconName =
if name == "beta"
then "zen-browser"
else binaryName;
installDarwin = ''
runHook preInstall
mkdir -p "$out/Applications" "$out/bin"
cp -r *.app "$out/Applications/${applicationName}.app"
ln -s zen "$out/Applications/${applicationName}.app/Contents/MacOS/${binaryName}"
# Install policies.json for macOS
mkdir -p "$out/Applications/${applicationName}.app/Contents/Resources/distribution"
ln -s ${policiesJson} "$out/Applications/${applicationName}.app/Contents/Resources/distribution/policies.json"
# Re-sign with correct identifier to maintain AdGuard compatibility
# AdGuard uses code signing identifier (not CFBundleIdentifier) to recognize apps
/usr/bin/codesign --force --deep --sign - \
--identifier "app.zen-browser.zen" \
"$out/Applications/${applicationName}.app"
# Use symlink path to avoid installs.ini accumulation on Nix rebuilds
# The symlink is created by home-manager and remains stable across rebuilds
cat > "$out/bin/${binaryName}" << EOF
#!/bin/bash
# Use stable path from home-manager to avoid creating new install IDs
STABLE_PATH="\$HOME/Applications/Home Manager Apps/${applicationName}.app"
if [[ -e "\$STABLE_PATH" ]]; then
exec /usr/bin/open -na "\$STABLE_PATH" --args "\$@"
else
# Fallback to nix store path if symlink doesn't exist yet
exec /usr/bin/open -na "$out/Applications/${applicationName}.app" --args "\$@"
fi
EOF
chmod +x "$out/bin/${binaryName}"
runHook postInstall
'';
installLinux = ''
runHook preInstall
# Linux tarball installation
mkdir -p "$prefix/lib/${libName}"
cp -r "$src"/* "$prefix/lib/${libName}"
mkdir -p "$out/bin"
ln -s "$prefix/lib/${libName}/zen" "$out/bin/${binaryName}"
mkdir -p "$out/lib/${libName}/distribution"
ln -s ${policiesJson} "$out/lib/${libName}/distribution/policies.json"
install -D $src/browser/chrome/icons/default/default16.png $out/share/icons/hicolor/16x16/apps/${desktopIconName}.png
install -D $src/browser/chrome/icons/default/default32.png $out/share/icons/hicolor/32x32/apps/${desktopIconName}.png
install -D $src/browser/chrome/icons/default/default48.png $out/share/icons/hicolor/48x48/apps/${desktopIconName}.png
install -D $src/browser/chrome/icons/default/default64.png $out/share/icons/hicolor/64x64/apps/${desktopIconName}.png
install -D $src/browser/chrome/icons/default/default128.png $out/share/icons/hicolor/128x128/apps/${desktopIconName}.png
runHook postInstall
'';
in
stdenv.mkDerivation {
inherit pname;
inherit (variant) version;
src =
if stdenv.hostPlatform.isDarwin
then
fetchurl {
inherit (variant) url;
hash = variant.sha256;
}
else
fetchzip {
inherit (variant) url;
hash = variant.sha256;
};
sourceRoot = lib.optionalString stdenv.hostPlatform.isDarwin ".";
desktopItems = let
mkDesktopEntry = args:
makeDesktopItem (args
// {
icon =
if icon != null && (lib.isString icon || lib.isPath icon)
then icon
else desktopIconName;
type = "Application";
mimeTypes = [
"text/html"
"text/xml"
"application/xhtml+xml"
"x-scheme-handler/http"
"x-scheme-handler/https"
"application/x-xpinstall"
"application/pdf"
"application/json"
];
startupWMClass = binaryName;
categories = ["Network" "WebBrowser"];
startupNotify = true;
terminal = false;
extraConfig.X-MultipleArgs = "false";
keywords = ["Internet" "WWW" "Browser" "Web" "Explorer"];
});
in
[
(mkDesktopEntry {
name = binaryName;
desktopName = "Zen Browser${lib.optionalString (name == "twilight") " Twilight"}";
exec = "${binaryName} %u";
actions = {
new-windows = {
name = "Open a New Window";
exec = "${binaryName} %u";
};
new-private-window = {
name = "Open a New Private Window";
exec = "${binaryName} --private-window %u";
};
profilemanager = {
name = "Open the Profile Manager";
exec = "${binaryName} --ProfileManager %u";
};
};
})
]
++ lib.optionals (enablePrivateDesktopEntry == true) [
(mkDesktopEntry {
name = "${binaryName}-private";
desktopName = "${applicationName} - Private Session";
exec = "${binaryName} --private-window %u";
})
];
nativeBuildInputs =
lib.optionals stdenv.hostPlatform.isLinux [
wrapGAppsHook3
autoPatchelfHook
patchelfUnstable
copyDesktopItems
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
undmg
];
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
gtk3
adwaita-icon-theme
alsa-lib
dbus-glib
libXtst
ffmpeg_7
];
runtimeDependencies = lib.optionals stdenv.hostPlatform.isLinux [
curl
libva.out
pciutils
libGL
];
appendRunpaths = lib.optionals stdenv.hostPlatform.isLinux [
"${libGL}/lib"
"${pipewire}/lib"
];
# Firefox uses "relrhack" to manually process relocations from a fixed offset
patchelfFlags = ["--no-clobber-old-sections"];
preFixup = ''
gappsWrapperArgs+=(
--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ffmpeg_7]}"
--add-flags "--name=''${MOZ_APP_LAUNCHER:-${binaryName}}"
--add-flags "--class=''${MOZ_APP_LAUNCHER:-${binaryName}}"
)
'';
installPhase =
if stdenv.hostPlatform.isDarwin
then installDarwin
else installLinux;
passthru = {
inherit applicationName binaryName libName;
ffmpegSupport = true;
gssSupport = true;
gtk3 = gtk3;
};
meta = {
description = "Experience tranquillity while browsing the web without people tracking you!";
homepage = "https://zen-browser.app";
downloadPage = "https://zen-browser.app/download/";
changelog = "https://github.com/zen-browser/desktop/releases";
sourceProvenance = with lib.sourceTypes; [binaryNativeCode];
platforms = builtins.attrNames mozillaPlatforms;
hydraPlatforms = [];
mainProgram = binaryName;
};
}