diff --git a/pkgs/by-name/my/mystmd/package.nix b/pkgs/by-name/my/mystmd/package.nix index 3a956e647590..9092d64aa386 100644 --- a/pkgs/by-name/my/mystmd/package.nix +++ b/pkgs/by-name/my/mystmd/package.nix @@ -1,30 +1,96 @@ { + bun, lib, - buildNpmPackage, fetchFromGitHub, mystmd, + nodejs, + stdenv, testers, nix-update-script, + writableTmpDirAsHomeHook, }: - -buildNpmPackage rec { +stdenv.mkDerivation (finalAttrs: { pname = "mystmd"; - version = "1.3.18"; + version = "1.8.3"; + + strictDeps = true; + __structuredAttrs = true; src = fetchFromGitHub { owner = "jupyter-book"; repo = "mystmd"; - rev = "mystmd@${version}"; - hash = "sha256-20Cxs4ib7xRn4UC9ShiQ+KnyrTCmW/vII7QN9BObY78="; + tag = "mystmd@${finalAttrs.version}"; + hash = "sha256-OmREjNDgmq5+nidBZh4DUy9bMtDeHMrGWZEqKo5TUrQ="; }; - npmDepsHash = "sha256-dcjOxEYTG/EnBRu+RE7cpSEvNmG32QsDDYzItaNTpa0="; + node_modules = stdenv.mkDerivation { + inherit (finalAttrs) src version; + pname = "${finalAttrs.pname}-node_modules"; - dontNpmInstall = true; + nativeBuildInputs = [ + bun + nodejs + writableTmpDirAsHomeHook + ]; + + dontConfigure = true; + dontFixup = true; + + buildPhase = '' + runHook preBuild + export BUN_INSTALL_CACHE_DIR=$(mktemp -d) + bun install --no-progress --frozen-lockfile --no-cache + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/node_modules + cp -R ./node_modules $out + + runHook postInstall + ''; + + outputHash = + { + x86_64-linux = "sha256-4EQkvsoji9M4VCrdwyHm+ncd4XFjgAf34Kt+YeM3qjs="; + aarch64-linux = "sha256-xm4T1BL3AyRsYOERz4LhG4ZJQkSMzspoA+l60OND3E0="; + x86_64-darwin = "sha256-L+zY9O5ridMvZEhGH0R56P3XiDlYF3UrFZwmOYlqxYY="; + aarch64-darwin = "sha256-ZUx+jF7IcEbUCnUUeW0uOFgEpO9UIJpP3/VpUJ5ulAM="; + } + .${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}"); + + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + }; + + nativeBuildInputs = [ + bun + nodejs + ]; + + buildInputs = [ + nodejs + ]; + + buildPhase = '' + runHook preBuild + + cp -R ${finalAttrs.node_modules}/node_modules . + patchShebangs node_modules + bun run build + + runHook postBuild + ''; installPhase = '' runHook preInstall + mkdir -p $out/lib + cp -r node_modules $out/lib/ + cp -r packages $out/lib/ install -D packages/mystmd/dist/myst.cjs $out/bin/myst runHook postInstall @@ -32,8 +98,8 @@ buildNpmPackage rec { passthru = { tests.version = testers.testVersion { - package = mystmd; - version = "v${version}"; + package = finalAttrs.finalPackage; + version = "v${finalAttrs.version}"; }; updateScript = nix-update-script { }; }; @@ -41,9 +107,9 @@ buildNpmPackage rec { meta = { description = "Command line tools for working with MyST Markdown"; homepage = "https://github.com/jupyter-book/mystmd"; - changelog = "https://github.com/jupyter-book/mystmd/blob/${src.rev}/packages/myst-cli/CHANGELOG.md"; + changelog = "https://github.com/jupyter-book/mystmd/blob/${finalAttrs.src.rev}/packages/myst-cli/CHANGELOG.md"; license = lib.licenses.mit; - maintainers = [ ]; + maintainers = with lib.maintainers; [ tbutter ]; mainProgram = "myst"; }; -} +})