nixos-system-config/overlays/nixpak/firefox.nix

90 lines
3 KiB
Nix
Raw Normal View History

2025-01-24 20:17:36 +01:00
# Shamelessly stolen most parts from here:
# https://github.com/ryan4yin/nix-config/blob/7deed26cc5a3af2072b8c89a688f265607babc80/hardening/nixpaks/firefox.nix
2025-01-24 20:33:38 +01:00
# https://github.com/schizofox/schizofox/blob/cdf69b2a445ff12680657a3bd44ce7c406bf2ae6/flake/modules/home-manager/default.nix
2025-01-24 16:50:18 +01:00
2025-01-25 00:03:28 +01:00
{ lib, ... }: final: prev: {
2025-01-25 01:29:59 +01:00
firefox-esr = let
2025-01-24 23:58:36 +01:00
sandboxed-firefox-esr = prev.mkNixPak {
config = { sloth, ... }: {
2025-01-25 02:04:45 +01:00
app.package = prev.firefox-esr-unwrapped;
2025-01-25 01:29:59 +01:00
app.binPath = "bin/firefox-esr";
2025-01-24 23:58:36 +01:00
flatpak.appId = "org.mozilla.firefox";
2025-01-24 20:17:36 +01:00
2025-01-24 23:58:36 +01:00
dbus.policies = {
"org.a11y.Bus" = "talk";
"org.gnome.SessionManager" = "talk";
"org.freedesktop.ScreenSaver" = "talk";
"org.gtk.vfs.*" = "talk";
"org.gtk.vfs" = "talk";
"org.freedesktop.Notifications" = "talk";
"org.freedesktop.portal.FileChooser" = "talk";
"org.freedesktop.portal.Settings" = "talk";
"org.mpris.MediaPlayer2.firefox.*" = "own";
"org.mozilla.firefox.*" = "own";
"org.mozilla.firefox_beta.*" = "own";
"org.freedesktop.DBus" = "talk";
"org.freedesktop.DBus.*" = "talk";
"ca.desrt.dconf" = "talk";
"org.freedesktop.portal.*" = "talk";
"org.freedesktop.NetworkManager" = "talk";
"org.freedesktop.FileManager1" = "talk";
};
2025-01-24 18:17:52 +01:00
2025-01-24 23:58:36 +01:00
gpu.enable = true;
gpu.provider = "bundle";
fonts.enable = true;
locale.enable = true;
etc.sslCertificates.enable = true;
2025-01-24 20:33:38 +01:00
2025-01-24 23:58:36 +01:00
bubblewrap = let
envSuffix = envKey: sloth.concat' (sloth.env envKey);
in {
bind.dev = [ "/dev/shm" ];
tmpfs = [ "/tmp" ];
2025-01-24 18:17:52 +01:00
2025-01-24 23:58:36 +01:00
bind.rw = [
sloth.xdgDownloadDir
2025-01-24 20:33:38 +01:00
2025-01-24 23:58:36 +01:00
(envSuffix "XDG_RUNTIME_DIR" "/at-spi/bus")
(envSuffix "XDG_RUNTIME_DIR" "/gvfsd")
(envSuffix "XDG_RUNTIME_DIR" "/pulse")
(envSuffix "XDG_RUNTIME_DIR" "/doc")
(envSuffix "XDG_RUNTIME_DIR" "/dconf")
2025-01-24 20:33:38 +01:00
2025-01-24 23:58:36 +01:00
[(sloth.mkdir (sloth.concat' sloth.xdgConfigHome "/mozilla")) (sloth.concat' sloth.homeDir "/.mozilla")]
];
2025-01-24 18:17:52 +01:00
2025-01-24 23:58:36 +01:00
bind.ro = [
"/sys/bus/pci"
"/etc/resolv.conf"
"/etc/localtime"
(sloth.concat' sloth.xdgConfigHome "/dconf")
(sloth.concat' sloth.xdgConfigHome "/gtk-2.0")
(sloth.concat' sloth.xdgConfigHome "/gtk-3.0")
(sloth.concat' sloth.xdgConfigHome "/gtk-4.0")
(sloth.concat' sloth.xdgConfigHome "/dconf")
];
2025-01-24 20:17:36 +01:00
2025-01-24 23:58:36 +01:00
sockets = {
x11 = false;
wayland = true;
pipewire = true;
2025-01-24 20:17:36 +01:00
};
2025-01-24 18:17:52 +01:00
};
2025-01-24 16:50:18 +01:00
};
};
2025-01-25 01:41:54 +01:00
2025-01-25 01:49:23 +01:00
wrappedFirefox = prev.wrapFirefox (sandboxed-firefox-esr.config.env // {
2025-01-25 01:47:56 +01:00
meta = prev.firefox-esr.meta;
2025-01-25 01:53:41 +01:00
gtk3 = prev.libcanberra-gtk3;
2025-01-25 01:48:31 +01:00
}) {
2025-01-25 01:41:54 +01:00
applicationName = "firefox-esr";
pname = "firefox-esr";
desktopName = "Firefox ESR";
icon = "firefox";
wmClass = "firefox-esr";
};
2025-01-24 23:49:02 +01:00
in
2025-01-25 01:47:56 +01:00
wrappedFirefox;
2025-01-24 16:50:18 +01:00
}