diff --git a/pkgs/by-name/ma/marktext/0001-update-electron.patch b/pkgs/by-name/ma/marktext/0001-update-electron.patch new file mode 100644 index 0000000000000..1b769546ca42b --- /dev/null +++ b/pkgs/by-name/ma/marktext/0001-update-electron.patch @@ -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 + diff --git a/pkgs/by-name/ma/marktext/package.nix b/pkgs/by-name/ma/marktext/package.nix index a5bcdd7c8c533..2ed8490c52927 100644 --- a/pkgs/by-name/ma/marktext/package.nix +++ b/pkgs/by-name/ma/marktext/package.nix @@ -1,51 +1,165 @@ { - appimageTools, - fetchurl, + stdenv, + fetchFromGitHub, lib, + fetchYarnDeps, + yarn, + fixup-yarn-lock, + nodejs, + electron, + node-gyp, + python311, + xorg, + fontconfig, + nodePackages, + ripgrep, + pkg-config, + libsecret, + karma-runner, + yarnBuildHook, + makeShellWrapper, + unstableGitUpdater, + commandLineArgs ? "", }: -let +stdenv.mkDerivation (finalAttrs: { pname = "marktext"; - version = "0.17.1"; + version = "0.17.0-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 + env = { + NIX_CFLAGS_COMPILE = toString [ + "-I${lib.getDev xorg.libX11}/include" + "-I${lib.getDev xorg.libxkbfile}/include" + "-I${lib.getDev libsecret}/include" + "-I${lib.getDev fontconfig}/include" + "-I${lib.getDev xorg.xorgproto}/include" + ]; + NIX_CFLAGS_LINK = toString [ + "-L${lib.getLib xorg.libX11}/lib" + "-L${lib.getLib xorg.libxkbfile}/lib" + "-L${lib.getLib libsecret}/lib" + "-L${lib.getLib fontconfig}/lib" + "-L${lib.getLib xorg.xorgproto}/lib" + ]; + }; + + nativeBuildInputs = [ + yarn + fixup-yarn-lock + makeShellWrapper + yarnBuildHook + python311 + pkg-config + nodejs + nodePackages.node-gyp-build + ]; + + buildInputs = [ + libsecret + xorg.libX11 + xorg.libxkbfile + ]; + + postPatch = '' + substituteInPlace src/common/filesystem/paths.js \ + --replace-fail "process.resourcesPath" "'$out/opt/marktext/resources'" + ''; + + 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} + + mkdir -p node_modules/vscode-ripgrep/bin + ln -sf ${lib.getExe ripgrep} node_modules/vscode-ripgrep/bin/rg + + 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" "" + + yarn --offline --frozen-lockfile install --no-progress + patchShebangs node_modules + + runHook postConfigure ''; - extraPkgs = pkgs: [ - pkgs.libsecret - pkgs.xorg.libxkbfile + 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"; + }; - cp -r ${appimageContents}/usr/share/icons $out/share + preBuild = '' + node .electron-vue/build.js + ''; # From package.json + + 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"; }; -} +})