diff options
Diffstat (limited to 'nixpkgs/pkgs/tools/typesetting/tectonic')
-rw-r--r-- | nixpkgs/pkgs/tools/typesetting/tectonic/biber.nix | 54 | ||||
-rw-r--r-- | nixpkgs/pkgs/tools/typesetting/tectonic/default.nix | 63 | ||||
-rw-r--r-- | nixpkgs/pkgs/tools/typesetting/tectonic/tests.nix | 93 | ||||
-rw-r--r-- | nixpkgs/pkgs/tools/typesetting/tectonic/wrapper.nix | 57 |
4 files changed, 267 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/tools/typesetting/tectonic/biber.nix b/nixpkgs/pkgs/tools/typesetting/tectonic/biber.nix new file mode 100644 index 000000000000..9798c1471667 --- /dev/null +++ b/nixpkgs/pkgs/tools/typesetting/tectonic/biber.nix @@ -0,0 +1,54 @@ +/* + This package, `biber-for-tectonic`, provides a compatible version of `biber` + as an optional runtime dependency of `tectonic`. + + The development of tectonic is slowing down recently, such that its `biber` + dependency has been lagging behind the one in the nixpkgs `texlive` bundle. + See: + + https://github.com/tectonic-typesetting/tectonic/discussions/1122 + + It is now feasible to track the biber dependency in nixpkgs, as the + version bump is not very frequent, and it would provide a more complete + user experience of tectonic in nixpkgs. +*/ + +{ lib +, fetchFromGitHub +, fetchpatch +, biber +}: + +let version = "2.17"; in ( + biber.override { + /* + It is necessary to first override the `version` data here, which is + passed to `buildPerlModule`, and then to `mkDerivation`. + + If we simply do `biber.overrideAttrs` the resulting package `name` + would be incorrect, since it has already been preprocessed by + `buildPerlModule`. + */ + texlive.pkgs.biber.texsource = { + inherit version; + inherit (biber) pname meta; + }; + } +).overrideAttrs (prevAttrs: { + src = fetchFromGitHub { + owner = "plk"; + repo = "biber"; + rev = "v${version}"; + hash = "sha256-Tt2sN2b2NGxcWyZDj5uXNGC8phJwFRiyH72n3yhFCi0="; + }; + patches = [ + # Perl>=5.36.0 compatibility + (fetchpatch { + url = "https://patch-diff.githubusercontent.com/raw/plk/biber/pull/411.patch"; + hash = "sha256-osgldRVfe3jnMSOMnAMQSB0Ymc1s7J6KtM2ig3c93SE="; + }) + ]; + meta = prevAttrs.meta // { + maintainers = with lib.maintainers; [ doronbehar bryango ]; + }; +}) diff --git a/nixpkgs/pkgs/tools/typesetting/tectonic/default.nix b/nixpkgs/pkgs/tools/typesetting/tectonic/default.nix new file mode 100644 index 000000000000..e7172e608746 --- /dev/null +++ b/nixpkgs/pkgs/tools/typesetting/tectonic/default.nix @@ -0,0 +1,63 @@ +/* + This file provides the `tectonic-unwrapped` package. On the other hand, + the `tectonic` package is defined in `./wrapper.nix`, by wrapping + - [`tectonic-unwrapped`](./default.nix) i.e. this package, and + - [`biber-for-tectonic`](./biber.nix), + which provides a compatible version of `biber`. +*/ + +{ lib +, stdenv +, fetchFromGitHub +, rustPlatform +, darwin +, fontconfig +, harfbuzz +, openssl +, pkg-config +, icu +}: + +rustPlatform.buildRustPackage rec { + pname = "tectonic"; + version = "0.15.0"; + + src = fetchFromGitHub { + owner = "tectonic-typesetting"; + repo = "tectonic"; + rev = "tectonic@${version}"; + fetchSubmodules = true; + sha256 = "sha256-xZHYiaQ8ASUwu0ieHIXcjRaH06SQoB6OR1y7Ok+FjAs="; + }; + + cargoHash = "sha256-niMgb4zsTWHw5yaa4kJOZzpOzO5gMG4k3cTHwSV+wmY="; + + nativeBuildInputs = [ pkg-config ]; + + buildInputs = [ icu fontconfig harfbuzz openssl ] + ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ ApplicationServices Cocoa Foundation ]); + + # workaround for https://github.com/NixOS/nixpkgs/issues/166205 + NIX_LDFLAGS = lib.optionalString (stdenv.cc.isClang && stdenv.cc.libcxx != null) " -l${stdenv.cc.libcxx.cxxabi.libName}"; + + postInstall = '' + # Makes it possible to automatically use the V2 CLI API + ln -s $out/bin/tectonic $out/bin/nextonic + '' + lib.optionalString stdenv.isLinux '' + substituteInPlace dist/appimage/tectonic.desktop \ + --replace Exec=tectonic Exec=$out/bin/tectonic + install -D dist/appimage/tectonic.desktop -t $out/share/applications/ + install -D dist/appimage/tectonic.svg -t $out/share/icons/hicolor/scalable/apps/ + ''; + + doCheck = true; + + meta = with lib; { + description = "Modernized, complete, self-contained TeX/LaTeX engine, powered by XeTeX and TeXLive"; + homepage = "https://tectonic-typesetting.github.io/"; + changelog = "https://github.com/tectonic-typesetting/tectonic/blob/tectonic@${version}/CHANGELOG.md"; + license = with licenses; [ mit ]; + mainProgram = "tectonic"; + maintainers = with maintainers; [ lluchs doronbehar bryango ]; + }; +} diff --git a/nixpkgs/pkgs/tools/typesetting/tectonic/tests.nix b/nixpkgs/pkgs/tools/typesetting/tectonic/tests.nix new file mode 100644 index 000000000000..da1961c8e42d --- /dev/null +++ b/nixpkgs/pkgs/tools/typesetting/tectonic/tests.nix @@ -0,0 +1,93 @@ +# This package provides `tectonic.passthru.tests`. +# It requires internet access to fetch tectonic's resource bundle on demand. + +{ lib +, fetchFromGitHub +, writeText +, runCommand +, tectonic +, curl +, cacert +, emptyFile +}: + +let + /* + Currently, the test files are only fully available from the `dev` branch of + `biber`. When https://github.com/plk/biber/pull/467 is eventually released, + we can obtain the test files from `texlive.pkgs.biber.texsource`. For now, + i.e. biber<=2.19, we fetch the test files directly from GitHub. + */ + biber-dev-source = fetchFromGitHub { + owner = "plk"; + repo = "biber"; + # curl https://api.github.com/repos/plk/biber/pulls/467 | jq .merge_commit_sha + rev = "d43e352586f5c9f98f0331978ca9d0b908986e09"; + hash = "sha256-Z5BdMteBouiDQasF6GZXkS//YzrZkcX1eLvKIQIBkBs="; + }; + testfiles = "${biber-dev-source}/testfiles"; + + noNetNotice = writeText "tectonic-offline-notice" '' + # To fetch tectonic's web bundle, the tests require internet access, + # which is not available in the current environment. + ''; + # `cacert` is required for tls connections + nativeBuildInputs = [ curl cacert tectonic ]; + checkInternet = '' + if curl --head "bing.com"; then + set -e # continue to the tests defined below, fail on error + else + cat "${noNetNotice}" + cp "${emptyFile}" "$out" + exit # bail out gracefully when there is no internet, do not panic + fi + ''; + + networkRequiringTestPkg = name: script: runCommand + /* + Introduce dependence on `tectonic` in the test package name. Note that + adding `tectonic` to `nativeBuildInputs` is not enough to trigger + rebuilds for a fixed-output derivation. One must update its name or + output hash to induce a rebuild. This behavior is exactly the same as a + standard nixpkgs "fetcher" such as `fetchurl`. + */ + "test-${lib.removePrefix "${builtins.storeDir}/" tectonic.outPath}-${name}" + { + /* + Make a fixed-output derivation, return an `emptyFile` with fixed hash. + These derivations are allowed to access the internet from within a + sandbox, which allows us to test the automatic download of resource + files in tectonic, as a side effect. The `tectonic.outPath` is included + in `name` to induce rebuild of this fixed-output derivation whenever + the `tectonic` derivation is updated. + */ + inherit (emptyFile) + outputHashAlgo + outputHashMode + outputHash + ; + allowSubstitutes = false; + inherit nativeBuildInputs; + } + '' + ${checkInternet} + ${script} + cp "${emptyFile}" "$out" + ''; + +in +lib.mapAttrs networkRequiringTestPkg { + biber-compatibility = '' + # import the test files + cp "${testfiles}"/* . + + # tectonic caches in the $HOME directory, so set it to $PWD + export HOME=$PWD + tectonic -X compile ./test.tex + ''; + + workspace = '' + tectonic -X new + cat Tectonic.toml | grep "${tectonic.bundleUrl}" + ''; +} diff --git a/nixpkgs/pkgs/tools/typesetting/tectonic/wrapper.nix b/nixpkgs/pkgs/tools/typesetting/tectonic/wrapper.nix new file mode 100644 index 000000000000..42125e7855d8 --- /dev/null +++ b/nixpkgs/pkgs/tools/typesetting/tectonic/wrapper.nix @@ -0,0 +1,57 @@ +{ lib +, symlinkJoin +, tectonic +, tectonic-unwrapped +, biber-for-tectonic +, makeBinaryWrapper +, callPackage +}: + +symlinkJoin { + name = "${tectonic-unwrapped.pname}-wrapped-${tectonic-unwrapped.version}"; + paths = [ tectonic-unwrapped ]; + + nativeBuildInputs = [ makeBinaryWrapper ]; + + passthru = { + unwrapped = tectonic-unwrapped; + biber = biber-for-tectonic; + tests = callPackage ./tests.nix { }; + + # The version locked tectonic web bundle, redirected from: + # https://relay.fullyjustified.net/default_bundle_v33.tar + # To check for updates, see: + # https://github.com/tectonic-typesetting/tectonic/blob/master/crates/bundles/src/lib.rs + # ... and look up `get_fallback_bundle_url`. + bundleUrl = "https://data1.fullyjustified.net/tlextras-2022.0r0.tar"; + }; + + # Replace the unwrapped tectonic with the one wrapping it with biber + postBuild = '' + rm $out/bin/{tectonic,nextonic} + '' + # Pin the version of the online TeX bundle that Tectonic's developer + # distribute, so that the `biber` version and the `biblatex` version + # distributed from there are compatible. + # + # Upstream is updating it's online TeX bundle slower then + # https://github.com/plk/biber. That's why we match here the `bundleURL` + # version with that of `biber-for-tectonic`. See also upstream discussion: + # + # https://github.com/tectonic-typesetting/tectonic/discussions/1122 + # + # Hence, we can be rather confident that for the near future, the online + # TeX bundle won't be updated and hence the biblatex distributed there + # won't require a higher version of biber. + + '' + makeWrapper ${lib.getBin tectonic-unwrapped}/bin/tectonic $out/bin/tectonic \ + --prefix PATH : "${lib.getBin biber-for-tectonic}/bin" \ + --add-flags "--web-bundle ${tectonic.passthru.bundleUrl}" + ln -s $out/bin/tectonic $out/bin/nextonic + ''; + + meta = tectonic-unwrapped.meta // { + description = "Tectonic TeX/LaTeX engine, wrapped with a compatible biber"; + maintainers = with lib.maintainers; [ doronbehar bryango ]; + }; +} |