Commit ac3e0dba authored by linsui's avatar linsui
Browse files

nixos/firefox: format

parent 4360c170
Loading
Loading
Loading
Loading
+184 −150
Original line number Diff line number Diff line
{ pkgs, config, lib, ... }:
{
  pkgs,
  config,
  lib,
  ...
}:

let
  cfg = config.programs.firefox;
@@ -99,7 +104,13 @@ in
    };

    preferences = lib.mkOption {
      type = with lib.types; attrsOf (oneOf [ bool int str ]);
      type =
        with lib.types;
        attrsOf (oneOf [
          bool
          int
          str
        ]);
      default = { };
      description = ''
        Preferences to set from `about:config`.
@@ -112,7 +123,12 @@ in
    };

    preferencesStatus = lib.mkOption {
      type = lib.types.enum [ "default" "locked" "user" "clear" ];
      type = lib.types.enum [
        "default"
        "locked"
        "user"
        "clear"
      ];
      default = "locked";
      description = ''
        The status of `firefox.preferences`.
@@ -127,7 +143,8 @@ in

    languagePacks = lib.mkOption {
      # Available languages can be found in https://releases.mozilla.org/pub/firefox/releases/${cfg.package.version}/linux-x86_64/xpi/
      type = lib.types.listOf (lib.types.enum ([
      type = lib.types.listOf (
        lib.types.enum ([
          "ach"
          "af"
          "an"
@@ -231,7 +248,8 @@ in
          "xh"
          "zh-CN"
          "zh-TW"
      ]));
        ])
      );
      default = [ ];
      description = ''
        The language packs to install.
@@ -273,18 +291,28 @@ in
    }) // (builtins.mapAttrs (k: v: lib.mkEnableOption "${v.name} support") nmhOptions);
  };

  config = let
    forEachEnabledNmh = fn: lib.flatten (lib.mapAttrsToList (k: v: lib.optional cfg.nativeMessagingHosts.${k} (fn k v)) nmhOptions);
  in lib.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."
  config =
    let
      forEachEnabledNmh =
        fn:
        lib.flatten (
          lib.mapAttrsToList (k: v: lib.optional cfg.nativeMessagingHosts.${k} (fn k v)) nmhOptions
        );
    in
    lib.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);

      environment.systemPackages = [
        (cfg.package.override (old: {
        extraPrefsFiles = old.extraPrefsFiles or [] ++ cfg.autoConfigFiles ++ [(pkgs.writeText "firefox-autoconfig.js" cfg.autoConfig)];
          extraPrefsFiles =
            old.extraPrefsFiles or [ ]
            ++ cfg.autoConfigFiles
            ++ [ (pkgs.writeText "firefox-autoconfig.js" cfg.autoConfig) ];
          nativeMessagingHosts = old.nativeMessagingHosts or [ ] ++ cfg.nativeMessagingHosts.packages;
          cfg = (old.cfg or { }) // cfg.wrapperConfig;
        }))
@@ -301,20 +329,26 @@ in
      # Preferences are converted into a policy
      programs.firefox.policies = {
        DisableAppUpdate = true;
      Preferences = (builtins.mapAttrs
        (_: value: { Value = value; Status = cfg.preferencesStatus; })
        cfg.preferences);
      ExtensionSettings = builtins.listToAttrs (builtins.map
        (lang: lib.attrsets.nameValuePair
          "langpack-${lang}@firefox.mozilla.org"
          {
        Preferences = (
          builtins.mapAttrs (_: value: {
            Value = value;
            Status = cfg.preferencesStatus;
          }) cfg.preferences
        );
        ExtensionSettings = builtins.listToAttrs (
          builtins.map (
            lang:
            lib.attrsets.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);
          ) cfg.languagePacks
        );
      };
    };

  meta.maintainers = with lib.maintainers; [ danth linsui ];
  meta.maintainers = with lib.maintainers; [
    danth
    linsui
  ];
}