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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
/* TeX Live user docs
- source: ../../../../../doc/languages-frameworks/texlive.xml
- current html: https://nixos.org/nixpkgs/manual/#sec-language-texlive
*/
{ stdenv, lib, fetchurl, runCommand, writeText, buildEnv
, callPackage, ghostscript_headless, harfbuzz
, makeWrapper, python3, ruby, perl, gnused, gnugrep, coreutils
, libfaketime, makeFontsConf
, useFixedHashes ? true
, recurseIntoAttrs
}:
let
# various binaries (compiled)
bin = callPackage ./bin.nix {
ghostscript = ghostscript_headless;
harfbuzz = harfbuzz.override {
withIcu = true; withGraphite2 = true;
};
};
# map: name -> fixed-output hash
fixedHashes = lib.optionalAttrs useFixedHashes (import ./fixedHashes.nix);
# function for creating a working environment from a set of TL packages
combine = import ./combine.nix {
inherit bin combinePkgs buildEnv lib makeWrapper writeText runCommand
stdenv python3 ruby perl gnused gnugrep coreutils libfaketime makeFontsConf;
ghostscript = ghostscript_headless;
};
tlpdb = import ./tlpdb.nix;
tlpdbVersion = tlpdb."00texlive.config";
# the set of TeX Live packages, collections, and schemes; using upstream naming
tl = let
orig = removeAttrs tlpdb [ "00texlive.config" ];
overridden = orig // {
# overrides of texlive.tlpdb
# only *.po for tlmgr
texlive-msg-translations = builtins.removeAttrs orig.texlive-msg-translations [ "hasTlpkg" ];
xdvi = orig.xdvi // { # it seems to need it to transform fonts
deps = (orig.xdvi.deps or []) ++ [ "metafont" ];
};
# remove dependency-heavy packages from the basic collections
collection-basic = orig.collection-basic // {
deps = lib.filter (n: n != "metafont" && n != "xdvi") orig.collection-basic.deps;
};
# add them elsewhere so that collections cover all packages
collection-metapost = orig.collection-metapost // {
deps = orig.collection-metapost.deps ++ [ "metafont" ];
};
collection-plaingeneric = orig.collection-plaingeneric // {
deps = orig.collection-plaingeneric.deps ++ [ "xdvi" ];
};
texdoc = orig.texdoc // {
version = orig.texdoc.version + "-tlpdb-" + (toString tlpdbVersion.revision);
# build Data.tlpdb.lua (part of the 'tlType == "run"' package)
postUnpack = ''
if [[ -f "$out"/scripts/texdoc/texdoc.tlu ]]; then
unxz --stdout "${tlpdbxz}" > texlive.tlpdb
# create dummy doc file to ensure that texdoc does not return an error
mkdir -p support/texdoc
touch support/texdoc/NEWS
TEXMFCNF="${bin.core}"/share/texmf-dist/web2c TEXMF="$out" TEXDOCS=. TEXMFVAR=. \
"${bin.luatex}"/bin/texlua "$out"/scripts/texdoc/texdoc.tlu \
-c texlive_tlpdb=texlive.tlpdb -lM texdoc
cp texdoc/cache-tlpdb.lua "$out"/scripts/texdoc/Data.tlpdb.lua
fi
'';
};
}; # overrides
in lib.mapAttrs mkTLPkg overridden;
# create a TeX package: an attribute set { pkgs = [ ... ]; ... } where pkgs is a list of derivations
mkTLPkg = pname: attrs:
let
version = attrs.version or (toString attrs.revision);
mkPkgV = tlType: let
pkg = attrs // {
sha512 = attrs.sha512.${if tlType == "tlpkg" then "run" else tlType};
inherit pname tlType version;
};
in mkPkg pkg;
in {
# TL pkg contains lists of packages: runtime files, docs, sources, tlpkg, binaries
pkgs =
# tarball of a collection/scheme itself only contains a tlobj file
[( if (attrs.hasRunfiles or false) then mkPkgV "run"
# the fake derivations are used for filtering of hyphenation patterns and formats
else {
inherit pname version;
tlType = "run";
hasFormats = attrs.hasFormats or false;
hasHyphens = attrs.hasHyphens or false;
tlDeps = map (n: tl.${n}) (attrs.deps or []);
}
)]
++ lib.optional (attrs.sha512 ? doc) (mkPkgV "doc")
++ lib.optional (attrs.sha512 ? source) (mkPkgV "source")
++ lib.optional (attrs.hasTlpkg or false) (mkPkgV "tlpkg")
++ lib.optional (bin ? ${pname})
( bin.${pname} // { tlType = "bin"; } );
};
version = {
# day of the snapshot being taken
year = "2023";
month = "03";
day = "19";
# TeX Live version
texliveYear = 2022;
# final (historic) release or snapshot
final = true;
};
# The tarballs on CTAN mirrors for the current release are constantly
# receiving updates, so we can't use those directly. Stable snapshots
# need to be used instead. Ideally, for the release branches of NixOS we
# should be switching to the tlnet-final versions
# (https://tug.org/historic/).
urlPrefixes = with version; lib.optionals final [
# tlnet-final snapshot; used when texlive.tlpdb is frozen
# the TeX Live yearly freeze typically happens in mid-March
"http://ftp.math.utah.edu/pub/tex/historic/systems/texlive/${toString texliveYear}/tlnet-final"
"ftp://tug.org/texlive/historic/${toString texliveYear}/tlnet-final"
] ++ [
# daily snapshots hosted by one of the texlive release managers;
# used for non-final snapshots and as fallback for final snapshots that have not reached yet the historic mirrors
# please note that this server is not meant for large scale deployment and should be avoided on release branches
# https://tug.org/pipermail/tex-live/2019-November/044456.html
"https://texlive.info/tlnet-archive/${year}/${month}/${day}/tlnet"
];
tlpdbxz = fetchurl {
urls = map (up: "${up}/tlpkg/texlive.tlpdb.xz") urlPrefixes;
hash = "sha256-vm7DmkH/h183pN+qt1p1wZ6peT2TcMk/ae0nCXsCoMw=";
};
tlpdbNix = runCommand "tlpdb.nix" {
inherit tlpdbxz;
tl2nix = ./tl2nix.sed;
}
''
xzcat "$tlpdbxz" | sed -rn -f "$tl2nix" | uniq > "$out"
'';
# create a derivation that contains an unpacked upstream TL package
mkPkg = { pname, tlType, revision, version, sha512, postUnpack ? "", stripPrefix ? 1, ... }@args:
let
# the basename used by upstream (without ".tar.xz" suffix)
urlName = pname + lib.optionalString (tlType != "run" && tlType != "tlpkg") ".${tlType}";
tlName = urlName + lib.optionalString (tlType == "tlpkg") ".tlpkg" + "-${version}";
fixedHash = fixedHashes.${tlName} or null; # be graceful about missing hashes
urls = args.urls or (if args ? url then [ args.url ] else
map (up: "${up}/archive/${urlName}.r${toString revision}.tar.xz") (args.urlPrefixes or urlPrefixes));
in runCommand "texlive-${tlName}"
( {
src = fetchurl { inherit urls sha512; };
inherit stripPrefix tlType;
# metadata for texlive.combine
passthru = {
inherit pname tlType version;
} // lib.optionalAttrs (tlType == "run" && args ? deps) {
tlDeps = map (n: tl.${n}) args.deps;
} // lib.optionalAttrs (tlType == "run") {
hasFormats = args.hasFormats or false;
hasHyphens = args.hasHyphens or false;
} // lib.optionalAttrs (tlType == "tlpkg" && args ? postactionScript) {
postactionScript = args.postactionScript;
};
} // lib.optionalAttrs (fixedHash != null) {
outputHash = fixedHash;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
}
)
( ''
mkdir "$out"
if [[ "$tlType" == "tlpkg" ]]; then
tar -xf "$src" \
--strip-components=1 \
-C "$out" --anchored --exclude=tlpkg/tlpobj --exclude=tlpkg/installer --exclude=tlpkg/gpg --keep-old-files \
tlpkg
else
tar -xf "$src" \
--strip-components="$stripPrefix" \
-C "$out" --anchored --exclude=tlpkg --keep-old-files
fi
'' + postUnpack
);
# combine a set of TL packages into a single TL meta-package
combinePkgs = pkgList: lib.catAttrs "pkg" (
let
# a TeX package is an attribute set { pkgs = [ ... ]; ... } where pkgs is a list of derivations
# the derivations make up the TeX package and optionally (for backward compatibility) its dependencies
tlPkgToSets = { pkgs, ... }: map ({ tlType, version ? "", outputName ? "", ... }@pkg: {
# outputName required to distinguish among bin.core-big outputs
key = "${pkg.pname or pkg.name}.${tlType}-${version}-${outputName}";
inherit pkg;
}) pkgs;
pkgListToSets = lib.concatMap tlPkgToSets; in
builtins.genericClosure {
startSet = pkgListToSets pkgList;
operator = { pkg, ... }: pkgListToSets (pkg.tlDeps or []);
});
assertions =
lib.assertMsg (tlpdbVersion.year == version.texliveYear) "TeX Live year in texlive does not match tlpdb.nix, refusing to evaluate" &&
lib.assertMsg (tlpdbVersion.frozen == version.final) "TeX Live final status in texlive does not match tlpdb.nix, refusing to evaluate";
in
tl // {
tlpdb = {
# nested in an attribute set to prevent them from appearing in search
nix = tlpdbNix;
xz = tlpdbxz;
};
bin = assert assertions; bin;
combine = assert assertions; combine;
# Pre-defined combined packages for TeX Live schemes,
# to make nix-env usage more comfortable and build selected on Hydra.
combined = with lib; recurseIntoAttrs (
mapAttrs
(pname: attrs:
addMetaAttrs rec {
description = "TeX Live environment for ${pname}";
platforms = lib.platforms.all;
maintainers = with lib.maintainers; [ veprbl ];
}
(combine {
${pname} = attrs;
extraName = "combined" + lib.removePrefix "scheme" pname;
extraVersion = with version; if final then "-final" else ".${year}${month}${day}";
})
)
{ inherit (tl)
scheme-basic scheme-context scheme-full scheme-gust scheme-infraonly
scheme-medium scheme-minimal scheme-small scheme-tetex;
}
);
}
|