From 2c6124b0f85e8c7d13754fe0f9421c173f1c6697 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Sun, 14 Jan 2024 15:11:40 +0100 Subject: [PATCH] Make nix flake respect unused grammars (#9326) * Make nix flake respect unused grammars * Use default value * Refactor * Take use-grammars.only into account --------- Co-authored-by: Sebastian Zivota --- grammars.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/grammars.nix b/grammars.nix index 9ca0cf3d63fd..2fef6be3a474 100644 --- a/grammars.nix +++ b/grammars.nix @@ -27,7 +27,17 @@ owner = builtins.elemAt match 0; repo = builtins.elemAt match 1; }; - gitGrammars = builtins.filter isGitGrammar languagesConfig.grammar; + # If `use-grammars.only` is set, use only those grammars. + # If `use-grammars.except` is set, use all other grammars. + # Otherwise use all grammars. + useGrammar = grammar: + if languagesConfig?use-grammars.only then + builtins.elem grammar.name languagesConfig.use-grammars.only + else if languagesConfig?use-grammars.except then + !(builtins.elem grammar.name languagesConfig.use-grammars.except) + else true; + grammarsToUse = builtins.filter useGrammar languagesConfig.grammar; + gitGrammars = builtins.filter isGitGrammar grammarsToUse; buildGrammar = grammar: let gh = toGitHubFetcher grammar.source.git; sourceGit = builtins.fetchTree {