Files
lhns--steam-frame-nix/modules/firefox.nix
T
Pierre Kisters 1672210ead firefox: desktop profile user.js only while its Firefox runs
The desktop profile's user.js link (undoing the fullscreen fix there) was
kept in place on every switch and before every launch. Now the launcher
(nested desktop only) makes it right before Firefox starts, waits for
Firefox instead of exec'ing it, and once it has exited and the profile is
no longer in use removes the link and the value Firefox stored from it in
prefs.js. A second launch that hands its URL to the running Firefox returns
at once and leaves both alone; a user.js of the user's own is never
touched. The desktop profile itself is a normal Firefox profile (browser
data) and is never removed.

No activation step touches profiles anymore: leftovers of a crash and what
older versions wrote (user.js copies and links, their prefs.js values) are
steam-frame-nix-cleanup's (orphans on switch), which leaves the desktop
link alone while the profile is in use; the firefox-desktop-userjs --keep
is gone. The launcher lives in firefox/launcher.nix; checks.firefox runs it
against a fake flatpak (link only while running, forwarded second launch,
prefs.js cleaned only once unlocked, own user.js untouched, Steam session).
2026-09-29 00:07:26 +02:00

134 lines
6.1 KiB
Nix

# Firefox Flatpak (org.mozilla.firefox) launcher.
# - prefs and vrFullscreenFix are default prefs (pref(), the default branch:
# never written to prefs.js, so removing one leaves nothing behind). Firefox
# reads defaults/pref/*.js from its system config dir, /app/etc/firefox in
# the Flatpak, the mount point of the org.mozilla.firefox.systemconfig
# extension. The user installation's "unmaintained extension" dir
# ($XDG_DATA_HOME/flatpak/extension/<id>/<arch>/<branch>) provides it: a
# home-manager link to a store dir, which Flatpak mounts itself (the
# sandbox needn't see /nix).
# - vrFullscreenFix: in the Steam session gamescope focuses a fullscreen X11
# window but never shows it (Firefox looks frozen). ignore-widgets keeps
# fullscreen inside the window.
# - desktopProfile: the sessions have separate buses/displays, so a second
# Firefox can't reach the running one and hits the profile lock; the nested
# desktop gets its own profile (a normal Firefox profile: browser data).
# Fullscreen works there, so the launcher undoes the fix in that profile
# only while its Firefox runs: a user.js link to the extension's
# steam-frame-nix-desktop-user.js (a sandbox path; dangling on the host),
# made right before Firefox starts and removed, with the value Firefox
# stored from it in prefs.js, once it has exited (firefox/launcher.nix).
# Leftovers (a crash) and what older versions wrote into profiles (user.js
# copies and links) are removed by steam-frame-nix-cleanup (on switch).
# The entry shadows the Flatpak's (same ID), keeping MIME associations, and is
# seen by the "+" menu (which reads only ~/.local/share/applications).
{ config, pkgs, lib, ... }:
let
cfg = config.steamFrame.firefox;
ffDir = "$HOME/.var/app/org.mozilla.firefox/config/mozilla/firefox";
profileDir = "${ffDir}/${cfg.desktopProfile}";
defaultPrefs = lib.optionalAttrs cfg.disableAv1 { "media.av1.enabled" = false; }
// lib.optionalAttrs cfg.vrFullscreenFix { "full-screen-api.ignore-widgets" = true; }
// cfg.prefs;
desktopFix = cfg.enable && cfg.vrFullscreenFix && cfg.desktopProfile != null;
# Only ever this one pref (steam-frame-nix-cleanup relies on it).
desktopKeys = [ "full-screen-api.ignore-widgets" ];
desktopUserJsName = "steam-frame-nix-desktop-user.js";
sysconfig = pkgs.runCommand "steam-frame-nix-firefox-systemconfig" { } (''
mkdir -p $out/defaults/pref
cp ${pkgs.writeText "steam-frame-nix.js" (lib.concatStrings (lib.mapAttrsToList
(k: v: "pref(${builtins.toJSON k}, ${builtins.toJSON v});\n") defaultPrefs))} \
$out/defaults/pref/steam-frame-nix.js
'' + lib.optionalString desktopFix ''
cp ${pkgs.writeText desktopUserJsName (lib.concatMapStrings
(k: "user_pref(${builtins.toJSON k}, false);\n") desktopKeys)} $out/${desktopUserJsName}
'');
firefox = pkgs.callPackage ./firefox/launcher.nix {
profileDir = if cfg.desktopProfile == null then null else profileDir;
inherit desktopFix desktopKeys;
desktopJs = "/app/etc/firefox/${desktopUserJsName}";
};
in {
imports = [ ./cleanup.nix ];
options.steamFrame.firefox = {
enable = lib.mkEnableOption ''
the Firefox Flatpak (org.mozilla.firefox) launcher with Steam Frame
fixes'';
vrFullscreenFix = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Default full-screen-api.ignore-widgets to true (except in the desktop
profile), so fullscreen fills the window instead of freezing in the
Steam session.
'';
};
disableAv1 = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Default media.av1.enabled to false: the Frame's decoder driver has no
AV1 (H.264, HEVC, VP9 only), so sites like YouTube send VP9/H.264,
decoded in hardware, instead of software-decoded AV1.
'';
};
prefs = lib.mkOption {
type = with lib.types; attrsOf (oneOf [ bool int str ]);
default = { };
example = { "media.autoplay.default" = 5; };
description = ''
Further about:config preferences for every profile (desktop one
included), as default values: about:config can still change them for
a profile, and removing one here leaves nothing behind. Override the
fixes above too. Take effect at the next start of Firefox.
'';
};
desktopProfile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = "desktop";
description = ''
Profile (directory name under the Flatpak's
~/.var/app/org.mozilla.firefox/config/mozilla/firefox) used in the
nested desktop, so both sessions can run Firefox at once; created on
first use, a normal profile with its own browser data. null = the
default profile in both sessions.
'';
};
};
config = lib.mkIf cfg.enable {
# stable: the branch the launcher runs (the extension point has no
# version, so it takes the app's branch).
xdg.dataFile = lib.optionalAttrs (defaultPrefs != { } || desktopFix) {
"flatpak/extension/org.mozilla.firefox.systemconfig/aarch64/stable".source = sysconfig;
} // {
"applications/org.mozilla.firefox.desktop".text = ''
[Desktop Entry]
Type=Application
Name=Firefox
GenericName=Web Browser
Icon=org.mozilla.firefox
Exec=${firefox} @@u %u @@
StartupWMClass=firefox
StartupNotify=true
Terminal=false
Categories=Network;WebBrowser;
MimeType=application/json;application/pdf;application/rdf+xml;application/rss+xml;application/x-xpinstall;application/xhtml+xml;application/xml;audio/flac;audio/ogg;audio/webm;image/avif;image/gif;image/jpeg;image/png;image/svg+xml;image/webp;text/html;text/xml;video/ogg;video/webm;x-scheme-handler/chrome;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/mailto;
Actions=new-window;new-private-window;
[Desktop Action new-window]
Name=New Window
Exec=${firefox} --new-window @@u %u @@
[Desktop Action new-private-window]
Name=New Private Window
Exec=${firefox} --private-window @@u %u @@
'';
};
};
}