diff --git a/.envrc b/.envrc index fee6256..30453fb 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,4 @@ watch_file ./home watch_file ./languages +watch_file ./.vale/styles use flake diff --git a/.gitignore b/.gitignore index 93edd5c..3336057 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .direnv .helix .pre-commit-config.yaml -.vale/styles/config/vocabularies/General/ +.vale/.vale.ini diff --git a/flake.nix b/flake.nix index aa7cc17..1e1dbe2 100644 --- a/flake.nix +++ b/flake.nix @@ -77,6 +77,7 @@ else rValue ) rhs); + tomlFormatter = pkgs.formats.toml { }; pkgs = import inputs.nixpkgs { inherit system; overlays = [ @@ -116,8 +117,7 @@ acc: cfg: acc // (cfg.devshell.devshellStartup or { }) ) { } configs; }; - helixLanguagesFormat = pkgs.formats.toml { }; - helixLanguagesFile = helixLanguagesFormat.generate "languages.toml" helixLanguages; + helixLanguagesFile = tomlFormatter.generate "languages.toml" helixLanguages; in { _module.args.pkgs = pkgs; diff --git a/languages/en-us.nix b/languages/en-us.nix index e65c436..8534e5a 100644 --- a/languages/en-us.nix +++ b/languages/en-us.nix @@ -7,21 +7,60 @@ let "NixOS" ]; tomlFormatter = pkgs.formats.toml { }; - valeDictionary = { - directory = "./.vale/styles/config/vocabularies/General"; - filename = "accept.txt"; - content = builtins.concatStringsSep "\n" dictionary; - file = builtins.toFile valeDictionary.filename valeDictionary.content; + vale = { + valeDirectory = ".vale"; + stylesDirectory = "styles"; + dictionary = { + directory = "config/vocabularies/General"; + filename = "accept.txt"; + content = builtins.concatStringsSep "\n" dictionary; + file = pkgs.writeTextFile { + name = vale.dictionary.filename; + text = vale.dictionary.content; + }; + }; + config = { + filename = ".vale.ini"; + content = '' + StylesPath = styles + + MinAlertLevel = suggestion + + Vocab = General + + # https://vale.sh/explorer + Packages = RedHat, proselint, write-good, alex + + [*.{md}] + BasedOnStyles = Vale, RedHat, proselint, write-good, alex + ''; + file = pkgs.writeTextFile { + name = vale.config.filename; + text = vale.config.content; + }; + }; + directory = { + base = ../.vale/styles; + full = pkgs.runCommand vale.valeDirectory { } '' + ${pkgs.uutils-coreutils-noprefix}/bin/mkdir -p $out/${vale.stylesDirectory}/${vale.dictionary.directory} + ${pkgs.uutils-coreutils-noprefix}/bin/cp -r ${vale.directory.base}/* $out/${vale.stylesDirectory} + ${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${vale.dictionary.file} $out/${vale.stylesDirectory}/${vale.dictionary.directory}/${vale.dictionary.filename} + ${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${vale.config.file} $out/${vale.config.filename}; + ''; + configFile = "${vale.directory.full}/${vale.config.filename}"; + }; }; - typosConfig = { - default.extendWords = builtins.listToAttrs ( - builtins.map (x: { - name = x; - value = x; - }) dictionary - ); + typos = { + content = { + default.extendWords = builtins.listToAttrs ( + builtins.map (x: { + name = x; + value = x; + }) dictionary + ); + }; + file = tomlFormatter.generate "typos.toml" typos.content; }; - typosConfigFile = tomlFormatter.generate "typos.toml" typosConfig; in { helix.language-server = { @@ -31,27 +70,33 @@ in config.ltex.dictionary.en-US = dictionary; }; # https://vale.sh/docs/formats/code - vale-ls.command = "${pkgs.vale-ls}/bin/vale-ls"; + vale-ls = { + command = "${pkgs.vale-ls}/bin/vale-ls"; + config.configPath = vale.directory.configFile; + }; # https://writewithharper.com/docs/integrations/language-server#Supported-Languages harper-ls.command = "${pkgs.harper}/bin/harper-ls"; typos = { command = "${pkgs.typos-lsp}/bin/typos-lsp"; - config.config = typosConfigFile.outPath; + config.config = typos.file.outPath; }; }; pre-commit = { typos = { enable = true; settings = { - configPath = typosConfigFile.outPath; + configPath = typos.file.outPath; locale = "en-us"; }; }; - vale.enable = true; + vale = { + enable = true; + config.configPath = vale.directory.configFile; + }; }; treefmt.programs.typos = { enable = true; - configFile = typosConfigFile.outPath; + configFile = typos.file.outPath; locale = "en-us"; }; devshell = { @@ -59,14 +104,13 @@ in { help = "sync vale configuration"; name = "vale-sync"; - command = "${pkgs.vale}/bin/vale sync"; + command = "${pkgs.vale}/bin/vale sync --config ${vale.valeDirectory}/${vale.config.filename}"; } ]; packages = [ pkgs.vale ]; devshellStartup = { vale_config.text = '' - mkdir -p ${valeDictionary.directory} - ${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${valeDictionary.file} ${valeDictionary.directory}/${valeDictionary.filename} + ${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${vale.config.file} ${vale.valeDirectory}/${vale.config.filename} ''; }; };