Skip to content

Commit 0bcf7c9

Browse files
committed
typst: add initial support for typst packages
1 parent 3e7585f commit 0bcf7c9

File tree

8 files changed

+226
-56
lines changed

8 files changed

+226
-56
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{ lib, stdenvNoCC }:
2+
{
3+
nativeBuildInputs ? [ ],
4+
buildInputs ? [ ],
5+
meta ? { },
6+
...
7+
}@attrs:
8+
let
9+
cleanAttrs = lib.flip lib.removeAttrs [ ];
10+
typstPkgPrefix = "typst-package";
11+
in
12+
stdenvNoCC.mkDerivation (
13+
(cleanAttrs attrs)
14+
// (with attrs; {
15+
name = lib.concatStringsSep "-" [
16+
typstPkgPrefix
17+
pname
18+
version
19+
];
20+
installPhase =
21+
let
22+
outDir = "$out/${pname}/${version}";
23+
in
24+
''
25+
${attrs.installPhase}
26+
mv $out tmp
27+
mkdir -p ${outDir}
28+
mv -T tmp ${outDir}
29+
'';
30+
})
31+
)

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+
rev = "refs/tags/v${version}";
22+
hash = "sha256-OfTMJ7ylVOJjL295W3Flj2upTiUQXmfkyDFSE1v8+a4=";
23+
};
1624

17-
src = fetchFromGitHub {
18-
owner = "typst";
19-
repo = "typst";
20-
rev = "refs/tags/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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
pkgs,
3+
lib,
4+
stdenvNoCC,
5+
callPackage,
6+
makeBinaryWrapper,
7+
buildTypstPackage,
8+
buildEnv,
9+
}:
10+
11+
let
12+
cleanAttrs = lib.flip lib.removeAttrs [ ];
13+
14+
typstPackages = callPackage ../../../top-level/typst-packages.nix {
15+
callPackage = lib.callPackageWith (pkgs // { inherit buildTypstPackage; });
16+
};
17+
18+
typstPackagesFor =
19+
typst:
20+
lib.makeOverridable (
21+
{ ... }@typstPkgs:
22+
f:
23+
let
24+
paths = f typstPkgs;
25+
in
26+
buildEnv {
27+
name = "${typst.name}-env";
28+
29+
inherit paths;
30+
31+
nativeBuildInputs = [ makeBinaryWrapper ];
32+
33+
postBuild = ''
34+
export _XDG_CACHE_HOME="$out/lib/"
35+
export TYPST_LIB="$_XDG_CACHE_HOME/typst/packages/preview"
36+
mkdir -p $TYPST_LIB
37+
38+
for path in $(find $out -type l); do
39+
mv $path $TYPST_LIB
40+
done
41+
42+
cp -r ${typst}/share $out/share
43+
mkdir -p $out/bin
44+
45+
makeWrapper "${typst}/bin/typst" "$out/bin/typst" --set XDG_CACHE_HOME $_XDG_CACHE_HOME
46+
'';
47+
}
48+
) typstPackages;
49+
in
50+
{
51+
inherit typstPackages typstPackagesFor;
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
buildTypstPackage,
3+
fetchFromGitHub,
4+
just,
5+
file,
6+
perl,
7+
}:
8+
9+
buildTypstPackage rec {
10+
pname = "cetz";
11+
version = "0.2.2";
12+
13+
src = fetchFromGitHub {
14+
owner = "cetz-package";
15+
repo = "cetz";
16+
rev = "v${version}";
17+
hash = "sha256-5+Np64+0Ca8yL7D1CCUewF03Wh6BM2bV1BQNUA+bW74=";
18+
deepClone = true;
19+
};
20+
21+
nativeBuildInputs = [
22+
just
23+
file
24+
perl
25+
];
26+
27+
buildPhase = ''
28+
patchShebangs scripts/package
29+
HOME=$(pwd) just install
30+
'';
31+
32+
installPhase = ''
33+
cp -r .local/share/typst/packages/local/cetz/0.2.2 $out/
34+
'';
35+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ buildTypstPackage, fetchFromGitHub }:
2+
3+
buildTypstPackage rec {
4+
pname = "oxifmt";
5+
version = "0.2.0";
6+
7+
src = fetchFromGitHub {
8+
owner = "PgBiel";
9+
repo = "typst-oxifmt";
10+
rev = "v${version}";
11+
hash = "sha256-OJpkUsoAOHHn7T2O+wICW4nLJ+epkAOfe5R1pMhv1MQ=";
12+
};
13+
14+
installPhase = ''
15+
mkdir -p $out
16+
cp -r . $out
17+
'';
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ buildTypstPackage, fetchFromGitHub }:
2+
3+
buildTypstPackage rec {
4+
pname = "polylux";
5+
version = "0.3.1";
6+
7+
src = fetchFromGitHub {
8+
owner = "andreasKroepelin";
9+
repo = "polylux";
10+
rev = "v${version}";
11+
hash = "sha256-jErxl2s2xez2huUwpsT6N1pZANvuZMdIt4taFOurCtU=";
12+
};
13+
14+
installPhase = ''
15+
mkdir -p $out
16+
cp -r . $out
17+
'';
18+
}

pkgs/top-level/all-packages.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15685,6 +15685,8 @@ with pkgs;
1568515685
inherit (darwin.apple_sdk.frameworks) Security;
1568615686
};
1568715687

15688+
buildTypstPackage = callPackage ../build-support/build-typst-package.nix {};
15689+
1568815690
ueberzug = with python3Packages; toPythonApplication ueberzug;
1568915691

1569015692
ueberzugpp = callPackage ../by-name/ue/ueberzugpp/package.nix {

pkgs/top-level/typst-packages.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ callPackage }:
2+
3+
{
4+
polylux = callPackage ../development/typst-packages/polylux.nix { };
5+
6+
cetz = callPackage ../development/typst-packages/cetz.nix { };
7+
8+
oxifmt = callPackage ../development/typst-packages/oxifmt.nix { };
9+
}

0 commit comments

Comments
 (0)