From 3646dbaaa7e0ecb4d3ebb9427eb1585df14dee53 Mon Sep 17 00:00:00 2001 From: Ethan Reece Date: Wed, 9 Jul 2025 23:36:53 -0500 Subject: [PATCH] Improve dictionary handling for en-us --- .envrc | 2 + .gitignore | 1 + .../config/vocabularies/General/accept.txt | 4 -- README.md | 2 +- flake.nix | 38 +++++++++++------- languages/en-us.nix | 39 ++++++++++++++++--- 6 files changed, 63 insertions(+), 23 deletions(-) delete mode 100644 .vale/styles/config/vocabularies/General/accept.txt diff --git a/.envrc b/.envrc index 3550a30..32c5313 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,3 @@ use flake +watch_file ./home +watch_file ./languages diff --git a/.gitignore b/.gitignore index 3277e29..1c85e47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .direnv .helix +.vale/styles/config/vocabularies/General diff --git a/.vale/styles/config/vocabularies/General/accept.txt b/.vale/styles/config/vocabularies/General/accept.txt deleted file mode 100644 index 9b1efeb..0000000 --- a/.vale/styles/config/vocabularies/General/accept.txt +++ /dev/null @@ -1,4 +0,0 @@ -Asahi -NixOS -LLMs -LTeX diff --git a/README.md b/README.md index 7448c0a..7f269b1 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ This repository has the Nix home-manager configuration for my laptop, allowing m - **`treefmt`** (with Helix integration) - Automatically formats this repository when modifying it, with features to check the flake for formatting consistency - **Language Server Protocol (LSP)** - Has language servers for file formats used in this repository; integrates with Helix text editor and fully managed by Nix with each language's configuration in its own file - **AI** - Uses Nix home-manager integrations for Codex and `aichat` for querying Large Language Models (LLMs) in the CLI and in Git repositories -- **Language tools** - Checks for grammatical and styling issues using Vale, Harper, LTeX, and Typos +- **Language tools** - Checks for grammatical and styling issues using Vale, Harper, LTeX, and Typos, centralizing the custom dictionary for these tools in the Nix configuration diff --git a/flake.nix b/flake.nix index 45ed0cb..6924f40 100644 --- a/flake.nix +++ b/flake.nix @@ -41,6 +41,7 @@ # ./home/flake-module.nix ]; flake = { + # https://nix-community.github.io/home-manager/options.xhtml homeConfigurations = { asahi = withSystem "aarch64-linux" ( { pkgs, ... }: @@ -82,21 +83,27 @@ }; treefmtPrograms = builtins.foldl' (acc: cfg: acc // (cfg.treefmt.programs or { })) { } configs; preCommitHooks = builtins.foldl' (acc: cfg: acc // (cfg.pre-commit or { })) { } configs; - devshellCommands = builtins.concatMap (cfg: cfg.devshell.commands) ( - (builtins.filter (cfg: builtins.hasAttr "commands" cfg.devshell) ( - builtins.filter (cfg: builtins.hasAttr "devshell" cfg) configs - )) - ); - devshellPackages = builtins.concatMap (cfg: cfg.devshell.packages) ( - (builtins.filter (cfg: builtins.hasAttr "packages" cfg.devshell) ( - builtins.filter (cfg: builtins.hasAttr "devshell" cfg) configs - )) - ); + devshellConfigs = { + commands = builtins.concatMap (cfg: cfg.devshell.commands) ( + (builtins.filter (cfg: builtins.hasAttr "commands" cfg.devshell) ( + builtins.filter (cfg: builtins.hasAttr "devshell" cfg) configs + )) + ); + packages = builtins.concatMap (cfg: cfg.devshell.packages) ( + (builtins.filter (cfg: builtins.hasAttr "packages" cfg.devshell) ( + builtins.filter (cfg: builtins.hasAttr "devshell" cfg) configs + )) + ); + devshellStartup = builtins.foldl' ( + acc: cfg: acc // (cfg.devshell.devshellStartup or { }) + ) { } configs; + }; helixLanguagesFormat = pkgs.formats.toml { }; helixLanguagesFile = helixLanguagesFormat.generate "languages.toml" helixLanguages; in { _module.args.pkgs = pkgs; + # https://flake.parts/options/devshell.html devshells.default = { commands = [ { @@ -134,7 +141,7 @@ name = "sops-edit"; command = "${pkgs.sops}/bin/sops edit ./home/secrets/secrets.yaml"; } - ] ++ devshellCommands; + ] ++ devshellConfigs.commands; packages = [ pkgs.age pkgs.forgejo-cli @@ -146,14 +153,17 @@ pkgs.man pkgs.sops pkgs.uutils-coreutils-noprefix - ] ++ devshellPackages; + ] ++ devshellConfigs.packages; devshell = { motd = '' {202}🔨 Nix Laptop Configuration{reset} $(type -p menu &>/dev/null && menu) ''; name = "Laptop Configuration"; - startup = { + startup = devshellConfigs.devshellStartup // { + # https://github.com/helix-editor/helix/blob/master/languages.toml + # https://helix-editor.vercel.app/reference/formatters + # https://docs.helix-editor.com/lang-support.html helix_config = { text = '' mkdir -p .helix @@ -163,9 +173,11 @@ }; }; }; + # https://flake.parts/options/git-hooks-nix.html pre-commit.settings = { hooks = preCommitHooks; }; + # https://flake.parts/options/treefmt-nix.html treefmt = { projectRootFile = "flake.nix"; programs = treefmtPrograms; diff --git a/languages/en-us.nix b/languages/en-us.nix index b1af32c..c89753d 100644 --- a/languages/en-us.nix +++ b/languages/en-us.nix @@ -1,19 +1,42 @@ { pkgs, treefmt }: +let + dictionary = [ + "Asahi" + "LLMs" + "LTeX" + "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; + }; + typosConfig = { + default.extendWords = + # dictionary: + builtins.listToAttrs ( + builtins.map (x: { + name = x; + value = x; + }) dictionary + ); + }; + typosConfigFile = tomlFormatter.generate "_typos.toml" typosConfig; +in { helix.language-server = { ltex-ls-plus = { command = "${pkgs.ltex-ls-plus}/bin/ltex-ls-plus"; - config.ltex.dictionary.en-US = [ - "Asahi" - "LLMs" - "LTeX" - ]; + config.ltex.dictionary.en-US = dictionary; }; vale-ls.command = "${pkgs.vale-ls}/bin/vale-ls"; }; treefmt.programs.typos = { enable = true; locale = "en-us"; + configFile = typosConfigFile.outPath; }; devshell = { commands = [ @@ -24,5 +47,11 @@ } ]; packages = [ pkgs.vale ]; + devshellStartup = { + vale_config.text = '' + mkdir -p ${valeDictionary.directory} + ${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${valeDictionary.file} ${valeDictionary.directory}/${valeDictionary.filename} + ''; + }; }; }