Unverified Commit b21becc7 authored by github-actions[bot]'s avatar github-actions[bot] Committed by GitHub
Browse files

Merge master into staging-next

parents c0c48b0c 0b00177a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2,11 +2,11 @@

let
  pname = "ledger-live-desktop";
  version = "2.58.0";
  version = "2.60.0";

  src = fetchurl {
    url = "https://download.live.ledger.com/${pname}-${version}-linux-x86_64.AppImage";
    hash = "sha256-y9D+RKAB/woYmnu8X0armsVaxu0CWbqZpRiEFcN7rYM=";
    hash = "sha256-dR6F6elUxZW3EuH71d5P9SOSDq5f5lAsYnrfWrsj2KA=";
  };

  appimageContents = appimageTools.extractType2 {
+13 −24
Original line number Diff line number Diff line
{ fetchFromGitHub, lib, rustPlatform, installShellFiles, makeWrapper, callPackage }:
{ fetchzip, lib, rustPlatform, git, installShellFiles, makeWrapper }:

let
rustPlatform.buildRustPackage rec {
  pname = "helix";
  version = "23.05";

  src = fetchFromGitHub {
    owner = "helix-editor";
    repo = "helix";
    rev = "${version}";
    hash = "sha256-Ws9uWtZLvTwL5HNonFr4YwyPoTU8QlCvhs6IJ92aLDw=";
  };

  grammars = callPackage ./grammars.nix { };
in rustPlatform.buildRustPackage {
  inherit src version;

  pname = "helix";
  # This release tarball includes source code for the tree-sitter grammars,
  # which is not ordinarily part of the repository.
  cargoSha256 = "sha256-/LCtfyDAA2JuioBD/CDMv6OOxM0B9A3PpuVP/YY5oF0=";
  src = fetchzip {
    url = "https://github.com/helix-editor/helix/releases/download/${version}/helix-${version}-source.tar.xz";
    hash = "sha256-3ZEToXwW569P7IFLqz6Un8rClnWrW5RiYKmRVFt7My8=";
    stripRoot = false;
  };

  cargoHash = "sha256-/LCtfyDAA2JuioBD/CDMv6OOxM0B9A3PpuVP/YY5oF0=";

  nativeBuildInputs = [ installShellFiles makeWrapper ];
  nativeBuildInputs = [ git installShellFiles makeWrapper ];

  postInstall = ''
    # We self build the grammar files
    rm -r runtime/grammars
    # not needed at runtime
    rm -r runtime/grammars/sources

    mkdir -p $out/lib
    cp -r runtime $out/lib
    ln -s ${grammars} $out/lib/runtime/grammars
    installShellCompletion contrib/completion/hx.{bash,fish,zsh}
    mkdir -p $out/share/{applications,icons/hicolor/256x256/apps}
    cp contrib/Helix.desktop $out/share/applications
@@ -37,11 +31,6 @@ in rustPlatform.buildRustPackage {
    wrapProgram $out/bin/hx --set HELIX_RUNTIME $out/lib/runtime
  '';

  # disable fetching and building of tree-sitter grammars in favor of the custom build process in ./grammars.nix
  env.HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";

  passthru.updateScript = ./update.py;

  meta = with lib; {
    description = "A post-modern modal text editor";
    homepage = "https://helix-editor.com";
+0 −106
Original line number Diff line number Diff line
{
  stdenv,
  lib,
  runCommand,
  includeGrammarIf ? _: true,
  fetchFromGitHub,
  fetchgit,
  ...
}: let
  # similiar to https://github.com/helix-editor/helix/blob/23.05/grammars.nix
  grammars = builtins.fromJSON (builtins.readFile ./language-grammars.json);
  isGitGrammar = grammar:
    builtins.hasAttr "source" grammar
    && builtins.hasAttr "git" grammar.source
    && builtins.hasAttr "rev" grammar.source;
  isGitHubGrammar = grammar: lib.hasPrefix "https://github.com" grammar.source.git;
  toGitHubFetcher = url: let
    match = builtins.match "https://github\.com/([^/]*)/([^/]*)/?" url;
  in {
    owner = builtins.elemAt match 0;
    repo = builtins.elemAt match 1;
  };
  gitGrammars = builtins.filter isGitGrammar grammars;
  buildGrammar = grammar: let
    gh = toGitHubFetcher grammar.source.git;
    sourceGit = fetchgit {
      url = grammar.source.git;
      inherit (grammar.source) rev sha256;
    };
    sourceGitHub = fetchFromGitHub {
      owner = gh.owner;
      repo = gh.repo;
      inherit (grammar.source) rev sha256;
    };
    source =
      if isGitHubGrammar grammar
      then sourceGitHub
      else sourceGit;
  in
    stdenv.mkDerivation rec {
      # similar to tree-sitter grammar generation
      pname = "helix-tree-sitter-grammar-${grammar.name}";
      version = grammar.source.rev;

      src =
        if builtins.hasAttr "subpath" grammar.source
        then "${source}/${grammar.source.subpath}"
        else source;

      dontConfigure = true;

      FLAGS = [
        "-I${src}/src"
        "-g"
        "-O3"
        "-fPIC"
        "-fno-exceptions"
        "-Wl,-z,relro,-z,now"
      ];

      NAME = grammar.name;

      buildPhase = ''
        runHook preBuild

        if [[ -e "src/scanner.cc" ]]; then
          $CXX -c "src/scanner.cc" -o scanner.o $FLAGS
        elif [[ -e "src/scanner.c" ]]; then
          $CC -c "src/scanner.c" -o scanner.o $FLAGS
        fi

        $CC -c "src/parser.c" -o parser.o $FLAGS
        $CXX -shared -o $NAME.so *.o

        runHook postBuild
      '';

      installPhase = ''
        runHook preInstall
        mkdir $out
        mv $NAME.so $out/
        runHook postInstall
      '';

      # Strip failed on darwin: strip: error: symbols referenced by indirect symbol table entries that can't be stripped
      fixupPhase = lib.optionalString stdenv.isLinux ''
        runHook preFixup
        $STRIP $out/$NAME.so
        runHook postFixup
      '';
    };
  grammarsToBuild = builtins.filter includeGrammarIf gitGrammars;
  builtGrammars =
    builtins.map (grammar: {
      inherit (grammar) name;
      artifact = buildGrammar grammar;
    })
    grammarsToBuild;
  grammarLinks =
    builtins.map (grammar: "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so")
    builtGrammars;
in
  runCommand "helix-tree-sitter-grammars" {} ''
    mkdir -p $out
    ${builtins.concatStringsSep "\n" grammarLinks}
  ''
+0 −1

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −47
Original line number Diff line number Diff line
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p nix-update python3 python3Packages.requests python3.pkgs.tomlkit nix-prefetch-git
import tomlkit
import json
import requests
import subprocess
from pathlib import Path

latest_release_url = "https://api.github.com/repos/helix-editor/helix/releases/latest"


def get_latest_release():
    res = requests.get(latest_release_url)
    res.raise_for_status()
    return res.json()["tag_name"]


def get_grammar_config():
    res = requests.get(f"https://raw.githubusercontent.com/helix-editor/helix/{version}/languages.toml")
    res.raise_for_status()
    return tomlkit.parse(res.text)["grammar"]


def calculate_sha256(url, rev):
    out = subprocess.check_output([
        "nix-prefetch-git", "--quiet",
        "--url", url,
        "--rev", rev])
    return json.loads(out)["sha256"]


version = get_latest_release()
grammars = get_grammar_config()
for grammar in grammars:
    if grammar["source"].get("git") is not None:
        grammar["source"]["sha256"] = calculate_sha256(
            grammar["source"]["git"], grammar["source"]["rev"])

json_grammars = json.dumps(grammars)

with open(Path(__file__).parent / "language-grammars.json", "w") as file:
    file.write(json_grammars + "\n")

subprocess.run([
    "nix-update", "helix",
    "--version", version,
])
Loading