Commit 20dde675 authored by COLAMAroro's avatar COLAMAroro
Browse files

pulsar: 1.103.0 -> 1.104.0

List of changes in the build:
- Updates to release [1.104.0](https://github.com/pulsar-edit/pulsar/releases/tag/v1.104.0)
- Set the `pname` to small caps (fixes #225755)
- Unpacks/repacks the app.asar bundle to patch binaries for the missing libstdc++.so.6
  - Fixes non-starting Pulsar encountered on non NixOS devices
  - This requires adding asar (and Python3) as dependencies
- Removes the unused imports in the update script
- Made the update script CWD-independant
parent 4c3edba8
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -17,23 +17,26 @@
, makeDesktopItem
, copyDesktopItems
, makeWrapper
, nodePackages
, python3
}:

let
  pname = "Pulsar";
  version = "1.103.0";
  pname = "pulsar";
  version = "1.104.0";

  sourcesPath = {
    x86_64-linux.tarname = "Linux.${pname}-${version}.tar.gz";
    x86_64-linux.hash = "sha256-C9La+rMpxyFthNPwPBZfV1goP/F1TiNYYYwmPCSkKdw=";
    x86_64-linux.hash = "sha256-HEMUQVNPb6qWIXX25N79HwHo7j11MyFiBRsq9otdAL8=";
    aarch64-linux.tarname = "ARM.Linux.${pname}-${version}-arm64.tar.gz";
    aarch64-linux.hash = "sha256-uVGxDLqFgm5USZT6i7pLYJZq8jFxZviVXXYTL3RVhpw=";
    aarch64-linux.hash = "sha256-f+s54XtLLdhTFY9caKTKngJF6zLai0F7ur9v37bwuNE=";
  }.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");

  additionalLibs = lib.makeLibraryPath [
    xorg.libxshmfence
    libxkbcommon
    xorg.libxkbfile
    stdenv.cc.cc.lib
  ];
  newLibpath = "${atomEnv.libPath}:${additionalLibs}";

@@ -57,6 +60,7 @@ stdenv.mkDerivation rec {
  nativeBuildInputs = [
    wrapGAppsHook
    copyDesktopItems
    nodePackages.asar
  ];

  buildInputs = [
@@ -110,12 +114,26 @@ stdenv.mkDerivation rec {
    ln -s ${git}/bin/git $dugite/git/bin/git
    rm -f $dugite/git/libexec/git-core/git
    ln -s ${git}/bin/git $dugite/git/libexec/git-core/git

    # We have to patch a prebuilt binary in the asar archive
    # But asar complains because the node_gyp unpacked dependency uses a prebuilt Python3 itself

    rm $opt/resources/app.asar.unpacked/node_modules/tree-sitter-bash/build/node_gyp_bins/python3
    ln -s ${python3}/bin/python3 $opt/resources/app.asar.unpacked/node_modules/tree-sitter-bash/build/node_gyp_bins/python3
  '' + ''
    # Patch the bundled node executables
    find $opt -name "*.node" -exec patchelf --set-rpath "${newLibpath}:$opt" {} \;
    # Also patch the node executable for apm
    patchelf --set-rpath "${newLibpath}:$opt" $opt/resources/app/ppm/bin/node

    # The pre-packaged ASAR bundle comes with prebuild binaries, expecting libstdc++.so.6
    asarBundle=$TMPDIR/asarbundle
    asar e $opt/resources/app.asar $asarBundle
    find $asarBundle -name "*.node" -exec patchelf --set-rpath "${newLibpath}:$opt" --add-needed libstdc++.so.6 {} \;
    unlink $asarBundle/node_modules/document-register-element/dre # Self referencing symlink, breaking asar rebundling
    asar p $asarBundle $opt/resources/app.asar
    rm -rf $asarBundle

    # We have patched the original wrapper, but now it needs the "PULSAR_PATH" env var
    mkdir -p $out/bin
    wrapProgram $opt/resources/pulsar.sh \
+3 −5
Original line number Diff line number Diff line
@@ -4,15 +4,13 @@
*/

import { promises as fs } from 'node:fs';
import { promisify } from 'node:util';
import { exec as _exec } from 'node:child_process';
const exec = promisify(_exec);

const constants = {
    githubUrl: "https://api.github.com/repos/pulsar-edit/pulsar/releases",
    sha256FileURL: (newVersion) => `https://github.com/pulsar-edit/pulsar/releases/download/v${newVersion}/SHA256SUMS.txt`,
    x86_64FileName: (newVersion) => `Linux.pulsar-${newVersion}.tar.gz`,
    aarch64FileName: (newVersion) => `ARM.Linux.pulsar-${newVersion}-arm64.tar.gz`,
    targetFile: new URL("default.nix", import.meta.url).pathname,
};

async function getLatestVersion() {
@@ -69,10 +67,10 @@ async function updateFile(newVersion, sha256Sums, currentFile) {
    newFile = newFile.replace(/x86_64-linux\.hash = "(.*)";/, `x86_64-linux.hash = "${sha256Sums.x86_64}";`);
    newFile = newFile.replace(/aarch64-linux\.hash = "(.*)";/, `aarch64-linux.hash = "${sha256Sums.aarch64}";`);

    await fs.writeFile('default.nix', newFile);
    await fs.writeFile(constants.targetFile, newFile);
};

let currentFile = await fs.readFile('default.nix', 'utf8');
let currentFile = await fs.readFile(constants.targetFile, 'utf8');
let currentVersion = currentFile.match(/version = "(.*)";/)[1];
const newVersion = await getLatestVersion();
if (currentVersion === newVersion) {