-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwrapped-librewolf-launcher.nix
More file actions
79 lines (79 loc) · 2.79 KB
/
Copy pathwrapped-librewolf-launcher.nix
File metadata and controls
79 lines (79 loc) · 2.79 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
{
pkgs ? import <nixpkgs> {}, librewolf ? p: (p.callPackage ./user/librewolf-with-policies.nix {}), librewolfName ? "librewolf"
, profileContent ? null
, baseProfile ? import ./firefox-profile.nix { inherit pkgs; firefox=librewolf; firefoxName = librewolfName; finalContent = profileContent; }
, name ? "firefox-launcher"
}:
rec {
socatCmd = (pkgs.lib.getBin pkgs.socat) + "/bin/socat";
firefoxCmd = (pkgs.lib.getBin (librewolf pkgs)) + "/bin/" + librewolfName;
unionfsCmd = (pkgs.lib.getBin pkgs.unionfs-fuse) + "/bin/unionfs";
xdummyCmd = (pkgs.lib.getBin pkgs.xdummy) + "/bin/xdummy";
xpropCmd = (pkgs.lib.getBin pkgs.xorg.xprop) + "/bin/xprop";
fuserCmd = (pkgs.lib.getBin pkgs.psmisc) + "/bin/fuser";
combineProfileScript = ''
if test -n "$FIREFOX_PROFILE"; then
_FIREFOX_PROFILE="$FIREFOX_PROFILE"
else
mkdir -p "/''${TMPDIR:-tmp}/ff.$USER/profiles/"
_FIREFOX_PROFILE="$(mktemp -d -p "/''${TMPDIR:-/tmp}/ff.$USER/profiles/")"
fi
chmod og-rwx "$_FIREFOX_PROFILE"
test -n "${baseProfile}" && yes n | cp -riT "${baseProfile}" "$_FIREFOX_PROFILE"
chmod u+rwX -R "$_FIREFOX_PROFILE"
'';
homeScript = ''
if test -z "$HOME" || ! test -d "$HOME"; then
export HOME="$(mktemp -d)"
_HOME_KILL="$HOME"
else
_HOME_KILL=
fi;
'';
cleanupScript = ''
if test -n "$_HOME_KILL"; then
echo "Removing [[$_HOME_KILL]]" >&2
rm -rf "$_HOME_KILL"
echo "Removed [[$_HOME_KILL]]" >&2
fi
echo "making accessible [[$FIREFOX_PROFILE]]" >&2
chmod a+rwX -R "$FIREFOX_PROFILE"/* 2> /dev/null
test -n "$FIREFOX_PROFILE_KILL" &&
rm -rf "$FIREFOX_PROFILE"
'';
firefoxProfileCombiner = pkgs.writeScriptBin "combine-firefox-profile" ''
export FIREFOX_PROFILE="$1"
${combineProfileScript}
echo "$_FIREFOX_PROFILE"
'';
displayScript=''
if test -n "$FIREFOX_DISPLAY"; then
export DISPLAY="$FIREFOX_DISPLAY"
"${xdummyCmd}" "$DISPLAY" &
while ! "${xpropCmd}" -root; do
sleep 1;
done
echo "Virtual local DISPLAY=$DISPLAY" >&2
fi
'';
firefoxLauncher = pkgs.writeScriptBin name ''#! /bin/sh
${homeScript}
${displayScript}
echo "$FIREFOX_EXTRA_PREFS" >> "$FIREFOX_PROFILE/prefs.js"
if test -z "$BROWSER_CONTROL_SOCKET" && test -n "$MARIONETTE_SOCKET"; then
export BROWSER_CONTROL_SOCKET="$MARIONETTE_SOCKET"
fi
"${firefoxCmd}" --profile "$FIREFOX_PROFILE" --new-instance "$@"
echo "${librewolfName} finished" >&2
exit_value="$?"
${cleanupScript}
exit $exit_value
'';
firefoxScripts = pkgs.runCommand "firefox-scripts" {} ''
mkdir -p "$out/bin"
ln -s "${firefoxProfileCombiner}"/bin/* "$out/bin"
ln -s "${firefoxLauncher}"/bin/* "$out/bin"
mkdir -p "$out/lib"
ln -s "${baseProfile}" "$out/lib/profile"
'';
}