From f7c0641e2ccf1b2e98d60ce6c79031cdda026ea1 Mon Sep 17 00:00:00 2001 From: linsui Date: Fri, 18 Nov 2022 10:53:56 +0800 Subject: nixos/firefox: fix "The option is used but not defined" (cherry picked from commit 6120738eaad48d46ec81f90c62762886fc557c37) --- nixos/modules/programs/firefox.nix | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nixos/modules/programs/firefox.nix b/nixos/modules/programs/firefox.nix index 76e6c1a553f3..c1bb0b3e3612 100644 --- a/nixos/modules/programs/firefox.nix +++ b/nixos/modules/programs/firefox.nix @@ -69,12 +69,13 @@ in { config = mkIf cfg.enable { environment.systemPackages = [ cfg.package ]; - environment.etc."firefox/policies/policies.json".source = - let policiesJSON = - policyFormat.generate - "firefox-policies.json" - { inherit (cfg) policies; }; - in mkIf (cfg.policies != {}) "${policiesJSON}"; + environment.etc = + let + policiesJSON = policyFormat.generate "firefox-policies.json" { inherit (cfg) policies; }; + in + mkIf (cfg.policies != { }) { + "firefox/policies/policies.json".source = "${policiesJSON}"; + }; # Preferences are converted into a policy programs.firefox.policies = -- cgit v1.2.3 From 43acdcfac5af612b006f8edcbc75f7cb702fa9df Mon Sep 17 00:00:00 2001 From: linsui Date: Fri, 18 Nov 2022 11:01:28 +0800 Subject: nixos/firefox: lint (cherry picked from commit b9778b3a9555a571b019e4dec5434e5e470c1ece) --- nixos/modules/programs/firefox.nix | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/nixos/modules/programs/firefox.nix b/nixos/modules/programs/firefox.nix index c1bb0b3e3612..0d162922f57a 100644 --- a/nixos/modules/programs/firefox.nix +++ b/nixos/modules/programs/firefox.nix @@ -15,15 +15,15 @@ let given control of your browser, unless of course they also control your NixOS configuration. ''; - -in { +in +{ options.programs.firefox = { enable = mkEnableOption (mdDoc "the Firefox web browser"); package = mkOption { - description = mdDoc "Firefox package to use."; type = types.package; default = pkgs.firefox; + description = mdDoc "Firefox package to use."; defaultText = literalExpression "pkgs.firefox"; relatedPackages = [ "firefox" @@ -37,6 +37,8 @@ in { }; policies = mkOption { + type = policyFormat.type; + default = { }; description = mdDoc '' Group policies to install. @@ -48,21 +50,19 @@ in { ${organisationInfo} ''; - type = policyFormat.type; - default = {}; }; preferences = mkOption { + type = with types; attrsOf (oneOf [ bool int string ]); + default = { }; description = mdDoc '' - Preferences to set from `about://config`. + Preferences to set from `about:config`. Some of these might be able to be configured more ergonomically using policies. ${organisationInfo} ''; - type = with types; attrsOf (oneOf [ bool int string ]); - default = {}; }; }; @@ -78,14 +78,11 @@ in { }; # Preferences are converted into a policy - programs.firefox.policies = - mkIf (cfg.preferences != {}) - { - Preferences = (mapAttrs (name: value: { - Value = value; - Status = "locked"; - }) cfg.preferences); - }; + programs.firefox.policies = mkIf (cfg.preferences != { }) { + Preferences = (mapAttrs + (name: value: { Value = value; Status = cfg.preferencesStatus; }) + cfg.preferences); + }; }; meta.maintainers = with maintainers; [ danth ]; -- cgit v1.2.3 From b89f48b8e4a2ebfedf29448b687c7535bb4d7c11 Mon Sep 17 00:00:00 2001 From: linsui Date: Fri, 18 Nov 2022 11:13:59 +0800 Subject: nixos/firefox: add preferencesStatus, autoConfig ... and nativeMessagingHosts (cherry picked from commit 958cdd7c6bc9482b43040662f03861b3836a964a) --- nixos/modules/programs/firefox.nix | 64 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/nixos/modules/programs/firefox.nix b/nixos/modules/programs/firefox.nix index 0d162922f57a..f108776aa098 100644 --- a/nixos/modules/programs/firefox.nix +++ b/nixos/modules/programs/firefox.nix @@ -5,6 +5,8 @@ with lib; let cfg = config.programs.firefox; + nmh = cfg.nativeMessagingHosts; + policyFormat = pkgs.formats.json { }; organisationInfo = '' @@ -64,10 +66,68 @@ in ${organisationInfo} ''; }; + + 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. + ''; + }; + + 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. + ''; + }; + + nativeMessagingHosts = mapAttrs (_: v: mkEnableOption (mdDoc v)) { + browserpass = "Browserpass support"; + bukubrow = "Bukubrow support"; + ff2mpv = "ff2mpv support"; + fxCast = "fx_cast support"; + gsconnect = "GSConnect support"; + jabref = "JabRef support"; + passff = "PassFF support"; + tridactyl = "Tridactyl support"; + ugetIntegrator = "Uget Integrator support"; + }; }; config = mkIf cfg.enable { - environment.systemPackages = [ cfg.package ]; + environment.systemPackages = [ + (cfg.package.override { + extraPrefs = cfg.autoConfig; + extraNativeMessagingHosts = with pkgs; optionals nmh.ff2mpv [ + ff2mpv + ] ++ optionals nmh.gsconnect [ + gnomeExtensions.gsconnect + ] ++ optionals nmh.jabref [ + jabref + ] ++ optionals nmh.passff [ + passff-host + ]; + }) + ]; + + nixpkgs.config.firefox = { + enableBrowserpass = nmh.browserpass; + enableBukubrow = nmh.bukubrow; + enableTridactylNative = nmh.tridactyl; + enableUgetIntegrator = nmh.ugetIntegrator; + enableFXCastBridge = nmh.fxCast; + }; environment.etc = let @@ -80,7 +140,7 @@ in # Preferences are converted into a policy programs.firefox.policies = mkIf (cfg.preferences != { }) { Preferences = (mapAttrs - (name: value: { Value = value; Status = cfg.preferencesStatus; }) + (_: value: { Value = value; Status = cfg.preferencesStatus; }) cfg.preferences); }; }; -- cgit v1.2.3 From 44828c98c055c0f5a20b01673a6ff1617387583c Mon Sep 17 00:00:00 2001 From: linsui Date: Sat, 19 Nov 2022 17:55:13 +0800 Subject: nixos/firefox: remove firefox-wayland (cherry picked from commit 7370fcf517830810ceab1fcca65ba634dd85827d) --- nixos/modules/programs/firefox.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/nixos/modules/programs/firefox.nix b/nixos/modules/programs/firefox.nix index f108776aa098..dfd912cdf5c1 100644 --- a/nixos/modules/programs/firefox.nix +++ b/nixos/modules/programs/firefox.nix @@ -33,8 +33,6 @@ in "firefox-bin" "firefox-devedition-bin" "firefox-esr" - "firefox-esr-wayland" - "firefox-wayland" ]; }; -- cgit v1.2.3