Skip to content

Commit 4114967

Browse files
committed
typst: add support to instantiate typst with a set of typst packages
1 parent d126c9d commit 4114967

File tree

2 files changed

+109
-56
lines changed

2 files changed

+109
-56
lines changed

pkgs/by-name/ty/typst/package.nix

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,77 @@
88
xz,
99
nix-update-script,
1010
versionCheckHook,
11+
callPackage,
1112
}:
13+
let
14+
typst = rustPlatform.buildRustPackage rec {
15+
pname = "typst";
16+
version = "0.12.0";
1217

13-
rustPlatform.buildRustPackage rec {
14-
pname = "typst";
15-
version = "0.12.0";
18+
src = fetchFromGitHub {
19+
owner = "typst";
20+
repo = "typst";
21+
tag = "v${version}";
22+
hash = "sha256-OfTMJ7ylVOJjL295W3Flj2upTiUQXmfkyDFSE1v8+a4=";
23+
};
1624

17-
src = fetchFromGitHub {
18-
owner = "typst";
19-
repo = "typst";
20-
tag = "v${version}";
21-
hash = "sha256-OfTMJ7ylVOJjL295W3Flj2upTiUQXmfkyDFSE1v8+a4=";
22-
};
25+
cargoDeps = rustPlatform.fetchCargoVendor {
26+
inherit pname version src;
27+
hash = "sha256-dphMJ1KkZARSntvyEayAtlYw8lL39K7Iw0X4n8nz3z8=";
28+
};
2329

24-
cargoDeps = rustPlatform.fetchCargoVendor {
25-
inherit pname version src;
26-
hash = "sha256-dphMJ1KkZARSntvyEayAtlYw8lL39K7Iw0X4n8nz3z8=";
27-
};
30+
nativeBuildInputs = [
31+
installShellFiles
32+
pkg-config
33+
];
2834

29-
nativeBuildInputs = [
30-
installShellFiles
31-
pkg-config
32-
];
35+
buildInputs = [
36+
openssl
37+
xz
38+
];
3339

34-
buildInputs = [
35-
openssl
36-
xz
37-
];
40+
env = {
41+
GEN_ARTIFACTS = "artifacts";
42+
OPENSSL_NO_VENDOR = true;
43+
};
3844

39-
env = {
40-
GEN_ARTIFACTS = "artifacts";
41-
OPENSSL_NO_VENDOR = true;
42-
};
45+
postPatch = ''
46+
# Fix for "Found argument '--test-threads' which wasn't expected, or isn't valid in this context"
47+
substituteInPlace tests/src/tests.rs --replace-fail 'ARGS.num_threads' 'ARGS.test_threads'
48+
substituteInPlace tests/src/args.rs --replace-fail 'num_threads' 'test_threads'
49+
'';
4350

44-
postPatch = ''
45-
# Fix for "Found argument '--test-threads' which wasn't expected, or isn't valid in this context"
46-
substituteInPlace tests/src/tests.rs --replace-fail 'ARGS.num_threads' 'ARGS.test_threads'
47-
substituteInPlace tests/src/args.rs --replace-fail 'num_threads' 'test_threads'
48-
'';
51+
postInstall = ''
52+
installManPage crates/typst-cli/artifacts/*.1
53+
installShellCompletion \
54+
crates/typst-cli/artifacts/typst.{bash,fish} \
55+
--zsh crates/typst-cli/artifacts/_typst
56+
'';
4957

50-
postInstall = ''
51-
installManPage crates/typst-cli/artifacts/*.1
52-
installShellCompletion \
53-
crates/typst-cli/artifacts/typst.{bash,fish} \
54-
--zsh crates/typst-cli/artifacts/_typst
55-
'';
58+
cargoTestFlags = [ "--workspace" ];
5659

57-
cargoTestFlags = [ "--workspace" ];
60+
nativeInstallCheckInputs = [ versionCheckHook ];
61+
versionCheckProgramArg = [ "--version" ];
62+
doInstallCheck = true;
5863

59-
nativeInstallCheckInputs = [
60-
versionCheckHook
61-
];
62-
versionCheckProgramArg = [ "--version" ];
63-
doInstallCheck = true;
64+
passthru.updateScript = nix-update-script { };
6465

65-
passthru.updateScript = nix-update-script { };
66-
67-
meta = {
68-
changelog = "https://github.com/typst/typst/releases/tag/v${version}";
69-
description = "New markup-based typesetting system that is powerful and easy to learn";
70-
homepage = "https://github.com/typst/typst";
71-
license = lib.licenses.asl20;
72-
mainProgram = "typst";
73-
maintainers = with lib.maintainers; [
74-
drupol
75-
figsoda
76-
kanashimia
77-
];
66+
meta = {
67+
changelog = "https://github.com/typst/typst/releases/tag/v${version}";
68+
description = "New markup-based typesetting system that is powerful and easy to learn";
69+
homepage = "https://github.com/typst/typst";
70+
license = lib.licenses.asl20;
71+
mainProgram = "typst";
72+
maintainers = with lib.maintainers; [
73+
drupol
74+
figsoda
75+
kanashimia
76+
];
77+
};
7878
};
79-
}
79+
80+
internal = callPackage ./with-packages.nix { };
81+
82+
typstFinal = self: self // { withPackages = internal.typstPackagesFor self; };
83+
in
84+
typstFinal typst
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
lib,
3+
buildEnv,
4+
typstPackages,
5+
makeBinaryWrapper,
6+
}:
7+
8+
let
9+
typstPackagesFor =
10+
typst:
11+
lib.makeOverridable (
12+
{ ... }@typstPkgs:
13+
f:
14+
let
15+
preparedTypstPkgs = f typstPkgs;
16+
expandTypstPkgs =
17+
ps:
18+
if ps == [ ] then
19+
ps
20+
else
21+
lib.foldl' (acc: p: acc ++ lib.singleton p ++ expandTypstPkgs p.typstDeps) [ ] ps;
22+
in
23+
buildEnv {
24+
name = "${typst.name}-env";
25+
26+
paths = lib.unique (expandTypstPkgs preparedTypstPkgs);
27+
28+
buildInputs = [ makeBinaryWrapper ];
29+
30+
postBuild = ''
31+
export TYPST_LIB_DIR="$out/lib/typst/packages"
32+
mkdir -p $TYPST_LIB_DIR/preview
33+
34+
for path in $(find $out -type l); do
35+
mv $path $TYPST_LIB_DIR/preview
36+
done
37+
38+
cp -r ${typst}/share $out/share
39+
mkdir -p $out/bin
40+
41+
makeWrapper "${lib.getExe typst}" "$out/bin/typst" --set TYPST_PACKAGE_CACHE_PATH $TYPST_LIB_DIR
42+
'';
43+
}
44+
) typstPackages;
45+
in
46+
{
47+
inherit typstPackagesFor;
48+
}

0 commit comments

Comments
 (0)