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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

126 lines
2.8 KiB
Nix
Raw Normal View History

2023-11-18 12:07:56 +00:00
{ lib
, rustPlatform
, fetchFromGitHub
, mkYarnPackage
, fetchYarnDeps
, pkg-config
, libgit2
, openssl
, zlib
, stdenv
, darwin
}:
let
# Keep the vscode "mgt19937.typst-preview" extension in sync when updating
# this package at pkgs/applications/editors/vscode/extensions/default.nix
2024-04-09 15:25:48 +00:00
version = "0.11.4";
2023-11-18 12:07:56 +00:00
src = fetchFromGitHub {
owner = "Enter-tainer";
repo = "typst-preview";
rev = "v${version}";
2024-04-09 15:25:48 +00:00
hash = "sha256-5MbKp6j4+61Do8YH0xPIQPHEjU/kCKsMUUQDJDXzSMw=";
2024-01-16 00:23:02 +00:00
fetchSubmodules = true;
2024-02-20 14:35:18 +00:00
postFetch = ''
cd $out
substituteInPlace addons/frontend/yarn.lock \
--replace-fail '"typst-dom@link:../typst-dom"' '"typst-dom@file:../typst-dom"'
'';
2023-11-18 12:07:56 +00:00
};
frontendSrc = "${src}/addons/frontend";
2024-01-16 00:23:02 +00:00
domSrc = "${src}/addons/typst-dom";
typst-dom = mkYarnPackage {
inherit version;
pname = "typst-dom";
src = domSrc;
packageJSON = ./dom.json;
offlineCache = fetchYarnDeps {
yarnLock = "${domSrc}/yarn.lock";
2024-04-09 15:25:48 +00:00
hash = "sha256-QIGwHG0n6vYfAPA/+CdvK1c+QxM3XyoQdS/T4+TdsKs=";
2024-01-16 00:23:02 +00:00
};
buildPhase = ''
runHook preBuild
yarn --offline build
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -R deps/typst-dom $out
runHook postInstall
'';
doDist = false;
};
2023-11-18 12:07:56 +00:00
frontend = mkYarnPackage {
inherit version;
pname = "typst-preview-frontend";
src = frontendSrc;
2024-01-16 00:23:02 +00:00
packageJSON = ./frontend.json;
2023-11-18 12:07:56 +00:00
offlineCache = fetchYarnDeps {
yarnLock = "${frontendSrc}/yarn.lock";
2024-04-09 15:25:48 +00:00
hash = "sha256-QFiyUky/0BdB5vS9KX5xBOvBCEtJ+zZG4f7ai5j6V4U=";
2023-11-18 12:07:56 +00:00
};
2024-01-16 00:23:02 +00:00
packageResolutions = { inherit typst-dom; };
2023-11-18 12:07:56 +00:00
buildPhase = ''
runHook preBuild
yarn --offline build
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -R deps/typst-preview-frontend/dist $out
runHook postInstall
'';
doDist = false;
};
2024-01-16 00:23:02 +00:00
2023-11-18 12:07:56 +00:00
in
rustPlatform.buildRustPackage {
pname = "typst-preview";
inherit version src;
2024-04-09 15:25:48 +00:00
cargoHash = "sha256-xj8Xvbz0NUy0BFoVS8ONiYZZQWIJu1FZxJkBEuABDOw=";
2023-11-18 12:07:56 +00:00
nativeBuildInputs = [
pkg-config
];
buildInputs = [
libgit2
openssl
zlib
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.CoreServices
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
];
prePatch = ''
mkdir -p addons/vscode/out/frontend
cp -R ${frontend}/* addons/vscode/out/frontend/
2024-03-18 08:54:16 +00:00
cp -R ${frontend}/index.html ./src/index.html
2023-11-18 12:07:56 +00:00
'';
meta = {
description = "Typst preview extension for VSCode";
homepage = "https://github.com/Enter-tainer/typst-preview/";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ berberman ];
mainProgram = "typst-preview";
};
}