Latex "\today" macro expands to December 31st, 1979

With latex installed through the nix package manager (on nixos), \today always expands to December 31st, 1979 instead of the current date. How can I get this to give return the correct date? Files corrected with nix build users have modification times of that date too so is this related?

MWE

Create a directory and add the mwe.tex and flake.nix (based off Exploring Nix Flakes: Build LaTeX Documents Reproducibly).

– mwe.tex –

\documentclass[11pt]{article}

\title{}
\date{\today}

\begin{document}
\maketitle
\end{document}

– mwe.tex ends here –

– flake.nix –

{
  description = "MWE for reproducing \\today macro problem";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        tex = pkgs.texlive.combine {
          inherit (pkgs.texlive) scheme-minimal latex-bin latexmk;
        };
      in rec {
        packages = {
          document = pkgs.stdenvNoCC.mkDerivation rec {
            name = "mwe";
            src = self;
            buildInputs = [ pkgs.coreutils tex ];
            phases = [ "unpackPhase" "buildPhase" "installPhase" ];
            buildPhase = ''
              export PATH="${pkgs.lib.makeBinPath buildInputs}";
              mkdir -p .cache/texmf-var
              env TEXMFHOME=.cache TEXMFVAR=.cache/texmf-var \
                latexmk -pdf -lualatex mwe.tex
            '';
            installPhase = ''
              mkdir -p $out
              cp mwe.pdf $out/
            '';
          };
        };
        defaultPackage = packages.document;
      });
}

– flake.nix ends here –

Then run nix build "." in the new directory. The results should be a pdf containing December 31, 1979 (or when I just ran this I actually got January 1, 1980). I get the same problem when running latexmk as myself at the command line so it’s not only when the file is compiled by a nix build user.j

3 Likes

I have latex install using home-manager (package texlive.combined.scheme-full). I tried your tex file and it’s not happening. The PDF contains December 16, 2021. I compiled using pdflatex.

1 Like

Tried it with pdflatex and xelatex and date is correct for both. Might be a problem with lualatex and not nix then.

1 Like

I read the article you linked, you have to export SOURCE_DATE_EPOCH:

# self.lastModified is the date of last commit
SOURCE_DATE_EPOCH=${toString self.lastModified}

or

# a date you want
SOURCE_DATE_EPOCH=$(date -d "2021-11-30" +%s)
2 Likes

That’s embarrassing. Thank you for pointing that out.

1 Like

But the problem still exists: Why doesn’t LuaLaTeX use the current (build) time by default when SOURCE_DATE_EPOCH is not set?

It totally should, but by default the build epoch is set by the stdenv

1 Like