2022-11-10 20:07:37 +01:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.firefox;
|
|
|
|
|
|
|
|
policyFormat = pkgs.formats.json { };
|
|
|
|
|
|
|
|
organisationInfo = ''
|
|
|
|
When this option is in use, Firefox will inform you that "your browser
|
|
|
|
is managed by your organisation". That message appears because NixOS
|
|
|
|
installs what you have declared here such that it cannot be overridden
|
|
|
|
through the user interface. It does not mean that someone else has been
|
|
|
|
given control of your browser, unless of course they also control your
|
|
|
|
NixOS configuration.
|
|
|
|
'';
|
2023-10-22 00:30:48 +02:00
|
|
|
|
|
|
|
# deprecated per-native-messaging-host options
|
|
|
|
nmhOptions = {
|
|
|
|
browserpass = {
|
|
|
|
name = "Browserpass";
|
|
|
|
package = pkgs.browserpass;
|
|
|
|
};
|
|
|
|
bukubrow = {
|
|
|
|
name = "Bukubrow";
|
|
|
|
package = pkgs.bukubrow;
|
|
|
|
};
|
|
|
|
euwebid = {
|
|
|
|
name = "Web eID";
|
|
|
|
package = pkgs.web-eid-app;
|
|
|
|
};
|
|
|
|
ff2mpv = {
|
|
|
|
name = "ff2mpv";
|
|
|
|
package = pkgs.ff2mpv;
|
|
|
|
};
|
|
|
|
fxCast = {
|
|
|
|
name = "fx_cast";
|
|
|
|
package = pkgs.fx-cast-bridge;
|
|
|
|
};
|
|
|
|
gsconnect = {
|
|
|
|
name = "GSConnect";
|
|
|
|
package = pkgs.gnomeExtensions.gsconnect;
|
|
|
|
};
|
|
|
|
jabref = {
|
|
|
|
name = "JabRef";
|
|
|
|
package = pkgs.jabref;
|
|
|
|
};
|
|
|
|
passff = {
|
|
|
|
name = "PassFF";
|
|
|
|
package = pkgs.passff-host;
|
|
|
|
};
|
|
|
|
tridactyl = {
|
|
|
|
name = "Tridactyl";
|
|
|
|
package = pkgs.tridactyl-native;
|
|
|
|
};
|
|
|
|
ugetIntegrator = {
|
|
|
|
name = "Uget Integrator";
|
|
|
|
package = pkgs.uget-integrator;
|
|
|
|
};
|
|
|
|
};
|
2022-11-18 04:01:28 +01:00
|
|
|
in
|
|
|
|
{
|
2022-11-10 20:07:37 +01:00
|
|
|
options.programs.firefox = {
|
|
|
|
enable = mkEnableOption (mdDoc "the Firefox web browser");
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.firefox;
|
2022-11-18 04:01:28 +01:00
|
|
|
description = mdDoc "Firefox package to use.";
|
2022-11-10 20:07:37 +01:00
|
|
|
defaultText = literalExpression "pkgs.firefox";
|
|
|
|
relatedPackages = [
|
|
|
|
"firefox"
|
|
|
|
"firefox-beta-bin"
|
|
|
|
"firefox-bin"
|
|
|
|
"firefox-devedition-bin"
|
|
|
|
"firefox-esr"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-09-26 17:01:07 +02:00
|
|
|
wrapperConfig = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
description = mdDoc "Arguments to pass to Firefox wrapper";
|
|
|
|
};
|
|
|
|
|
2022-11-10 20:07:37 +01:00
|
|
|
policies = mkOption {
|
2022-11-18 04:01:28 +01:00
|
|
|
type = policyFormat.type;
|
|
|
|
default = { };
|
2022-11-10 20:07:37 +01:00
|
|
|
description = mdDoc ''
|
|
|
|
Group policies to install.
|
|
|
|
|
2023-11-03 10:05:25 +01:00
|
|
|
See [Mozilla's documentation](https://mozilla.github.io/policy-templates/)
|
2022-11-10 20:07:37 +01:00
|
|
|
for a list of available options.
|
|
|
|
|
|
|
|
This can be used to install extensions declaratively! Check out the
|
|
|
|
documentation of the `ExtensionSettings` policy for details.
|
|
|
|
|
|
|
|
${organisationInfo}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
preferences = mkOption {
|
2023-08-08 14:45:53 +02:00
|
|
|
type = with types; attrsOf (oneOf [ bool int str ]);
|
2022-11-18 04:01:28 +01:00
|
|
|
default = { };
|
2022-11-10 20:07:37 +01:00
|
|
|
description = mdDoc ''
|
2022-11-18 04:01:28 +01:00
|
|
|
Preferences to set from `about:config`.
|
2022-11-10 20:07:37 +01:00
|
|
|
|
|
|
|
Some of these might be able to be configured more ergonomically
|
|
|
|
using policies.
|
|
|
|
|
|
|
|
${organisationInfo}
|
|
|
|
'';
|
|
|
|
};
|
2022-11-18 04:13:59 +01:00
|
|
|
|
|
|
|
preferencesStatus = mkOption {
|
|
|
|
type = types.enum [ "default" "locked" "user" "clear" ];
|
|
|
|
default = "locked";
|
|
|
|
description = mdDoc ''
|
|
|
|
The status of `firefox.preferences`.
|
|
|
|
|
|
|
|
`status` can assume the following values:
|
|
|
|
- `"default"`: Preferences appear as default.
|
|
|
|
- `"locked"`: Preferences appear as default and can't be changed.
|
|
|
|
- `"user"`: Preferences appear as changed.
|
|
|
|
- `"clear"`: Value has no effect. Resets to factory defaults on each startup.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-12-18 13:48:49 +01:00
|
|
|
languagePacks = mkOption {
|
|
|
|
# Available languages can be found in https://releases.mozilla.org/pub/firefox/releases/${cfg.package.version}/linux-x86_64/xpi/
|
|
|
|
type = types.listOf (types.enum ([
|
|
|
|
"ach"
|
|
|
|
"af"
|
|
|
|
"an"
|
|
|
|
"ar"
|
|
|
|
"ast"
|
|
|
|
"az"
|
|
|
|
"be"
|
|
|
|
"bg"
|
|
|
|
"bn"
|
|
|
|
"br"
|
|
|
|
"bs"
|
|
|
|
"ca-valencia"
|
|
|
|
"ca"
|
|
|
|
"cak"
|
|
|
|
"cs"
|
|
|
|
"cy"
|
|
|
|
"da"
|
|
|
|
"de"
|
|
|
|
"dsb"
|
|
|
|
"el"
|
|
|
|
"en-CA"
|
|
|
|
"en-GB"
|
|
|
|
"en-US"
|
|
|
|
"eo"
|
|
|
|
"es-AR"
|
|
|
|
"es-CL"
|
|
|
|
"es-ES"
|
|
|
|
"es-MX"
|
|
|
|
"et"
|
|
|
|
"eu"
|
|
|
|
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autoConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = mdDoc ''
|
|
|
|
AutoConfig files can be used to set and lock preferences that are not covered
|
|
|
|
by the policies.json for Mac and Linux. This method can be used to automatically
|
|
|
|
change user preferences or prevent the end user from modifiying specific
|
|
|
|
preferences by locking them. More info can be found in https://support.mozilla.org/en-US/kb/customizing-firefox-using-autoconfig.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-10-22 00:30:48 +02:00
|
|
|
nativeMessagingHosts = ({
|
|
|
|
packages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
|
|
|
description = mdDoc ''
|
|
|
|
Additional packages containing native messaging hosts that should be made available to Firefox extensions.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}) // (mapAttrs (k: v: mkEnableOption (mdDoc "${v.name} support")) nmhOptions);
|
2022-11-10 20:07:37 +01:00
|
|
|
};
|
|
|
|
|
2023-10-22 00:30:48 +02:00
|
|
|
config = let
|
|
|
|
forEachEnabledNmh = fn: flatten (mapAttrsToList (k: v: lib.optional cfg.nativeMessagingHosts.${k} (fn k v)) nmhOptions);
|
|
|
|
in mkIf cfg.enable {
|
|
|
|
warnings = forEachEnabledNmh (k: v:
|
|
|
|
"The `programs.firefox.nativeMessagingHosts.${k}` option is deprecated, " +
|
|
|
|
"please add `${v.package.pname}` to `programs.firefox.nativeMessagingHosts.packages` instead."
|
|
|
|
);
|
|
|
|
programs.firefox.nativeMessagingHosts.packages = forEachEnabledNmh (_: v: v.package);
|
|
|
|
|
2022-11-18 04:13:59 +01:00
|
|
|
environment.systemPackages = [
|
2023-10-19 12:10:22 +02:00
|
|
|
(cfg.package.override (old: {
|
2023-10-22 00:30:48 +02:00
|
|
|
extraPrefsFiles = old.extraPrefsFiles or [] ++ [(pkgs.writeText "firefox-autoconfig.js" cfg.autoConfig)];
|
|
|
|
nativeMessagingHosts = old.nativeMessagingHosts or [] ++ cfg.nativeMessagingHosts.packages;
|
|
|
|
cfg = (old.cfg or {}) // cfg.wrapperConfig;
|
2023-10-19 12:10:22 +02:00
|
|
|
}))
|
2022-11-18 04:13:59 +01:00
|
|
|
];
|
|
|
|
|
2022-11-18 03:53:56 +01:00
|
|
|
environment.etc =
|
|
|
|
let
|
|
|
|
policiesJSON = policyFormat.generate "firefox-policies.json" { inherit (cfg) policies; };
|
|
|
|
in
|
|
|
|
mkIf (cfg.policies != { }) {
|
|
|
|
"firefox/policies/policies.json".source = "${policiesJSON}";
|
|
|
|
};
|
2022-11-10 20:07:37 +01:00
|
|
|
|
|
|
|
# Preferences are converted into a policy
|
2022-12-18 13:48:49 +01:00
|
|
|
programs.firefox.policies = {
|
2022-11-18 04:01:28 +01:00
|
|
|
Preferences = (mapAttrs
|
2022-11-18 04:13:59 +01:00
|
|
|
(_: value: { Value = value; Status = cfg.preferencesStatus; })
|
2022-11-18 04:01:28 +01:00
|
|
|
cfg.preferences);
|
2022-12-18 13:48:49 +01:00
|
|
|
ExtensionSettings = listToAttrs (map
|
|
|
|
(lang: nameValuePair
|
|
|
|
"langpack-${lang}@firefox.mozilla.org"
|
|
|
|
{
|
|
|
|
installation_mode = "normal_installed";
|
|
|
|
install_url = "https://releases.mozilla.org/pub/firefox/releases/${cfg.package.version}/linux-x86_64/xpi/${lang}.xpi";
|
|
|
|
}
|
|
|
|
)
|
|
|
|
cfg.languagePacks);
|
2022-11-18 04:01:28 +01:00
|
|
|
};
|
2022-11-10 20:07:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ danth ];
|
|
|
|
}
|