Installing CMU fonts on NixOS

fontslatexnixnixos

I have figured out that I need CMU fonts to be able to typeset Russian text with XeLaTeX. Under NixOS there is cm-unicode package for it, I have installed it with

nix-env -iA nixos.cm_unicode

but XeLaTeX still cannot find it. A LaTeX file that I can compile with XeLaTeX on Ubuntu does not compile with XeLaTeX on NixOS, and I get an error that the CMU font that I indicated was not found.

I've learned that I could list all fonts installed on the system with fc-list, so I tried running fc-list | grep -i cmu, fc-list | grep -i com, fc-list | grep -i unic, but got no results.

How can I get this font installed? This is for NixOS 17.09.


By the way, I have already had to manually install Latin Modern font: it was initially not available for selection in XeLaTeX, but after I installed lmodern package with nix-env -i, it works fine.

I have just tested this again: uninstalling lmodern with nix-env -e removes Latin Modern from the results of fc-list and from font-manager, and installing with nix-env -i restores it. The same does not work the same with cm_unicode.


I have a possibly related question, so I'll put it here. (If it turns out that it is not related, I would appreciate a short comment or explanation.)

I wanted to define my TeX Live environment with all its dependencies in my .nixpkgs/config.nix, so I did

# .nixpkgs/config.nix
{ # ...
  packageOverrides = pkgs: {
    myTexLive = pkgs.texlive.combine {
      inherit (pkgs.texlive) scheme-basic
                             collection-bibtexextra
                             collection-fontsrecommended
                             collection-genericrecommended
                             collection-langcyrillic
                             collection-langfrench
                             collection-latex
                             collection-latexextra
                             collection-latexrecommended
                             collection-mathextra
                             collection-xetex
                             cm-unicode  # from `collection-fontsextra`
                             latexmk
                             lm       # from `collection-fontsrecommended`
                             lm-math  # from `collection-fontsrecommended`
                             texdoc;
    };
}

I was hoping that having lm and cm-unicode TeX Live packages would be enough to have the Latin Modern and CMU fonts install, but it did not work.

Is there any way to declare the necessary fonts as dependencies of myTexLive?

Best Answer

On NixOS fonts cannot be installed via nix-env because for fonts to be found a database of sorts needs to be created. That requires side-effects, yet Nix packages are pure functions. In general, you can think of side-effecting code as being handled by nixos-rebuild; hence you'll need to use configuration.nix:

fonts.fonts = [ pkgs.cm_unicode ];

You can watch my video on NixOS fonts for a demonstration. Pardon my robot-voice.

For Latex-specific info, see https://nixos.org/nixpkgs/manual/#sec-language-texlive

Related Question