diff --git a/pkgs/by-name/ty/typst/package.nix b/pkgs/by-name/ty/typst/package.nix index 37abf902a5b69e..77bff6723e39de 100644 --- a/pkgs/by-name/ty/typst/package.nix +++ b/pkgs/by-name/ty/typst/package.nix @@ -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 diff --git a/pkgs/by-name/ty/typst/with-packages.nix b/pkgs/by-name/ty/typst/with-packages.nix new file mode 100644 index 00000000000000..a4523765d02476 --- /dev/null +++ b/pkgs/by-name/ty/typst/with-packages.nix @@ -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; +}