Skip to content

Commit

Permalink
texlive: extract generic interface
Browse files Browse the repository at this point in the history
This generic interface allows the addition of texlive-2023 without repeating too
much code or case distinctions

TODO: rename default.nix -> generic.nix, stable.nix -> default.nix
This will be done later as this makes rebasing a lot harder
  • Loading branch information
apfelkuchen6 committed Aug 28, 2023
1 parent 2379bc3 commit d3ffe62
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 59 deletions.
17 changes: 5 additions & 12 deletions pkgs/tools/typesetting/tex/texlive/bin.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
{ lib, stdenv, fetchurl, fetchpatch, buildPackages
, bin, combine, pkgs
, bin, combine, pkgs, src, version
, zlib, libiconv, libpng, libX11
, freetype, gd, libXaw, icu, ghostscript, libXpm, libXmu, libXext
, perl, perlPackages, python3Packages, pkg-config
, libpaper, graphite2, zziplib, harfbuzz, potrace, gmp, mpfr
, brotli, cairo, pixman, xorg, clisp, biber, woff2, xxHash
, makeWrapper, shortenPerlShebang, useFixedHashes, asymptote
, biber-ms
}:
}@args:

# Useful resource covering build options:
# http://tug.org/texlive/doc/tlbuild.html

let
withSystemLibs = map (libname: "--with-system-${libname}");

year = toString ((import ./tlpdb.nix)."00texlive.config").year;
version = year; # keep names simple for now
version = toString args.version.texliveYear; # keep names simple for now

# detect and stop redundant rebuilds that may occur when building new fixed hashes
assertFixedHash = name: src:
if ! useFixedHashes || src ? outputHash then src else throw "The TeX Live package '${src.pname}' must have a fixed hash before building '${name}'.";

common = {
src = fetchurl {
urls = [
"http://ftp.math.utah.edu/pub/tex/historic/systems/texlive/${year}/texlive-${year}0321-source.tar.xz"
"ftp://tug.ctan.org/pub/tex/historic/systems/texlive/${year}/texlive-${year}0321-source.tar.xz"
];
hash = "sha256-X/o0heUessRJBJZFD8abnXvXy55TNX2S20vNT9YXm1Y=";
};
inherit src;

prePatch = ''
for i in texk/kpathsea/mktex*; do
Expand Down Expand Up @@ -77,7 +70,7 @@ let
in rec { # un-indented

inherit (common) cleanBrokenLinks;
texliveYear = year;
texliveYear = version;


core = stdenv.mkDerivation rec {
Expand Down
55 changes: 9 additions & 46 deletions pkgs/tools/typesetting/tex/texlive/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,15 @@
, recurseIntoAttrs
, fetchurl, runCommand
, ghostscript_headless, harfbuzz
, useFixedHashes ? true
, tlpdb, tlpdbxzHash, src, version, mirrors, useFixedHashes ? true, fixedHashes ? {}
}:
let
tlpdb = import ./tlpdb.nix;

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/).
mirrors = 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"
];
# the "texlive-specific" arguments passed to this function.
args = { inherit tlpdb tlpdbxzHash src version mirrors useFixedHashes fixedHashes; };

tlpdbxz = fetchurl {
urls = map (up: "${up}/tlpkg/texlive.tlpdb.xz") mirrors;
hash = "sha256-vm7DmkH/h183pN+qt1p1wZ6peT2TcMk/ae0nCXsCoMw=";
hash = tlpdbxzHash;
};

tlpdbNix = runCommand "tlpdb.nix" {
Expand All @@ -54,26 +26,17 @@ let
xzcat "$tlpdbxz" | sed -rn -f "$tl2nix" | uniq > "$out"
'';

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

tlpdbVersion = tlpdb."00texlive.config";

assertions = with lib;
assertMsg (tlpdbVersion.year == version.texliveYear) "TeX Live year in texlive does not match tlpdb.nix, refusing to evaluate" &&
assertMsg (tlpdbVersion.frozen == version.final) "TeX Live final status in texlive does not match tlpdb.nix, refusing to evaluate";
assertions = let tlpdbVersion = tlpdb."00texlive.config"; in
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";

# the function defining the recursive attribute set that eventually makes up the texlive scope
addPackages = self:
let
callPackage = self.newScope {
callPackage = self.newScope (args // {
ghostscript = ghostscript_headless;
harfbuzz = harfbuzz.override { withIcu = true; withGraphite2 = true; };
inherit useFixedHashes;
# make the tlpdb used by callPackage the "source" tlpdb above, not the one in the scope
# TODO: rename one of them to make things less confusing
inherit tlpdb;
};
});
in {
inherit callPackage;

Expand Down
30 changes: 30 additions & 0 deletions pkgs/tools/typesetting/tex/texlive/stable.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ callPackage, lib, fetchurl, useFixedHashes ? true, fetchpatch }:
lib.makeOverridable callPackage ./. rec {
version = {
texliveYear = 2022;
final = true;
};

mirrors = with version; [
# 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"
# mostly just kept to prevent rebuilds :)
"https://texlive.info/tlnet-archive/2023/03/19/tlnet"
];

src = with version; fetchurl {
urls = [
"http://ftp.math.utah.edu/pub/tex/historic/systems/texlive/${toString texliveYear}/texlive-${toString texliveYear}0321-source.tar.xz"
"ftp://tug.ctan.org/pub/tex/historic/systems/texlive/${toString texliveYear}/texlive-${toString texliveYear}0321-source.tar.xz"
];
hash = "sha256-X/o0heUessRJBJZFD8abnXvXy55TNX2S20vNT9YXm1Y=";
};

tlpdb = import ./tlpdb.nix;
tlpdbxzHash = "sha256-vm7DmkH/h183pN+qt1p1wZ6peT2TcMk/ae0nCXsCoMw=";

fixedHashes = lib.optionalAttrs useFixedHashes (import ./fixed-hashes.nix);
inherit useFixedHashes;
}
7 changes: 6 additions & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5373,7 +5373,12 @@ with pkgs;
texFunctions = callPackage ../tools/typesetting/tex/nix pkgs;

# TeX Live; see https://nixos.org/nixpkgs/manual/#sec-language-texlive
texlive = recurseIntoAttrs (callPackage ../tools/typesetting/tex/texlive { });
texlive = recurseIntoAttrs
# callPackage is not used here in order not to override the override-attribute
# from makeOverridable in stable.nix
(import ../tools/typesetting/tex/texlive/stable.nix {
inherit (__splicedPackages) callPackage lib fetchurl fetchpatch;
});

fop = callPackage ../tools/typesetting/fop {
jdk = openjdk8;
Expand Down

0 comments on commit d3ffe62

Please sign in to comment.