-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-document.nix
87 lines (65 loc) · 1.98 KB
/
build-document.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Build a reproducible latex document with latexmk, based on:
# https://flyx.org/nix-flakes-latex/
{ pkgs
# Document source
, src ? ./.
# Name of the final pdf file
, name ? "document.pdf"
# Use -shell-escape
, shellEscape ? false
# Use minted (requires shellEscape)
, minted ? false
# Additional flags for latexmk
, extraFlags ? []
# Do not use the default latexmk flags. Usefull if you have a .latexmkrc or you
# don't want to use lualatex
, dontUseDefaultFlags ? false
# texlive packages needed to build the document
# you can also include other packages as a list.
, texlive ? pkgs.texlive.combined.scheme-full
# Pygments package to use (needed for minted)
, pygments ? pkgs.python39Packages.pygments
# Add system fonts
# you can specify one font directly with: pkgs.fira-code
# of join multiple fonts using symlinJoin:
# pkgs.symlinkJoin { name = "fonts"; paths = with pkgs; [ fira-code souce-code-pro ]; }
, fonts ? null
# Date for the document in unix time. You can change it
# to "$(date -r . +%s)" , "$(date -d "2022/02/22" +%s)", toString
# self.lastModified
, SOURCE_DATE_EPOCH ? "$(git log -1 --pretty=%ct)"
}:
let
lib = pkgs.lib;
defaultFlags = [
"-interaction=nonstopmode"
"-pdf"
"-lualatex"
"-pretex='\\pdfvariable suppressoptionalinfo 512\\relax'"
"-usepretex"
];
flags = lib.concatLists [
(lib.optional (!dontUseDefaultFlags) defaultFlags)
extraFlags
(lib.optional shellEscape ["-shell-escape" ])
];
in
assert minted -> shellEscape;
pkgs.stdenvNoCC.mkDerivation rec {
inherit src name;
buildInputs = [ texlive pkgs.git ] ++
lib.optional minted [ pkgs.which pygments ];
TEXMFHOME = "./cache";
TEXMFVAR = "./cache/var";
OSFONTDIR = lib.optionalString (fonts != null) "${fonts}/share/fonts";
buildPhase = ''
runHook preBuild
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH}" latexmk ${toString flags}
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -m644 -D *.pdf $out/${name}
runHook postInstall
'';
}