Skip to content

Commit

Permalink
typst: add support to instantiate typst with a set of typst packages
Browse files Browse the repository at this point in the history
  • Loading branch information
cherrypiejam committed Jan 6, 2025
1 parent bb3802b commit 080f739
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 56 deletions.
117 changes: 61 additions & 56 deletions pkgs/by-name/ty/typst/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,77 @@
xz,
nix-update-script,
versionCheckHook,
callPackage,
}:
let
typst = rustPlatform.buildRustPackage rec {
pname = "typst";
version = "0.12.0";

rustPlatform.buildRustPackage rec {
pname = "typst";
version = "0.12.0";
src = fetchFromGitHub {
owner = "typst";
repo = "typst";
tag = "v${version}";
hash = "sha256-OfTMJ7ylVOJjL295W3Flj2upTiUQXmfkyDFSE1v8+a4=";
};

src = fetchFromGitHub {
owner = "typst";
repo = "typst";
tag = "v${version}";
hash = "sha256-OfTMJ7ylVOJjL295W3Flj2upTiUQXmfkyDFSE1v8+a4=";
};
cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-dphMJ1KkZARSntvyEayAtlYw8lL39K7Iw0X4n8nz3z8=";
};

cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-dphMJ1KkZARSntvyEayAtlYw8lL39K7Iw0X4n8nz3z8=";
};
nativeBuildInputs = [
installShellFiles
pkg-config
];

nativeBuildInputs = [
installShellFiles
pkg-config
];
buildInputs = [
openssl
xz
];

buildInputs = [
openssl
xz
];
env = {
GEN_ARTIFACTS = "artifacts";
OPENSSL_NO_VENDOR = true;
};

env = {
GEN_ARTIFACTS = "artifacts";
OPENSSL_NO_VENDOR = true;
};
postPatch = ''
# Fix for "Found argument '--test-threads' which wasn't expected, or isn't valid in this context"
substituteInPlace tests/src/tests.rs --replace-fail 'ARGS.num_threads' 'ARGS.test_threads'
substituteInPlace tests/src/args.rs --replace-fail 'num_threads' 'test_threads'
'';

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

postInstall = ''
installManPage crates/typst-cli/artifacts/*.1
installShellCompletion \
crates/typst-cli/artifacts/typst.{bash,fish} \
--zsh crates/typst-cli/artifacts/_typst
'';
cargoTestFlags = [ "--workspace" ];

cargoTestFlags = [ "--workspace" ];
nativeInstallCheckInputs = [ versionCheckHook ];
versionCheckProgramArg = [ "--version" ];
doInstallCheck = true;

nativeInstallCheckInputs = [
versionCheckHook
];
versionCheckProgramArg = [ "--version" ];
doInstallCheck = true;
passthru.updateScript = nix-update-script { };

passthru.updateScript = nix-update-script { };

meta = {
changelog = "https://github.com/typst/typst/releases/tag/v${version}";
description = "New markup-based typesetting system that is powerful and easy to learn";
homepage = "https://github.com/typst/typst";
license = lib.licenses.asl20;
mainProgram = "typst";
maintainers = with lib.maintainers; [
drupol
figsoda
kanashimia
];
meta = {
changelog = "https://github.com/typst/typst/releases/tag/v${version}";
description = "New markup-based typesetting system that is powerful and easy to learn";
homepage = "https://github.com/typst/typst";
license = lib.licenses.asl20;
mainProgram = "typst";
maintainers = with lib.maintainers; [
drupol
figsoda
kanashimia
];
};
};
}

internal = callPackage ./with-packages.nix { };

typstFinal = self: self // { withPackages = internal.typstPackagesFor self; };
in
typstFinal typst
42 changes: 42 additions & 0 deletions pkgs/by-name/ty/typst/with-packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
lib,
buildEnv,
typstPackages,
makeBinaryWrapper,
}:

let
typstPackagesFor =
typst:
lib.makeOverridable (
{ ... }@typstPkgs:
f:
let
paths = f typstPkgs;
in
buildEnv {
name = "${typst.name}-env";

inherit paths;

nativeBuildInputs = [ makeBinaryWrapper ];

postBuild = ''
export TYPST_LIB_DIR="$out/lib/typst/packages"
mkdir -p $TYPST_LIB_DIR/preview
for path in $(find $out -type l); do
mv $path $TYPST_LIB_DIR/preview
done
cp -r ${typst}/share $out/share
mkdir -p $out/bin
makeWrapper "${lib.getExe typst}" "$out/bin/typst" --set TYPST_PACKAGE_CACHE_PATH $TYPST_LIB_DIR
'';
}
) typstPackages;
in
{
inherit typstPackagesFor;
}

0 comments on commit 080f739

Please sign in to comment.