1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00

marktext: build from source (#354253)

This commit is contained in:
Aleksana 2024-12-10 11:30:15 +08:00 committed by GitHub
commit 9f9cacfac9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 207 additions and 24 deletions

View file

@ -0,0 +1,45 @@
From d9ee8be58200be1bcf1cf16dda44de811a9e4660 Mon Sep 17 00:00:00 2001
From: wxt <3264117476@qq.com>
Date: Fri, 8 Nov 2024 09:06:22 +0800
Subject: [PATCH] update electron
---
package.json | 2 +-
yarn.lock | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/package.json b/package.json
index 3b8e07a8..b4956d9d 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,7 @@
"deobfuscateStackTrace": "node tools/deobfuscateStackTrace.js"
},
"dependencies": {
- "@electron/remote": "^2.0.8",
+ "@electron/remote": "^2.1.2",
"@hfelix/electron-localshortcut": "^4.0.1",
"@marktext/file-icons": "^1.0.6",
"@octokit/rest": "^18.12.0",
diff --git a/yarn.lock b/yarn.lock
index 4abf622d..d2310b45 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1589,10 +1589,10 @@
global-agent "^3.0.0"
global-tunnel-ng "^2.7.1"
-"@electron/remote@^2.0.8":
- version "2.0.8"
- resolved "https://registry.yarnpkg.com/@electron/remote/-/remote-2.0.8.tgz#85ff321f0490222993207106e2f720273bb1a5c3"
- integrity sha512-P10v3+iFCIvEPeYzTWWGwwHmqWnjoh8RYnbtZAb3RlQefy4guagzIwcWtfftABIfm6JJTNQf4WPSKWZOpLmHXw==
+"@electron/remote@^2.1.2":
+ version "2.1.2"
+ resolved "https://registry.yarnpkg.com/@electron/remote/-/remote-2.1.2.tgz#52a97c8faa5b769155b649ef262f2f8c851776e6"
+ integrity sha512-EPwNx+nhdrTBxyCqXt/pftoQg/ybtWDW3DUWHafejvnB1ZGGfMpv6e15D8KeempocjXe78T7WreyGGb3mlZxdA==
"@electron/universal@1.2.1":
version "1.2.1"
--
2.47.0

View file

@ -1,41 +1,179 @@
{ appimageTools, fetchurl, lib }:
{
stdenv,
fetchFromGitHub,
lib,
fetchYarnDeps,
yarn,
fixup-yarn-lock,
nodejs,
electron,
python3,
xorg,
fontconfig,
nodePackages,
ripgrep,
pkg-config,
libsecret,
yarnBuildHook,
makeShellWrapper,
unstableGitUpdater,
xcbuild,
libtool,
}:
let
stdenv.mkDerivation (finalAttrs: {
pname = "marktext";
version = "0.17.1";
version = "0.17.1-unstable-2024-06-10";
src = fetchurl {
url = "https://github.com/marktext/marktext/releases/download/v${version}/marktext-x86_64.AppImage";
sha256 = "2e2555113e37df830ba3958efcccce7020907b12fd4162368cfd906aeda630b7";
src = fetchFromGitHub {
owner = "marktext";
repo = "marktext";
rev = "cd8452979bf2441f8064968ab1f9ae28302c9d75";
hash = "sha256-6oD9Bp0XonhNHWA8JajyWdNkAXpX4GoKPpdLzpvr+jM=";
postFetch = ''
cd $out
patch -p1 < ${./0001-update-electron.patch}
''; # Need for offlineCache
};
appimageContents = appimageTools.extractType2 {
inherit pname version src;
offlineCache = fetchYarnDeps {
yarnLock = "${finalAttrs.src}/yarn.lock";
hash = "sha256-mr79FV/LHkoY3vX9B5yv95IQIJQ9akwfslKndKYmwCo=";
};
in
appimageTools.wrapType2 rec {
inherit pname version src;
profile = ''
export LC_ALL=C.UTF-8
nativeBuildInputs =
[
yarn
fixup-yarn-lock
makeShellWrapper
yarnBuildHook
(python3.withPackages (ps: with ps; [ packaging ]))
pkg-config
nodejs
nodePackages.node-gyp-build
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
xcbuild
libtool
];
buildInputs = [
libsecret
xorg.libX11
xorg.libxkbfile
fontconfig
xorg.xorgproto
];
postPatch = ''
substituteInPlace src/common/filesystem/paths.js \
--replace-fail "process.resourcesPath" "'$out/opt/marktext/resources'"
substituteInPlace src/main/cli/index.js \
--replace-fail "process.argv.slice(1)" "process.argv.slice(2)"
'';
extraPkgs = pkgs: [ pkgs.libsecret pkgs.xorg.libxkbfile ];
configurePhase = ''
runHook preConfigure
extraInstallCommands = ''
install -m 444 -D ${appimageContents}/marktext.desktop $out/share/applications/marktext.desktop
substituteInPlace $out/share/applications/marktext.desktop \
--replace "Exec=AppRun" "Exec=${pname} --"
export HOME=$(mktemp -d)
yarn config --offline set yarn-offline-mirror ${finalAttrs.offlineCache}
fixup-yarn-lock yarn.lock
cp -r ${appimageContents}/usr/share/icons $out/share
# set nodedir to prevent node-gyp from downloading headers
# taken from https://nixos.org/manual/nixpkgs/stable/#javascript-tool-specific
mkdir -p $HOME/.node-gyp/${nodejs.version}
echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
export npm_config_nodedir=${nodejs}
yarn --offline --frozen-lockfile install --ignore-scripts --no-progress --non-interactive
patchShebangs node_modules
substituteInPlace node_modules/node-gyp/gyp/pylib/gyp/input.py \
--replace-fail "from distutils.version import StrictVersion" "from packaging.version import Version as StrictVersion"
./node_modules/.bin/electron-rebuild -f
substituteInPlace package.json \
--replace-fail "electron-rebuild -f" "echo 0" \
--replace-fail "&& yarn run lint:fix" ""
mkdir -p node_modules/vscode-ripgrep/bin
yarn --offline --frozen-lockfile install --no-progress
patchShebangs node_modules
substituteInPlace node_modules/node-gyp/gyp/pylib/gyp/input.py \
--replace-fail "from distutils.version import StrictVersion" "from packaging.version import Version as StrictVersion"
sed -i -e 's|path.join(.*);|"${lib.getExe ripgrep}";|' \
node_modules/vscode-ripgrep/lib/index.js
runHook postConfigure
'';
meta = with lib; {
yarnBuildScript = "electron-builder";
yarnBuildFlags = [
"--dir"
"-c.electronDist=${electron.dist}"
"-c.electronVersion=${electron.version}"
];
env = {
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1";
};
preBuild = ''
node .electron-vue/build.js
''; # From package.json
installPhase = ''
runHook preInstall
mkdir -p $out/opt/marktext $out/bin
install -Dm644 resources/linux/marktext.desktop $out/share/application/marktext.desktop
pushd resources/icons/
find -maxdepth 1 -mindepth 1 -type d -exec install -DT {}/marktext.png $out/share/icons/hicolor/{}/apps/marktext.png \;
find -maxdepth 1 -mindepth 1 -type d -exec install -DT {}/md.png $out/share/icons/hicolor/{}/apps/md.png \;
popd
cp -r build/*-unpacked/{locales,resources{,.pak}} $out/opt/marktext
makeWrapper ${lib.getExe electron} $out/bin/marktext \
--add-flags $out/opt/marktext/resources/app.asar \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}"
runHook postInstall
'';
passthru.updateScript = unstableGitUpdater {
tagPrefix = "v";
branch = "develop";
};
meta = {
description = "Simple and elegant markdown editor, available for Linux, macOS and Windows";
homepage = "https://www.marktext.cc";
license = licenses.mit;
maintainers = with maintainers; [ nh2 eduarrrd ];
platforms = [ "x86_64-linux" ];
license = lib.licenses.mit;
maintainers = with lib.maintainers; [
nh2
eduarrrd
bot-wxt1221
];
badPlatforms = [
"x86_64-darwin"
"aarch64-darwin"
];
platforms = lib.platforms.unix;
mainProgram = "marktext";
};
}
})