Skip to content

Commit

Permalink
marktext: build from source
Browse files Browse the repository at this point in the history
  • Loading branch information
Bot-wxt1221 committed Nov 8, 2024
1 parent d0a1177 commit 17876a7
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 27 deletions.
45 changes: 45 additions & 0 deletions pkgs/by-name/ma/marktext/0001-update-electron.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From d9ee8be58200be1bcf1cf16dda44de811a9e4660 Mon Sep 17 00:00:00 2001
From: wxt <[email protected]>
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/[email protected]":
version "1.2.1"
--
2.47.0

156 changes: 129 additions & 27 deletions pkgs/by-name/ma/marktext/package.nix
Original file line number Diff line number Diff line change
@@ -1,51 +1,153 @@
{
appimageTools,
fetchurl,
stdenv,
fetchFromGitHub,
lib,
fetchYarnDeps,
yarn,
fixup-yarn-lock,
nodejs,
electron,
python311,
xorg,
fontconfig,
nodePackages,
ripgrep,
pkg-config,
libsecret,
yarnBuildHook,
makeShellWrapper,
unstableGitUpdater,
commandLineArgs ? "",
}:

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
python311
pkg-config
nodejs
nodePackages.node-gyp-build
];

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
export HOME=$(mktemp -d)
yarn config --offline set yarn-offline-mirror ${finalAttrs.offlineCache}
fixup-yarn-lock yarn.lock
# 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
./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
sed -i -e 's|path.join(.*);|"${lib.getExe ripgrep}";|' \
node_modules/vscode-ripgrep/lib/index.js
runHook postConfigure
'';

yarnBuildScript = "electron-builder";

yarnBuildFlags = [
"--dir"
"-c.electronDist=${electron.dist}"
"-c.electronVersion=${electron.version}"
];

extraInstallCommands = ''
install -m 444 -D ${appimageContents}/marktext.desktop $out/share/applications/marktext.desktop
substituteInPlace $out/share/applications/marktext.desktop \
--replace "Exec=AppRun" "Exec=${pname} --"
env = {
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1";
};

preBuild = ''
node .electron-vue/build.js
''; # From package.json

cp -r ${appimageContents}/usr/share/icons $out/share
installPhase = ''
runHook preInstall
mkdir -p $out/opt/marktext $out/bin
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 ${lib.escapeShellArg commandLineArgs} \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}"
runHook postInstall
'';

meta = with lib; {
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; [
license = lib.licenses.mit;
maintainers = with lib.maintainers; [
nh2
eduarrrd
bot-wxt1221
];
platforms = [ "x86_64-linux" ];
platforms = lib.platforms.unix;
mainProgram = "marktext";
};
}
})

0 comments on commit 17876a7

Please sign in to comment.