Unverified Commit eea25938 authored by Pol Dellaiera's avatar Pol Dellaiera Committed by GitHub
Browse files

meshtastic-web: build from source (#471080)

parents 6aea433c b108b622
Loading
Loading
Loading
Loading
+48 −8
Original line number Diff line number Diff line
{
  stdenv,
  lib,
  fetchurl,
  stdenv,
  fetchFromGitHub,
  pnpm_9,
  fetchPnpmDeps,
  pnpmConfigHook,
  nodejs,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "meshtastic-web";
  version = "2.6.7";

  src = fetchurl {
    url = "https://github.com/meshtastic/web/releases/download/v${finalAttrs.version}/build.tar";
    hash = "sha256-o09DYKBIZUOmmN4g3lM1V0kudjq0Wfwn/OqV0ElRRO0=";
  src = fetchFromGitHub {
    owner = "meshtastic";
    repo = "web";
    tag = "v${finalAttrs.version}";
    hash = "sha256-71/Wr/b42fknVCdeO99AI4ZpJk8Smkse/TFisKLzBCQ=";
    fetchSubmodules = true;
    leaveDotGit = true;
    postFetch = ''
      cd "$out"
      git rev-parse --short HEAD > $out/COMMIT
      find "$out" -name .git -print0 | xargs -0 rm -rf
    '';
  };

  pnpmWorkspaces = [ "*" ];
  pnpmRoot = "packages/web";
  pnpmDeps = fetchPnpmDeps {
    pnpm = pnpm_9;
    inherit (finalAttrs)
      pname
      version
      src
      pnpmWorkspaces
      ;
    fetcherVersion = 2;
    hash = "sha256-p8AdAYqaHoKaWirNy9uPLs/kRDVNDcXBJQ1y29MVAA0=";
  };

  sourceRoot = ".";
  nativeBuildInputs = [
    pnpm_9
    pnpmConfigHook
    nodejs
  ];

  preConfigure = ''
    substituteInPlace packages/web/vite.config.ts \
      --replace-fail "hash = \"DEV\"" "hash = \"$(cat COMMIT)\"" \
      --replace-fail "version = \"v0.0.0\"" "version = \"${finalAttrs.version}\""
  '';

  buildPhase = ''
    runHook preBuild

    gzip -dr .
    pushd packages/web
    pnpm install
    pnpm run build

    runHook postBuild
  '';
@@ -26,7 +66,7 @@ stdenv.mkDerivation (finalAttrs: {
    runHook preInstall

    mkdir -p $out
    cp -ar . $out/
    cp -ar dist/. $out/

    runHook postInstall
  '';