git.iko.soy/typeable/nixpkgs
on master help sign in
tor-browser-bundle: approximate upstream bundle & purity control
commitf05d50f36c879400a679498eb9677f8653a892e3 authorJoachim Fasting <joachifm@fastmail.fm> dateTue 26 Sep 2017, 20:34 (9 years ago) parent93b9109
1 file changed+92−5
pkgs/applications/networking/browsers/tor-browser-bundle/default.nix+92−5
pkgs/applications/networking/browsers/tor-browser-bundle/default.nix+92−5
@@ -7,6 +7,10 @@
77, tor
88, tor-browser-unwrapped
99
10+# Wrapper runtime
11+, coreutils
12+, hicolor_icon_theme
13+, shared_mime_info
1014# Extensions, common
1115, unzip
1216, zip
@@ -217,8 +221,6 @@ stdenv.mkDerivation rec {
217221 clearPref("extensions.bootstrappedAddons");
218222
219223 // Insist on using IPC for communicating with Tor
220− //
221− // Defaults to $XDG_RUNTIME_DIR/Tor/{socks,control}.socket
222224 lockPref("extensions.torlauncher.control_port_use_ipc", true);
223225 lockPref("extensions.torlauncher.socks_port_use_ipc", true);
224226
@@ -243,18 +245,103 @@ stdenv.mkDerivation rec {
243245 >> defaults/pref/extension-overrides.js
244246
245247 # Generate a suitable wrapper
248+ wrapper_PATH=${lib.makeBinPath [ coreutils ]}
249+ wrapper_XDG_DATA_DIRS=${lib.concatMapStringsSep ":" (x: "${x}/share") [
250+ hicolor_icon_theme
251+ shared_mime_info
252+ ]}
253+
246254 mkdir -p $out/bin
247255 cat >$out/bin/tor-browser <<EOF
248− #! ${stdenv.shell} -e
256+ #! ${stdenv.shell} -eu
257+
258+ PATH=$wrapper_PATH
249259
250− THE_HOME=\$HOME
260+ readonly THE_HOME=\$HOME
251261 TBB_HOME=\''${TBB_HOME:-\''${XDG_DATA_HOME:-$HOME/.local/share}/tor-browser}
262+ if [[ \''${TBB_HOME:0:1} != / ]] ; then
263+ TBB_HOME=\$PWD/\$TBB_HOME
264+ fi
265+ readonly TBB_HOME
266+
267+ # Basic sanity check: never want to vomit directly onto user's homedir
268+ if [[ "\$TBB_HOME" = "\$THE_HOME" ]] ; then
269+ echo 'TBB_HOME=\$HOME; refusing to run' >&2
270+ exit 1
271+ fi
272+
252273 mkdir -p "\$TBB_HOME"
253274
254275 HOME=\$TBB_HOME
255276 cd "\$HOME"
256277
257− exec $self/firefox -no-remote about:tor
278+ # Re-init XDG basedir envvars
279+ XDG_CACHE_HOME=\$HOME/.cache
280+ XDG_CONFIG_HOME=\$HOME/.config
281+ XDG_DATA_HOME=\$HOME/.local/share
282+
283+ # Initialize empty TBB runtime state directory hierarchy. Mirror the
284+ # layout used by the official TBB, to avoid the hassle of working
285+ # against the assumptions made by tor-launcher & co.
286+ mkdir -p "\$HOME/TorBrowser" "\$HOME/TorBrowser/Data"
287+
288+ # Initialize the Tor data directory.
289+ mkdir -p "\$HOME/TorBrowser/Data/Tor"
290+
291+ # TBB fails if ownership is too permissive
292+ chmod 0700 "\$HOME/TorBrowser/Data/Tor"
293+
294+ # Initialize the browser profile state. Expect TBB to generate all data.
295+ mkdir -p "\$HOME/TorBrowser/Data/Browser/profile.default"
296+
297+ # Files that capture store paths; re-generated by firefox at startup
298+ rm -rf "\$HOME/TorBrowser/Data/Browser/profile.default"/{compatibility.ini,extensions.ini,extensions.json,startupCache}
299+
300+ # Clear out fontconfig caches
301+ rm -f "\$HOME/.cache/fontconfig/"*.cache-*
302+
303+ # Lift-off!
304+ #
305+ # TZ is set to avoid stat()ing /etc/localtime over and over ...
306+ #
307+ # DBUS_SESSION_BUS_ADDRESS is inherited to avoid auto-launching a new
308+ # dbus instance; to prevent using the session bus, set the envvar to
309+ # an empty/invalid value prior to running tor-browser.
310+ #
311+ # FONTCONFIG_FILE is required to make fontconfig read the TBB
312+ # fonts.conf; upstream uses FONTCONFIG_PATH, but FC_DEBUG=1024
313+ # indicates the system fonts.conf being used instead.
314+ #
315+ # HOME, TMPDIR, XDG_*_HOME are set as a form of soft confinement;
316+ # ideally, tor-browser should not write to any path outside TBB_HOME
317+ # and should run even under strict confinement to TBB_HOME.
318+ #
319+ # XDG_DATA_DIRS is set to prevent searching system directories for
320+ # mime and icon data.
321+ #
322+ # Parameters lacking a default value below are *required* (enforced by
323+ # -o nounset).
324+ exec env -i \
325+ TZ=":" \
326+ \
327+ DISPLAY="\$DISPLAY" \
328+ XAUTHORITY="\$XAUTHORITY" \
329+ DBUS_SESSION_BUS_ADDRESS="\$DBUS_SESSION_BUS_ADDRESS" \
330+ \
331+ HOME="\$HOME" \
332+ TMPDIR="\$XDG_CACHE_HOME/tmp" \
333+ XDG_CONFIG_HOME="\$XDG_CONFIG_HOME" \
334+ XDG_DATA_HOME="\$XDG_DATA_HOME" \
335+ XDG_CACHE_HOME="\$XDG_CACHE_HOME" \
336+ \
337+ XDG_DATA_DIRS="$wrapper_XDG_DATA_DIRS" \
338+ \
339+ FONTCONFIG_FILE="$TBDATA_IN_STORE/fonts.conf" \
340+ \
341+ $self/firefox \
342+ -no-remote \
343+ -profile "\$HOME/TorBrowser/Data/Browser/profile.default" \
344+ "\$@"
258345 EOF
259346 chmod +x $out/bin/tor-browser
260347 '';