Skip to content

Commit 7d8a3b4

Browse files
committed
tectonic: add online passthru.tests.biber
The test requires internet access to fetch tectonic's web bundle on demand. This is achieved by abusing a fixed-output derivation, which is capable of internet access. The `tectonic.outPath` is included in the test package name. This ensures that it is always triggered for rebuild when the main derivation changes.
1 parent d44d59d commit 7d8a3b4

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# This package provides `tectonic.passthru.tests`.
2+
# It requires internet access to fetch tectonic's resource bundle on demand.
3+
4+
{ lib
5+
, fetchFromGitHub
6+
, runCommand
7+
, tectonic
8+
, curl
9+
, cacert
10+
, emptyFile
11+
}:
12+
13+
let
14+
/*
15+
Currently, the test files are only fully available from the `dev` branch of
16+
`biber`. When https://github.com/plk/biber/pull/467 is eventually released,
17+
we can obtain the test files from `texlive.pkgs.biber.texsource`. For now,
18+
i.e. biber<=2.19, we fetch the test files directly from GitHub.
19+
*/
20+
biber-dev-source = fetchFromGitHub {
21+
owner = "plk";
22+
repo = "biber";
23+
# curl https://api.github.com/repos/plk/biber/pulls/467 | jq .merge_commit_sha
24+
rev = "d43e352586f5c9f98f0331978ca9d0b908986e09";
25+
hash = "sha256-Z5BdMteBouiDQasF6GZXkS//YzrZkcX1eLvKIQIBkBs=";
26+
};
27+
testfiles = "${biber-dev-source}/testfiles";
28+
29+
noNetNotice = builtins.toFile "tectonic-offline-notice" ''
30+
# To fetch tectonic's web bundle, the tests require internet access,
31+
# which is not available in the current environment.
32+
'';
33+
# `cacert` is required for tls connections
34+
buildInputs = [ curl cacert tectonic ];
35+
checkInternet = ''
36+
if curl --head "bing.com"; then
37+
set -e # continue to the tests defined below, fail on error
38+
else
39+
cat "${noNetNotice}"
40+
cp "${emptyFile}" "$out"
41+
exit # bail out gracefully when there is no internet, do not panic
42+
fi
43+
'';
44+
45+
fixedOutputTest = name: script: runCommand
46+
/*
47+
Introduce dependence on `tectonic` in the test package name.
48+
Note that adding `tectonic` to `buildInputs` is not enough to trigger
49+
rebuilds for a fixed-output derivation. One must update its name or
50+
output hash to induce a rebuild. This behavior is exactly the same as a
51+
standard nixpkgs "fetcher" such as `fetchurl`.
52+
*/
53+
"test-${lib.removePrefix "${builtins.storeDir}/" tectonic.outPath}-${name}"
54+
{
55+
/*
56+
Make a fixed-output derivation, return an `emptyFile` with fixed hash.
57+
These derivations are allowed to access the internet from within a
58+
sandbox, which allows us to test the automatic download of resource
59+
files in tectonic, as a side effect. The `tectonic.outPath` is included
60+
in `name` to induce rebuild of this fixed-output derivation whenever
61+
the `tectonic` derivation is updated.
62+
*/
63+
inherit (emptyFile)
64+
outputHashAlgo
65+
outputHashMode
66+
outputHash
67+
;
68+
preferLocalBuild = true;
69+
allowSubstitutes = false;
70+
inherit buildInputs;
71+
}
72+
''
73+
${checkInternet}
74+
${script}
75+
cp "${emptyFile}" "$out"
76+
'';
77+
78+
in
79+
lib.mapAttrs fixedOutputTest {
80+
biber = ''
81+
# import the test files
82+
cp "${testfiles}"/* .
83+
84+
# tectonic caches in the $HOME directory, so set it to $PWD
85+
export HOME=$PWD
86+
tectonic -X compile ./test.tex
87+
'';
88+
}

pkgs/tools/typesetting/tectonic/wrapper.nix

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
, tectonic-unwrapped
44
, biber-for-tectonic
55
, makeWrapper
6+
, callPackage
67
}:
78

89
symlinkJoin {
@@ -14,6 +15,7 @@ symlinkJoin {
1415
passthru = {
1516
unwrapped = tectonic-unwrapped;
1617
biber = biber-for-tectonic;
18+
tests = callPackage ./tests.nix { };
1719
};
1820

1921
# Replace the unwrapped tectonic with the one wrapping it with biber

0 commit comments

Comments
 (0)