diff --git a/pkgs/by-name/ev/evil-helix/package.nix b/pkgs/by-name/ev/evil-helix/package.nix index 1a4f783bc4d4..176480be9723 100644 --- a/pkgs/by-name/ev/evil-helix/package.nix +++ b/pkgs/by-name/ev/evil-helix/package.nix @@ -5,44 +5,58 @@ installShellFiles, nix-update-script, rustPlatform, + runCommand, + makeBinaryWrapper, }: -rustPlatform.buildRustPackage (finalAttrs: { - pname = "evil-helix"; - version = "20250915"; +rustPlatform.buildRustPackage ( + finalAttrs: + let + defaultRuntimeDir = runCommand "evil-helix-default-runtime" { } '' + cp -r --no-preserve=mode ${finalAttrs.src}/runtime $out + rm -rf $out/grammars $out/queries + ''; + in + { + pname = "evil-helix"; + version = "20250915"; - src = fetchFromGitHub { - owner = "usagi-flow"; - repo = "evil-helix"; - tag = "release-${finalAttrs.version}"; - hash = "sha256-6kqKTZNS1RZwfxcFoa2uC7fUKcQ+KhT5KXusyCt59YQ="; - }; + src = fetchFromGitHub { + owner = "usagi-flow"; + repo = "evil-helix"; + tag = "release-${finalAttrs.version}"; + hash = "sha256-6kqKTZNS1RZwfxcFoa2uC7fUKcQ+KhT5KXusyCt59YQ="; + }; - cargoHash = "sha256-Mf0nrgMk1MlZkSyUN6mlM5lmTcrOHn3xBNzmVGtApEU="; + cargoHash = "sha256-Mf0nrgMk1MlZkSyUN6mlM5lmTcrOHn3xBNzmVGtApEU="; - nativeBuildInputs = [ installShellFiles ]; + nativeBuildInputs = [ + installShellFiles + makeBinaryWrapper + ]; - env = { - # disable fetching and building of tree-sitter grammars in the helix-term build.rs - HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1"; - HELIX_DEFAULT_RUNTIME = helix.runtime; - }; + env = { + # disable fetching and building of tree-sitter grammars in the helix-term build.rs + HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1"; + HELIX_DEFAULT_RUNTIME = defaultRuntimeDir; + }; - postInstall = '' - mkdir -p $out/lib - installShellCompletion contrib/completion/hx.{bash,fish,zsh} - mkdir -p $out/share/{applications,icons/hicolor/256x256/apps} - cp contrib/Helix.desktop $out/share/applications - cp contrib/helix.png $out/share/icons/hicolor/256x256/apps - ''; + postInstall = '' + installShellCompletion contrib/completion/hx.{bash,fish,zsh} + mkdir -p $out/share/{applications,icons/hicolor/256x256/apps} + cp contrib/Helix.desktop $out/share/applications + cp contrib/helix.png $out/share/icons/hicolor/256x256/apps + wrapProgram $out/bin/hx --set HELIX_RUNTIME ${helix.runtime} + ''; - passthru.updateScript = nix-update-script { }; + passthru.updateScript = nix-update-script { }; - meta = { - description = "Post-modern modal text editor, with vim keybindings"; - homepage = "https://github.com/usagi-flow/evil-helix"; - license = lib.licenses.mpl20; - mainProgram = "hx"; - maintainers = with lib.maintainers; [ thiagokokada ]; - }; -}) + meta = { + description = "Post-modern modal text editor, with vim keybindings"; + homepage = "https://github.com/usagi-flow/evil-helix"; + license = lib.licenses.mpl20; + mainProgram = "hx"; + maintainers = with lib.maintainers; [ thiagokokada ]; + }; + } +) diff --git a/pkgs/by-name/he/helix/mdbook-0.5-support.patch b/pkgs/by-name/he/helix-unwrapped/mdbook-0.5-support.patch similarity index 100% rename from pkgs/by-name/he/helix/mdbook-0.5-support.patch rename to pkgs/by-name/he/helix-unwrapped/mdbook-0.5-support.patch diff --git a/pkgs/by-name/he/helix-unwrapped/package.nix b/pkgs/by-name/he/helix-unwrapped/package.nix new file mode 100644 index 000000000000..5b520dc6bbfd --- /dev/null +++ b/pkgs/by-name/he/helix-unwrapped/package.nix @@ -0,0 +1,91 @@ +{ + lib, + rustPlatform, + fetchFromGitHub, + runCommand, + installShellFiles, + mdbook, + versionCheckHook, +}: + +rustPlatform.buildRustPackage ( + finalAttrs: + let + defaultRuntimeDir = runCommand "helix-default-runtime" { } '' + cp -r --no-preserve=mode ${finalAttrs.src}/runtime $out + rm -rf $out/grammars $out/queries + ''; + in + { + pname = "helix-unwrapped"; + version = "25.07.1"; + + outputs = [ + "out" + "doc" + ]; + + src = fetchFromGitHub { + owner = "helix-editor"; + repo = "helix"; + tag = finalAttrs.version; + hash = "sha256-RFSzGAcB0mMg/02ykYfTWXzQjLFu2CJ4BkS5HZ/6pBo="; + }; + + cargoHash = "sha256-Mf0nrgMk1MlZkSyUN6mlM5lmTcrOHn3xBNzmVGtApEU="; + + patches = [ + # Support mdbook 0.5.x: escape HTML tags in command descriptions + ./mdbook-0.5-support.patch + ]; + + postPatch = '' + # mdbook 0.5 uses asset hashing for CSS/JS files + # Remove custom theme to use default mdbook theme with correct asset references + rm -f book/theme/index.hbs + ''; + + nativeBuildInputs = [ + installShellFiles + mdbook + ]; + + env = { + # disable fetching and building of tree-sitter grammars in the helix-term build.rs + HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1"; + HELIX_DEFAULT_RUNTIME = defaultRuntimeDir; + }; + + postBuild = '' + mdbook build book -d ../book-html + ''; + + postInstall = '' + installShellCompletion contrib/completion/hx.{bash,fish,zsh} + mkdir -p $out/share/{applications,icons/hicolor/256x256/apps} + cp contrib/Helix.desktop $out/share/applications/Helix.desktop + cp contrib/helix.png $out/share/icons/hicolor/256x256/apps/helix.png + mkdir -p $doc/share/doc + cp -r ../book-html $doc/share/doc/$name + ''; + + nativeInstallCheckInputs = [ + versionCheckHook + ]; + versionCheckProgram = "${placeholder "out"}/bin/hx"; + doInstallCheck = true; + + meta = { + description = "Post-modern modal text editor"; + homepage = "https://helix-editor.com"; + changelog = "https://github.com/helix-editor/helix/blob/${finalAttrs.version}/CHANGELOG.md"; + license = lib.licenses.mpl20; + mainProgram = "hx"; + maintainers = with lib.maintainers; [ + aciceri + danth + yusdacra + ]; + }; + } +) diff --git a/pkgs/by-name/he/helix/package.nix b/pkgs/by-name/he/helix/package.nix index b66ba8dfa721..60dc5ecf6d66 100644 --- a/pkgs/by-name/he/helix/package.nix +++ b/pkgs/by-name/he/helix/package.nix @@ -1,12 +1,9 @@ { - fetchFromGitHub, lib, - rustPlatform, - mdbook, - gitMinimal, - installShellFiles, - versionCheckHook, + symlinkJoin, runCommand, + makeBinaryWrapper, + helix-unwrapped, removeReferencesTo, pkgs, tree-sitter, @@ -22,133 +19,81 @@ } ), }: +let + lockedVersionsOverlay = + final: prev: + lib.mapAttrs ( + drvName: grammar: + let + lockedGrammar = lockedGrammars.${lib.removePrefix "tree-sitter-" drvName}; + in + (prev.${drvName}.override { + location = lockedGrammar.subpath; + }).overrideAttrs + { + version = lib.sources.shortRev lockedGrammar.nurl.args.rev; + src = (pkgs.${lockedGrammar.nurl.fetcher} lockedGrammar.nurl.args); + } + ) prev; -rustPlatform.buildRustPackage ( - finalAttrs: - let - lockedVersionsOverlay = - final: prev: - lib.mapAttrs ( - drvName: grammar: - let - lockedGrammar = lockedGrammars.${lib.removePrefix "tree-sitter-" drvName}; - in - (prev.${drvName}.override { - location = lockedGrammar.subpath; - }).overrideAttrs - { - version = lib.sources.shortRev lockedGrammar.nurl.args.rev; - src = (pkgs.${lockedGrammar.nurl.fetcher} lockedGrammar.nurl.args); - } - ) prev; + tree-sitter-grammars = + lib.filterAttrs (drvName: _: lib.hasAttr (lib.removePrefix "tree-sitter-" drvName) lockedGrammars) + ( + tree-sitter.grammarsScope.overrideScope ( + lib.composeExtensions lockedVersionsOverlay grammarsOverlay + ) + ); - tree-sitter-grammars = - lib.filterAttrs (drvName: _: lib.hasAttr (lib.removePrefix "tree-sitter-" drvName) lockedGrammars) - ( - tree-sitter.grammarsScope.overrideScope ( - lib.composeExtensions lockedVersionsOverlay grammarsOverlay - ) - ); + # Dynamic libraries for the grammars always use the `.so` extension, also on Darwin (should use `.dylib`) + # See here: https://github.com/helix-editor/helix/pull/14982 + # Switch to `stdenv.hostPlatform.extensions.sharedLibrary` once the fix above reaches the next release - # Dynamic libraries for the grammars always use the `.so` extension, also on Darwin (should use `.dylib`) - # See here: https://github.com/helix-editor/helix/pull/14982 - # Switch to `stdenv.hostPlatform.extensions.sharedLibrary` once the fix above reaches the next release + grammarsFarm = runCommand "helix-grammars" { } ( + lib.concatMapAttrsStringSep "\n" (_: grammar: '' + install -D ${grammar}/parser $out/${grammar.language}.so + ${lib.getExe removeReferencesTo} -t ${grammar} $out/${grammar.language}.so + '') (lib.filterAttrs (_: lib.isDerivation) tree-sitter-grammars) + ); - grammarsFarm = runCommand "helix-grammars" { } ( - lib.concatMapAttrsStringSep "\n" (_: grammar: '' - install -D ${grammar}/parser $out/${grammar.language}.so - ${lib.getExe removeReferencesTo} -t ${grammar} $out/${grammar.language}.so - '') (lib.filterAttrs (_: lib.isDerivation) tree-sitter-grammars) - ); + lockedGrammarsCount = lib.length (lib.attrNames lockedGrammars); - lockedGrammarsCount = lib.length (lib.attrNames lockedGrammars); + runtimeDir = runCommand "helix-runtime" { } '' + mkdir -p $out + ln -s ${grammarsFarm} $out/grammars + cp -r --no-preserve=mode ${helix-unwrapped.src}/runtime/queries $out + count=$(ls -1 "$out/grammars/" | wc -l) + if [ "$count" -ne ${toString lockedGrammarsCount} ]; then + echo "Expected ${toString lockedGrammarsCount} grammars, found $count" + exit 1 + fi + ''; +in - runtimeDir = runCommand "helix-runtime" { } '' - cp -r --no-preserve=mode ${finalAttrs.src}/runtime $out - rm -r $out/grammars - ln -s ${grammarsFarm} $out/grammars - count=$(ls -1 "$out/grammars/" | wc -l) - if [ "$count" -ne ${toString lockedGrammarsCount} ]; then - echo "Expected ${toString lockedGrammarsCount} grammars, found $count" - exit 1 - fi - ''; - in - { - pname = "helix"; - version = "25.07.1"; - outputs = [ - "out" - "doc" - ]; +symlinkJoin { + pname = "helix"; + inherit (helix-unwrapped) version; - src = fetchFromGitHub { - owner = "helix-editor"; - repo = "helix"; - tag = "${finalAttrs.version}"; - hash = "sha256-RFSzGAcB0mMg/02ykYfTWXzQjLFu2CJ4BkS5HZ/6pBo="; - }; + paths = [ helix-unwrapped ]; + nativeBuildInputs = [ makeBinaryWrapper ]; - patches = [ - # Support mdbook 0.5.x: escape HTML tags in command descriptions - ./mdbook-0.5-support.patch - ]; + postBuild = '' + wrapProgram $out/bin/hx --set HELIX_RUNTIME "${runtimeDir}" + ''; - postPatch = '' - # mdbook 0.5 uses asset hashing for CSS/JS files - # Remove custom theme to use default mdbook theme with correct asset references - rm -f book/theme/index.hbs - ''; + passthru = { + updateScript = ./update.sh; + runtime = runtimeDir; + inherit tree-sitter-grammars; + }; - cargoHash = "sha256-Mf0nrgMk1MlZkSyUN6mlM5lmTcrOHn3xBNzmVGtApEU="; - - nativeBuildInputs = [ - gitMinimal - installShellFiles - mdbook - ]; - - env = { - HELIX_DEFAULT_RUNTIME = runtimeDir; - HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1"; - }; - - postBuild = '' - mdbook build book -d ../book-html - ''; - - postInstall = '' - mkdir -p $out/lib $doc/share/doc - installShellCompletion contrib/completion/hx.{bash,fish,zsh} - mkdir -p $out/share/{applications,icons/hicolor/256x256/apps} - cp contrib/Helix.desktop $out/share/applications/Helix.desktop - cp contrib/helix.png $out/share/icons/hicolor/256x256/apps/helix.png - cp -r ../book-html $doc/share/doc/$name - ''; - - nativeInstallCheckInputs = [ - versionCheckHook - ]; - versionCheckProgram = "${placeholder "out"}/bin/hx"; - doInstallCheck = true; - - passthru = { - updateScript = ./update.sh; - runtime = runtimeDir; - inherit tree-sitter-grammars; - }; - - meta = { - description = "Post-modern modal text editor"; - homepage = "https://helix-editor.com"; - changelog = "https://github.com/helix-editor/helix/blob/${finalAttrs.version}/CHANGELOG.md"; - license = lib.licenses.mpl20; - mainProgram = "hx"; - maintainers = with lib.maintainers; [ - aciceri - danth - yusdacra - ]; - }; - } -) + meta = { + inherit (helix-unwrapped.meta) + description + homepage + changelog + license + mainProgram + maintainers + ; + }; +} diff --git a/pkgs/by-name/he/helix/update.sh b/pkgs/by-name/he/helix/update.sh index 096374e02693..c143f5d1fde5 100755 --- a/pkgs/by-name/he/helix/update.sh +++ b/pkgs/by-name/he/helix/update.sh @@ -6,10 +6,10 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo "Updating helix source to the latest stable..." -nix-update helix +nix-update helix-unwrapped echo "Fetching updated helixSource..." -HELIX_SRC=$(nix-instantiate --eval -A "helix.src.outPath" --raw) +HELIX_SRC=$(nix-instantiate --eval -A "helix-unwrapped.src.outPath" --raw) echo "Generating grammars.json..." "$SCRIPT_DIR/generate_grammars.py" \