Skip to content

Commit

Permalink
typst: add initial support for typst packages
Browse files Browse the repository at this point in the history
  • Loading branch information
cherrypiejam committed Dec 30, 2024
1 parent 3e7585f commit b5ab425
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 56 deletions.
31 changes: 31 additions & 0 deletions pkgs/build-support/build-typst-package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ lib, stdenvNoCC }:
{
nativeBuildInputs ? [ ],
buildInputs ? [ ],
meta ? { },
...
}@attrs:
let
cleanAttrs = lib.flip lib.removeAttrs [ ];
typstPkgPrefix = "typst-package";
in
stdenvNoCC.mkDerivation (
(cleanAttrs attrs)
// (with attrs; {
name = lib.concatStringsSep "-" [
typstPkgPrefix
pname
version
];
installPhase =
let
outDir = "$out/${pname}/${version}";
in
''
${attrs.installPhase}
mv $out tmp
mkdir -p ${outDir}
mv -T tmp ${outDir}
'';
})
)
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";
rev = "refs/tags/v${version}";
hash = "sha256-OfTMJ7ylVOJjL295W3Flj2upTiUQXmfkyDFSE1v8+a4=";
};

src = fetchFromGitHub {
owner = "typst";
repo = "typst";
rev = "refs/tags/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
52 changes: 52 additions & 0 deletions pkgs/by-name/ty/typst/with-packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
pkgs,
lib,
stdenvNoCC,
callPackage,
makeBinaryWrapper,
buildTypstPackage,
buildEnv,
}:

let
cleanAttrs = lib.flip lib.removeAttrs [ ];

typstPackages = callPackage ../../../top-level/typst-packages.nix {
callPackage = lib.callPackageWith (pkgs // { inherit buildTypstPackage; });
};

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

inherit paths;

nativeBuildInputs = [ makeBinaryWrapper ];

postBuild = ''
export _XDG_CACHE_HOME="$out/lib/"
export TYPST_LIB="$_XDG_CACHE_HOME/typst/packages/preview"
mkdir -p $TYPST_LIB
for path in $(find $out -type l); do
mv $path $TYPST_LIB
done
cp -r ${typst}/share $out/share
mkdir -p $out/bin
makeWrapper "${typst}/bin/typst" "$out/bin/typst" --set XDG_CACHE_HOME $_XDG_CACHE_HOME
'';
}
) typstPackages;
in
{
inherit typstPackages typstPackagesFor;
}
29 changes: 29 additions & 0 deletions pkgs/development/typst-packages/cetz.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ buildTypstPackage, fetchFromGitHub }:

buildTypstPackage rec {
pname = "cetz";
version = "0.2.2";

src = fetchFromGitHub {
owner = "cetz-package";
repo = "cetz";
rev = "v${version}";
hash = "sha256-5+Np64+0Ca8yL7D1CCUewF03Wh6BM2bV1BQNUA+bW74=";
deepClone = true;
};

nativeBuildInputs = [
just
file
perl
];

buildPhase = ''
patchShebangs scripts/package
HOME=$(pwd) just install
'';

installPhase = ''
cp -r .local/share/typst/packages/local/cetz/0.2.2 $out/
'';
}
18 changes: 18 additions & 0 deletions pkgs/development/typst-packages/oxifmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ buildTypstPackage, fetchFromGitHub }:

buildTypstPackage rec {
pname = "oxifmt";
version = "0.2.0";

src = fetchFromGitHub {
owner = "PgBiel";
repo = "typst-oxifmt";
rev = "v${version}";
hash = "sha256-OJpkUsoAOHHn7T2O+wICW4nLJ+epkAOfe5R1pMhv1MQ=";
};

installPhase = ''
mkdir -p $out
cp -r . $out
'';
}
18 changes: 18 additions & 0 deletions pkgs/development/typst-packages/polylux.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ buildTypstPackage, fetchFromGitHub }:

buildTypstPackage rec {
pname = "polylux";
version = "0.3.1";

src = fetchFromGitHub {
owner = "andreasKroepelin";
repo = "polylux";
rev = "v${version}";
hash = "sha256-jErxl2s2xez2huUwpsT6N1pZANvuZMdIt4taFOurCtU=";
};

installPhase = ''
mkdir -p $out
cp -r . $out
'';
}
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15685,6 +15685,8 @@ with pkgs;
inherit (darwin.apple_sdk.frameworks) Security;
};

buildTypstPackage = callPackage ../build-support/build-typst-package.nix {};

ueberzug = with python3Packages; toPythonApplication ueberzug;

ueberzugpp = callPackage ../by-name/ue/ueberzugpp/package.nix {
Expand Down
9 changes: 9 additions & 0 deletions pkgs/top-level/typst-packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ callPackage }:

{
polylux = callPackage ../development/typst-packages/polylux.nix { };

cetz = callPackage ../development/typst-packages/cetz.nix { };

oxifmt = callPackage ../development/typst-packages/oxifmt.nix { };
}

0 comments on commit b5ab425

Please sign in to comment.