How to set system-wide default emoji font?

I am using nixos unstable and would like to use the emoji provided by the OpenMoji project as default emoji in applications (rofi, chromium, firefox, terminal, etc…). Luckily, such font can be installed in unstable (package is called openmoji-color).

This is my fonts section in the configuration.nix looks:

    fonts.fonts = with pkgs; [
        # Serif fonts
        roboto ttf_bitstream_vera
        liberation_ttf dejavu_fonts

        # Mono fonts
        (nerdfonts.override { fonts = [ 
            "FantasqueSansMono" 
            ]; })

        # Emoji
        openmoji-color
    ];

    fonts.fontconfig = {
      defaultFonts = {
        emoji = [ "OpenMoji Color" ];
      };
    };

However, when I open rofimoji or firefox or chromium and look for emojis, I can see that they are only rendered with noto-fonts-emoji (despite I did not install specifically any noto fonts).

Do you know how to remove that noto fonts emoji for som reasons get installed and force the emoji to be rendered with OpenMoji?

According to https://github.com/hfg-gmuend/openmoji/tree/master/font, the fonts use SVG table which currently is not supported by anything other than Firefox.

And since fontconfig will not recognize it as color font, it will prefer Noto. Only if you disable Noto installation, it will use OpenMoji – you can play with nixosTests.fontconfig-default-fonts. But again only Firefox will be able to use it.

--- a/nixos/tests/fontconfig-default-fonts.nix
+++ b/nixos/tests/fontconfig-default-fonts.nix
@@ -7,11 +7,11 @@ import ./make-test-python.nix ({ lib, ... }:
   ];
 
   machine = { config, pkgs, ... }: {
-    fonts.enableDefaultFonts = true; # Background fonts
+    fonts.enableDefaultFonts = false; # Background fonts
     fonts.fonts = with pkgs; [
-      noto-fonts-emoji
+      # noto-fonts-emoji
       cantarell-fonts
-      twitter-color-emoji
+      openmoji-color
       source-code-pro
       gentium
     ];
@@ -19,7 +19,7 @@ import ./make-test-python.nix ({ lib, ... }:
       serif = [ "Gentium Plus" ];
       sansSerif = [ "Cantarell" ];
       monospace = [ "Source Code Pro" ];
-      emoji = [ "Twitter Color Emoji" ];
+      emoji = [ "OpenMoji Color" ];
     };
   };
 
@@ -27,6 +27,6 @@ import ./make-test-python.nix ({ lib, ... }:
     machine.succeed("fc-match serif | grep '\"Gentium Plus\"'")
     machine.succeed("fc-match sans-serif | grep '\"Cantarell\"'")
     machine.succeed("fc-match monospace | grep '\"Source Code Pro\"'")
-    machine.succeed("fc-match emoji | grep '\"Twitter Color Emoji\"'")
+    machine.succeed("fc-match emoji | tee >(systemd-cat) | grep '\"OpenMoji Color\"'")
   '';
 })

Thank you very much for your reply but then may I ask:

  1. Why does still Firefox use noto fonts despite the openmoji are set as default? When I was using void linux I just had to install the openmoji and they would be rendered automatically in Firefox.
  2. Why nixos installs noto fonts and used them as default? Where does it take ‘such command’ from if no noto fonts is specifically put in the configuration? Why not another emoji font, like the Twitter Color Emoji? (just curious)
  3. I am still quite new to nixos. What would be such nixosTests.fontconfig-default-fonts and how to use it?

Probably because Firefox has its own font configuration settings. On void, you had no other emoji fonts installed, so Firefox picked up the only one that you had. On NixOS, you have to change that in Firefox settings.

When you enable Xorg, the fonts.enableDefaultFonts option automatically becomes available as well. The list of default fonts includes Noto Fonts. (https://github.com/NixOS/nixpkgs/blob/7b77cca268d1c0de2c22c13baf19654a47abe562/nixos/modules/config/fonts/fonts.nix#L36)

2 Likes

The default font settings are bit of a misnomer. It only adds a certain font to the top of fontconfigʼs list of fonts to use for the emoji family. But fontconfig will still prefer any other installed colour font when it does not recognize the preferred font as containing colour glyphs.

Hence when Firefox asks fontconfig for an emoji font, it will receive Noto as the answer.

We need to install a emoji font if we want emoji to work by default. There is not much of a choice of emoji fonts that are not SVG and we have them packaged – only Noto, Twitter and JoyPixels (unfree). So we went with Noto as that was most popular and used by other distros (Ubuntu).

2 Likes