aboutsummaryrefslogtreecommitdiff
path: root/grammars.nix
diff options
context:
space:
mode:
authorYusuf Bera Ertan2022-06-06 19:24:52 +0000
committerGitHub2022-06-06 19:24:52 +0000
commitbb83ea83938b7098cc1c1823c791d3b05dd5399f (patch)
treec084d46a8d7e8951ceed0f763f8b7deb29144cf3 /grammars.nix
parentf0d1c855539cfeb8e66c3602a971857f8c20be0f (diff)
chore(nix): format nix files with alejandra, update deps, minor code refactors (#2683)
Diffstat (limited to 'grammars.nix')
-rw-r--r--grammars.nix96
1 files changed, 54 insertions, 42 deletions
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}
+ ''