From 269c26da70c262754b5fd84ce160b76d5bb8f071 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Sat, 31 Oct 2026 10:53:08 -0500 Subject: [PATCH] wip: Add medical/American hunspell dict --- homes/desktop.nix | 27 ++++++++++++++++++-- pkgs/default.nix | 4 ++- pkgs/hunspell-en-med.nix | 55 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 pkgs/hunspell-en-med.nix diff --git a/homes/desktop.nix b/homes/desktop.nix index fa3d500..fad5434 100644 --- a/homes/desktop.nix +++ b/homes/desktop.nix @@ -1,4 +1,10 @@ -{ pkgs, custom-pkgs, ... }: { +{ + pkgs, + lib, + custom-pkgs, + ... +}: +{ imports = [ ./../programs/firefox.nix @@ -31,6 +37,7 @@ woodpecker-cli (texlive.combine { inherit (texlive) scheme-basic latex-bin latexmk; }) custom-pkgs.ark + custom-pkgs.hunspell-en-med custom-pkgs.jlfmt custom-pkgs.runic ]; @@ -48,5 +55,21 @@ ''; }; }; - services = { syncthing.enable = true; }; + services = { + syncthing.enable = true; + }; + + # Symlink the merged en_MED Hunspell dictionary into the user dictionary + # directory that Qt/Sonnet (and macOS native spellcheck) scan at startup. + home.file = lib.mkIf pkgs.stdenv.isDarwin { + "Library/Spelling/en_MED.dic".source = "${custom-pkgs.hunspell-en-med}/share/hunspell/en_MED.dic"; + "Library/Spelling/en_MED.aff".source = "${custom-pkgs.hunspell-en-med}/share/hunspell/en_MED.aff"; + }; + + # On Linux, Qt/Sonnet resolves QStandardPaths::GenericDataLocation + "/hunspell" + # which maps to ~/.local/share/hunspell (managed via xdg.dataFile). + xdg.dataFile = lib.mkIf pkgs.stdenv.isLinux { + "hunspell/en_MED.dic".source = "${custom-pkgs.hunspell-en-med}/share/hunspell/en_MED.dic"; + "hunspell/en_MED.aff".source = "${custom-pkgs.hunspell-en-med}/share/hunspell/en_MED.aff"; + }; } diff --git a/pkgs/default.nix b/pkgs/default.nix index 8178242..8fa7b3d 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,6 +1,8 @@ { pkgs, ... }: -with pkgs; { +with pkgs; +{ ark = callPackage ./ark.nix { }; + hunspell-en-med = callPackage ./hunspell-en-med.nix { }; jlfmt = callPackage ./jlfmt.nix { }; runic = callPackage ./runic.nix { }; sc4pac = callPackage ./sc4pac.nix { }; diff --git a/pkgs/hunspell-en-med.nix b/pkgs/hunspell-en-med.nix new file mode 100644 index 0000000..db3f182 --- /dev/null +++ b/pkgs/hunspell-en-med.nix @@ -0,0 +1,55 @@ +{ pkgs, lib }: + +let + # Hunspell dictionary of English medical terms by glutanimate. + # Merges OpenMedSpel (R. Robinson) and MTH-Med-Spel-Chek (Rajasekharan N.), + # covering ~90,000 terms (anatomy, pharmacology, DSM-IV, ICD-9, etc.). + # Note: word list is current to April 2014; GPL-3.0 licensed. + # Source: https://github.com/glutanimate/hunspell-en-med-glut + medDic = pkgs.fetchurl { + url = "https://raw.githubusercontent.com/glutanimate/hunspell-en-med-glut/master/en_med_glut.dic"; + # Run `nix build` once with this placeholder to get the real hash from the + # error message, then replace it here. + hash = "sha256-voNMOdaB3QED0Lut3KujWXhr0Sa+sdDAi27ZMoVJDBs="; + }; + +in +pkgs.stdenv.mkDerivation { + pname = "hunspell-en-med"; + # Date of last upstream commit to the dictionary file + version = "2017-01-04"; + + dontUnpack = true; + + installPhase = '' + runHook preInstall + mkdir -p $out/share/hunspell + + # Strip the word-count header from both .dic files, concatenate, + # de-duplicate, then prepend the new count to form a valid .dic file. + { + tail -n +2 "${pkgs.hunspellDicts.en_US}/share/hunspell/en_US.dic" + tail -n +2 ${medDic} + } | sort -u > words.txt + + count=$(wc -l < words.txt) + { printf '%s\n' "$count"; cat words.txt; } > $out/share/hunspell/en_MED.dic + + # Reuse en_US affix rules; the medical word list carries no morphology. + cp "${pkgs.hunspellDicts.en_US}/share/hunspell/en_US.aff" $out/share/hunspell/en_MED.aff + + runHook postInstall + ''; + + meta = { + description = "Merged US English + medical terms Hunspell dictionary (en_MED)"; + longDescription = '' + Combines the standard en_US Hunspell dictionary with the glutanimate + medical terms word list (hunspell-en-med-glut), giving a single + en_MED dictionary that covers everyday English and ~90,000 medical terms. + ''; + homepage = "https://github.com/glutanimate/hunspell-en-med-glut"; + license = lib.licenses.gpl3; + platforms = lib.platforms.all; + }; +}