summaryrefslogtreecommitdiffstats
path: root/pkgs/tools/typesetting/tex/texlive/default.nix
blob: 9faca1c147b20d2200521c2e1f1c8fbe189e510b (plain)
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
/*
  TeX Live user docs
  - source: ../../../../../doc/languages-frameworks/texlive.xml
  - current html: https://nixos.org/nixpkgs/manual/#sec-language-texlive
*/
{
  lib,
  stdenv,
  fetchpatch,
  fetchurl,
  runCommand,
  writeShellScript,
  writeText,
  buildEnv,
  ghostscript_headless,
  git-latexdiff,
  harfbuzzFull,
  makeWrapper,
  installShellFiles,
  python3,
  ruby,
  perl,
  tk,
  jre_headless,
  bash,
  snobol4,
  coreutils,
  findutils,
  gawk,
  getopt,
  gettext,
  gnugrep,
  gnumake,
  gnupg,
  gnused,
  gzip,
  html-tidy,
  ncurses,
  zip,
  libfaketime,
  asymptote,
  biber-ms,
  makeFontsConf,
  useFixedHashes ? true,
  extraMirrors ? [ ],
  nixfmt,
  luajit,
  texinfo,
  texlive,
  # for bin.nix
  gnum4,
  jdk_headless,
  perlPackages,
  python3Packages,
  pkg-config,
  autoconf,
  automake,
  libtool,
  cmake,
  ninja,
  libpaper,
  graphite2,
  zziplib,
  potrace,
  gmp,
  mpfr,
  mupdf-headless,
  brotli,
  cairo,
  pixman,
  libxi,
  libxfixes,
  clisp,
  biber,
  woff2,
  xxhash,
  unzip,
  fetchFromGitHub,
  buildPackages,
  zlib,
  libiconv,
  libpng,
  libx11,
  freetype,
  ttfautohint,
  gd,
  libxaw,
  icu,
  libxpm,
  libxmu,
  libxext,
}@args:
let
  # various binaries (compiled)
  bin = import ./bin.nix (args // { tlpdb = overriddenTlpdb; });

  tlpdb = import ./tlpdb.nix;

  tlpdbVersion = tlpdb."00texlive.config";

  # the set of TeX Live packages, collections, and schemes; using upstream naming
  overriddenTlpdb =
    let
      overrides = import ./tlpdb-overrides.nix {
        inherit (texlive) pkgs;
        inherit
          stdenv
          lib
          fetchpatch
          bin
          tlpdb
          tlpdbxz
          installShellFiles
          coreutils
          findutils
          gawk
          getopt
          gettext
          ghostscript_headless
          git-latexdiff
          gnugrep
          gnumake
          gnupg
          gnused
          gzip
          html-tidy
          ncurses
          perl
          python3
          ruby
          zip
          luajit
          texinfo
          ;
      };
    in
    overrides tlpdb;

  version = {
    # day of the snapshot being taken
    year = "2026";
    month = "03";
    day = "01";
    # TeX Live version
    texliveYear = 2025;
    # 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/).
  mirrors =
    extraMirrors
    ++ (
      if version.final then
        [
          # tlnet-final snapshot; used when texlive.tlpdb is frozen
          # the TeX Live yearly freeze typically happens in mid-March
          "mirror://texhistoric/systems/texlive/${toString version.texliveYear}/tlnet-final"
        ]
      else
        [
          # CTAN mirrors
          "https://mirror.ctan.org/systems/texlive/tlnet"
          # daily snapshots hosted by one of the texlive release managers;
          # used for packages that in the meanwhile have been updated or removed from CTAN
          # and for packages that have not reached yet the historic mirrors
          # please note that this server is not meant for large scale deployment
          # https://tug.org/pipermail/tex-live/2019-November/044456.html
          # https://texlive.info/ MUST appear last (see tlpdbxz)
          "https://texlive.info/tlnet-archive/${version.year}/${version.month}/${version.day}/tlnet"
        ]
    );

  tlpdbxz = fetchurl {
    urls =
      map (up: "${up}/tlpkg/texlive.tlpdb.xz")
        # use last mirror for daily snapshots as texlive.tlpdb.xz changes every day
        # TODO make this less hacky
        (if version.final then mirrors else [ (lib.last mirrors) ]);
    hash = "sha256-Vt8DjpBwo9WH7s613vPxVLLKzM7zbUKVu0ngYYl3w0o=";
  };

  tlpdbNix =
    runCommand "tlpdb.nix"
      {
        inherit tlpdbxz;
        tl2nix = ./tl2nix.sed;
        nativeBuildInputs = [ nixfmt ];
      }
      ''
        xzcat "$tlpdbxz" | sed -rn -f "$tl2nix" | uniq | nixfmt > "$out"
      '';

  # map: name -> fixed-output hash
  fixedHashes = lib.optionalAttrs useFixedHashes (import ./fixed-hashes.nix);

  buildTeXLivePackage = import ./build-texlive-package.nix {
    inherit
      lib
      fetchurl
      runCommand
      writeShellScript
      bash
      jre_headless
      perl
      python3
      ruby
      snobol4
      tk
      ;
    texliveBinaries = bin;
  };

  tl = lib.mapAttrs (
    pname:
    {
      revision,
      extraRevision ? "",
      ...
    }@args:
    buildTeXLivePackage (
      args
      # NOTE: the fixed naming scheme must match generate-fixed-hashes.nix
      // {
        inherit mirrors pname;
        fixedHashes = fixedHashes."${pname}-${toString revision}${extraRevision}" or { };
      }
      // lib.optionalAttrs (args ? deps) {
        deps = map (n: texlive.pkgs.${n} or bin.${n}) (args.deps or [ ]);
      }
    )
  ) overriddenTlpdb;

  # function for creating a working environment
  buildTeXEnv = import ./build-tex-env.nix {
    inherit (texlive) pkgs;
    inherit tlpdbVersion;
    ghostscript = ghostscript_headless;
    inherit
      lib
      buildEnv
      libfaketime
      makeFontsConf
      makeWrapper
      runCommand
      toTLPkgSets
      perl
      coreutils
      gawk
      gnugrep
      gnused
      ;
  };

  ### texlive.combine compatibility layer:
  # convert TeX packages to { pkgs = [ ... ]; } lists
  # respecting specified outputs
  toTLPkgList =
    drv:
    let
      drvWithoutDeps = removeAttrs drv [ "tlDeps" ];
      drvWithDeps =
        if (drv ? tlDeps) then
          drv // { tlDeps = if builtins.isFunction drv.tlDeps then drv.tlDeps texlive.pkgs else drv.tlDeps; }
        else
          drv;
    in
    if drv.outputSpecified or false then
      let
        tlType = drv.tlType or tlOutToType.${drv.tlOutputName or drv.outputName} or null;
      in
      lib.optional (tlType != null) (drvWithDeps // { inherit tlType; })
    else
      lib.optional (drv ? tex) (drvWithDeps.tex // { tlType = "run"; })
      ++ lib.optional (drv ? texdoc) (
        drvWithoutDeps.texdoc
        // {
          tlType = "doc";
        }
        // lib.optionalAttrs (drv ? man) { hasManpages = true; }
      )
      ++ lib.optional (drv ? texsource) (drvWithoutDeps.texsource // { tlType = "source"; })
      ++ lib.optional (drv ? tlpkg) (drvWithDeps.tlpkg // { tlType = "tlpkg"; })
      ++ lib.optional (drv ? out) (drvWithDeps.out // { tlType = "bin"; });
  tlOutToType = {
    out = "bin";
    tex = "run";
    texsource = "source";
    texdoc = "doc";
    tlpkg = "tlpkg";
  };

  # convert { pkgs = [ ... ]; } lists to TeX packages
  # possibly more than one, if pkgs is also used to specify dependencies
  tlTypeToOut = {
    run = "tex";
    doc = "texdoc";
    source = "texsource";
    bin = "out";
    tlpkg = "tlpkg";
  };
  toSpecifiedNV = p: rec {
    name = value.tlOutputName;
    value = removeAttrs p [ "pkgs" ] // {
      outputSpecified = true;
      tlOutputName = tlTypeToOut.${p.tlType};
    };
  };
  toTLPkgSet =
    pname: drvs:
    let
      set = lib.listToAttrs (map toSpecifiedNV drvs);
      mainDrv = set.out or set.tex or set.tlpkg or set.texdoc or set.texsource;
    in
    removeAttrs mainDrv [ "outputSpecified" ];
  toTLPkgSets = { pkgs, ... }: lib.mapAttrsToList toTLPkgSet (lib.groupBy (p: p.pname) pkgs);

  # export TeX packages as { pkgs = [ ... ]; } in the top attribute set
  allPkgLists = lib.mapAttrs (n: drv: { pkgs = toTLPkgList drv; }) tl;

  # function for creating a working environment from a set of TL packages
  # now a legacy wrapper around buildTeXEnv
  combine = import ./combine-wrapper.nix {
    inherit (texlive) pkgs;
    inherit
      buildTeXEnv
      lib
      toTLPkgList
      ;
  };

  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";

  # Pre-defined environment packages for TeX Live schemes,
  # to make nix-env usage more comfortable and build selected on Hydra.

  # these license lists should be the sorted union of the licenses of the packages the schemes contain.
  # The correctness of this collation is tested by tests.texlive.licenses
  licenses = with lib.licenses; {
    scheme-basic = [
      cc-by-sa-40
      free
      gfl
      gpl1Only
      gpl2Only
      gpl2Plus
      knuth
      lgpl21
      lppl1
      lppl13c
      mit
      ofl
      publicDomain
    ];
    scheme-bookpub = [
      artistic2
      asl20
      bsd3
      cc-by-sa-40
      fdl13Only
      free
      gfl
      gpl1Only
      gpl2Only
      gpl2Plus
      knuth
      lgpl21
      lppl1
      lppl12
      lppl13c
      mit
      ofl
      publicDomain
    ];
    scheme-context = [
      bsd2
      bsd3
      cc-by-sa-40
      eupl12
      fdl13Only
      free
      gfl
      gfsl
      gpl1Only
      gpl2Only
      gpl2Plus
      gpl3Only
      gpl3Plus
      knuth
      lgpl2
      lgpl21
      lppl1
      lppl13c
      mit
      ofl
      publicDomain
      x11
    ];
    scheme-full = [
      agpl3Only
      artistic1-cl8
      artistic2
      asl20
      bsd0
      bsd2
      bsd3
      bsdOriginal
      cc-by-10
      cc-by-20
      cc-by-30
      cc-by-40
      cc-by-sa-10
      cc-by-sa-20
      cc-by-sa-30
      cc-by-sa-40
      cc0
      eupl12
      fdl13Only
      free
      gfl
      gfsl
      gpl1Only
      gpl2Only
      gpl2Plus
      gpl3Only
      gpl3Plus
      isc
      knuth
      lgpl2
      lgpl21
      lgpl3
      lppl1
      lppl12
      lppl13a
      lppl13c
      mit
      ofl
      publicDomain
      x11
    ];
    scheme-gust = [
      artistic1-cl8
      asl20
      bsd2
      bsd3
      cc-by-40
      cc-by-sa-40
      cc0
      eupl12
      fdl13Only
      free
      gfl
      gfsl
      gpl1Only
      gpl2Only
      gpl2Plus
      gpl3Only
      gpl3Plus
      knuth
      lgpl2
      lgpl21
      lppl1
      lppl12
      lppl13c
      mit
      ofl
      publicDomain
      x11
    ];
    scheme-infraonly = [
      gpl2Plus
      lgpl21
    ];
    scheme-medium = [
      artistic1-cl8
      asl20
      bsd0
      bsd2
      bsd3
      cc-by-40
      cc-by-sa-20
      cc-by-sa-30
      cc-by-sa-40
      cc0
      eupl12
      fdl13Only
      free
      gfl
      gpl1Only
      gpl2Only
      gpl2Plus
      gpl3Only
      gpl3Plus
      isc
      knuth
      lgpl2
      lgpl21
      lgpl3
      lppl1
      lppl12
      lppl13a
      lppl13c
      mit
      ofl
      publicDomain
      x11
    ];
    scheme-minimal = [
      cc-by-sa-40
      free
      gpl1Only
      gpl2Plus
      knuth
      lgpl21
      lppl1
      lppl13c
      mit
      ofl
      publicDomain
    ];
    scheme-small = [
      asl20
      cc-by-40
      cc-by-sa-40
      cc0
      eupl12
      fdl13Only
      free
      gfl
      gpl1Only
      gpl2Only
      gpl2Plus
      gpl3Only
      gpl3Plus
      knuth
      lgpl2
      lgpl21
      lppl1
      lppl12
      lppl13c
      mit
      ofl
      publicDomain
      x11
    ];
    scheme-tetex = [
      agpl3Only
      artistic1-cl8
      asl20
      bsd2
      bsd3
      cc-by-30
      cc-by-40
      cc-by-sa-10
      cc-by-sa-20
      cc-by-sa-30
      cc-by-sa-40
      cc0
      eupl12
      fdl13Only
      free
      gfl
      gpl1Only
      gpl2Only
      gpl2Plus
      gpl3Only
      gpl3Plus
      isc
      knuth
      lgpl2
      lgpl21
      lgpl3
      lppl1
      lppl12
      lppl13a
      lppl13c
      mit
      ofl
      publicDomain
      x11
    ];
  };

  meta = {
    description = "TeX Live environment";
    platforms = lib.platforms.all;
    maintainers = with lib.maintainers; [
      veprbl
      xworld21
    ];
    license = licenses.scheme-infraonly;
  };

  combined = lib.recurseIntoAttrs (
    lib.genAttrs
      [
        "scheme-basic"
        "scheme-bookpub"
        "scheme-context"
        "scheme-full"
        "scheme-gust"
        "scheme-infraonly"
        "scheme-medium"
        "scheme-minimal"
        "scheme-small"
        "scheme-tetex"
      ]
      (
        pname:
        (buildTeXEnv {
          __extraName = "combined" + lib.removePrefix "scheme" pname;
          __extraVersion =
            if version.final then "-final" else ".${version.year}${version.month}${version.day}";
          requiredTeXPackages = ps: [ ps.${pname} ];
          # to maintain full backward compatibility, enable texlive.combine behavior
          __combine = true;
        }).overrideAttrs
          {
            meta = meta // {
              description = "TeX Live environment for ${pname}";
              license = licenses.${pname};
              problems.removal.message = "texlive.combined schemes are deprecated and will be removed from Nixpkgs 27.05. Please switch to texliveSmall or another top level scheme.";
            };
          }
      )
  );

  schemes = lib.listToAttrs (
    map
      (s: {
        name = "texlive" + s;
        value = lib.addMetaAttrs { license = licenses.${"scheme-" + (lib.toLower s)}; } (buildTeXEnv {
          requiredTeXPackages = ps: [ ps.${"scheme-" + (lib.toLower s)} ];
        });
      })
      [
        "Basic"
        "BookPub"
        "ConTeXt"
        "Full"
        "GUST"
        "InfraOnly"
        "Medium"
        "Minimal"
        "Small"
        "TeTeX"
      ]
  );

in
allPkgLists
// {
  pkgs = tl;

  tlpdb = {
    # nested in an attribute set to prevent them from appearing in search
    nix = tlpdbNix;
    xz = tlpdbxz;
  };

  bin =
    assert assertions;
    bin
    // {
      # for backward compatibility
      latexindent = texlive.pkgs.latexindent;
      pygmentex = texlive.pkgs.pygmentex;
    };

  combine =
    assert assertions;
    combine;

  combined =
    assert assertions;
    combined;

  inherit schemes;

  # convenience alias
  withPackages = (buildTeXEnv { }).withPackages;
}