{ config, pkgs, lib, ... }: let
singleton = pkgs.writeShellApplication {
name = "singleton.sh";
runtimeInputs = with pkgs; [ jq niri ];
text = builtins.readFile ./singleton.sh;
};
in {
options = {
firefox-apps = lib.mkOption {
type = lib.types.listOf (lib.types.submodule {
options = {
name = lib.mkOption {
type = lib.types.str;
default = null;
};
url = lib.mkOption {
type = lib.types.str;
default = null;
};
icon = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};
enableDesktopEntry = lib.mkOption {
type = lib.types.bool;
default = true;
};
desktopEntryExtras = lib.mkOption {
type = lib.types.attrs;
default = {};
description = "extra settings for desktopEntry, see xdg.desktopEntries.<xxx>";
};
};
});
};
};
config = {
programs.firefox.profiles = builtins.listToAttrs (
lib.imap1 (i: firefox-app: {
name = assert firefox-app.name!=null; firefox-app.name;
value = {
id = i;
extensions.packages = with pkgs.nur.repos.rycee.firefox-addons; [
# auto open all windows in fullscreen mode
i-auto-fullscreen
darkreader
vimium
ublock-origin
];
settings = {
# https://superuser.com/questions/1483037/making-firefox-fullscreen-like-without-actually-maximizing-the-window
# the full screen hotkey/button will trigger fullscreen like normal, except it won't resize the window.
"full-screen-api.ignore-widgets" = true;
# Automatically enable extensions
"extensions.autoDisableScopes" = 0;
# https://stackoverflow.com/questions/51081754/cross-origin-request-blocked-when-loading-local-file
"security.fileuri.strict_origin_policy" = false;
# enable userChrome.css
"toolkit.legacyUserProfileCustomizations.stylesheets" = true;
# disable extensions auto update
"extensions.update.enabled" = false;
};
userChrome = ''
/* [Disabling the mouseover to reveal the address/toolbar while in fullscreen - old method doesn't work](https://support.mozilla.org/en-US/questions/1324666) */
/* [prevent firefox from showing the address bar in fullscreen mode](https://support.mozilla.org/en-US/questions/1323320) */
*|div#fullscr-toggler {display:none!important;}
'';
};
}) config.firefox-apps
);
xdg.desktopEntries = let
firefox-apps-with-desktopEntry = (builtins.filter (firefox-app: firefox-app.enableDesktopEntry) config.firefox-apps);
in builtins.listToAttrs (
map (firefox-app: {
name = assert firefox-app.name!=null; firefox-app.name;
value = {
name = firefox-app.name;
genericName = firefox-app.name;
exec = assert firefox-app.url!=null;
"${singleton}/bin/singleton.sh ${firefox-app.name} firefox -P ${firefox-app.name} --name ${firefox-app.name} ${firefox-app.url}";
icon = if firefox-app.icon != null then firefox-app.icon
else builtins.fetchurl {
url = "http://www.google.com/s2/favicons?domain=${firefox-app.url}&sz=128";
name = "${firefox-app.name}.png";
};
settings = {
StartupWMClass = firefox-app.name;
};
} // firefox-app.desktopEntryExtras;
}) firefox-apps-with-desktopEntry
);
};
}