From bb83ea83938b7098cc1c1823c791d3b05dd5399f Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Mon, 6 Jun 2022 22:24:52 +0300 Subject: chore(nix): format nix files with alejandra, update deps, minor code refactors (#2683) --- grammars.nix | 96 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 42 deletions(-) (limited to 'grammars.nix') diff --git a/grammars.nix b/grammars.nix index ada14aaf..2f50662e 100644 --- a/grammars.nix +++ b/grammars.nix @@ -1,17 +1,23 @@ -{ stdenv, lib, runCommand, yj }: -let +{ + stdenv, + lib, + runCommandLocal, + runCommandNoCC, + yj, +}: let # HACK: nix < 2.6 has a bug in the toml parser, so we convert to JSON # before parsing - languages-json = runCommand "languages-toml-to-json" { } '' + languages-json = runCommandLocal "languages-toml-to-json" {} '' ${yj}/bin/yj -t < ${./languages.toml} > $out ''; - languagesConfig = if lib.versionAtLeast builtins.nixVersion "2.6.0" then - builtins.fromTOML (builtins.readFile ./languages.toml) - else - builtins.fromJSON (builtins.readFile (builtins.toPath languages-json)); - isGitGrammar = (grammar: - builtins.hasAttr "source" grammar && builtins.hasAttr "git" grammar.source - && builtins.hasAttr "rev" grammar.source); + languagesConfig = + if lib.versionAtLeast builtins.nixVersion "2.6.0" + then builtins.fromTOML (builtins.readFile ./languages.toml) + else builtins.fromJSON (builtins.readFile (builtins.toPath languages-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; @@ -20,33 +26,36 @@ let repo = builtins.elemAt match 1; }; gitGrammars = builtins.filter isGitGrammar languagesConfig.grammar; - buildGrammar = grammar: - let - gh = toGitHubFetcher grammar.source.git; - sourceGit = builtins.fetchTree { - type = "git"; - url = grammar.source.git; - rev = grammar.source.rev; - ref = grammar.source.ref or "HEAD"; - shallow = true; - }; - sourceGitHub = builtins.fetchTree { - type = "github"; - owner = gh.owner; - repo = gh.repo; - inherit (grammar.source) rev; - }; - source = if isGitHubGrammar grammar then sourceGitHub else sourceGit; - in stdenv.mkDerivation rec { + buildGrammar = grammar: let + gh = toGitHubFetcher grammar.source.git; + sourceGit = builtins.fetchTree { + type = "git"; + url = grammar.source.git; + rev = grammar.source.rev; + ref = grammar.source.ref or "HEAD"; + shallow = true; + }; + sourceGitHub = builtins.fetchTree { + type = "github"; + owner = gh.owner; + repo = gh.repo; + inherit (grammar.source) rev; + }; + source = + if isGitHubGrammar grammar + then sourceGitHub + else sourceGit; + in + stdenv.mkDerivation rec { # see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix pname = "helix-tree-sitter-${grammar.name}"; version = grammar.source.rev; - src = if builtins.hasAttr "subpath" grammar.source then - "${source}/${grammar.source.subpath}" - else - source; + src = + if builtins.hasAttr "subpath" grammar.source + then "${source}/${grammar.source.subpath}" + else source; dontUnpack = true; dontConfigure = true; @@ -93,14 +102,17 @@ let runHook postFixup ''; }; - builtGrammars = builtins.map (grammar: { - inherit (grammar) name; - artifact = buildGrammar grammar; - }) gitGrammars; - grammarLinks = builtins.map (grammar: - "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so") + builtGrammars = + builtins.map (grammar: { + inherit (grammar) name; + artifact = buildGrammar grammar; + }) + gitGrammars; + grammarLinks = + builtins.map (grammar: "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so") builtGrammars; -in runCommand "consolidated-helix-grammars" { } '' - mkdir -p $out - ${builtins.concatStringsSep "\n" grammarLinks} -'' +in + runCommandNoCC "consolidated-helix-grammars" {} '' + mkdir -p $out + ${builtins.concatStringsSep "\n" grammarLinks} + '' -- cgit v1.2.3-70-g09d2