NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.19k stars 14.2k forks source link

Hunspell dictionaries require per-user installation. #95455

Closed calvertvl closed 2 years ago

calvertvl commented 4 years ago

Describe the bug Hunspell cannot find dictionaries that installed globally without a problem. I have added the following packages to the global package configuration, and they show as installed (e.g. the docs for the dictionaries show up in /run/current-system/sw/share/doc/).

hunspell
hunspellDicts.en-us
hunspellDicts.en-us-large

Output:

 $ ls /run/current-system/sw/share/doc/hun* -l
lrwxrwxrwx 1 root root 149 Dec 31  1969 /run/current-system/sw/share/doc/hunspell-dict-en-us-large-wordlist-2018.04.16.txt -> /nix/store/5k4qp490w6gd5gqwb341cjg1q0z0z596-hunspell-dict-en-us-large-wordlist-2018.04.16/share/doc/hunspell-dict-en-us-large-wordlist-2018.04.16.txt
lrwxrwxrwx 1 root root 137 Dec 31  1969 /run/current-system/sw/share/doc/hunspell-dict-en-us-wordlist-2018.04.16.txt -> /nix/store/l6nyzg1m4g5zdrx6iv0yvlj6zr1kc24i-hunspell-dict-en-us-wordlist-2018.04.16/share/doc/hunspell-dict-en-us-wordlist-2018.04.16.txt
$ ls /nix/store/5k4qp490w6gd5gqwb341cjg1q0z0z596-hunspell-dict-en-us-large-wordlist-2018.04.16/share/hunspell/ /nix/store/l6nyzg1m4g5zdrx6iv0yvlj6zr1kc24i-hunspell-dict-en-us-wordlist-2018.04.16/share/hunspell/
/nix/store/5k4qp490w6gd5gqwb341cjg1q0z0z596-hunspell-dict-en-us-large-wordlist-2018.04.16/share/hunspell/:
en_US.aff  en_US.dic

/nix/store/l6nyzg1m4g5zdrx6iv0yvlj6zr1kc24i-hunspell-dict-en-us-wordlist-2018.04.16/share/hunspell/:
en_US.aff  en_US.dic

$ hunspell -D
SEARCH PATH:
.::/home/calvertvl/.nix-profile/share/hunspell:/etc/profiles/per-user/calvertvl/share/hunspell:/nix/var/nix/profiles/default/share/hunspell:/run/current-system/sw/share/hunspell:/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/home/calvertvl/.openoffice.org/3/user/wordbook:/home/calvertvl/.openoffice.org2/user/wordbook:/home/calvertvl/.openoffice.org2.0/user/wordbook:/home/calvertvl/Library/Spelling:/opt/openoffice.org/basis3.0/share/dict/ooo:/usr/lib/openoffice.org/basis3.0/share/dict/ooo:/opt/openoffice.org2.4/share/dict/ooo:/usr/lib/openoffice.org2.4/share/dict/ooo:/opt/openoffice.org2.3/share/dict/ooo:/usr/lib/openoffice.org2.3/share/dict/ooo:/opt/openoffice.org2.2/share/dict/ooo:/usr/lib/openoffice.org2.2/share/dict/ooo:/opt/openoffice.org2.1/share/dict/ooo:/usr/lib/openoffice.org2.1/share/dict/ooo:/opt/openoffice.org2.0/share/dict/ooo:/usr/lib/openoffice.org2.0/share/dict/ooo
AVAILABLE DICTIONARIES (path is not mandatory for -d option):
$ ls /run/current-system/sw/share/hunspell
ls: cannot access '/run/current-system/sw/share/hunspell': No such file or directory
$

Expected behavior Hunspell should be able to see at least one of the two en-US dictionaries, e.g. these files should be visible:

$ ls /run/current-system/sw/share/hunspell -d
/run/current-system/sw/share/hunspell/
$ ls /run/current-system/sw/share/hunspell
en_US.aff  en_US.dic

Workaround

Note that the following command seems to work to install it in the user-profile (for either of the dictionaries), but must be run per-user, e.g. with:

$ nix-env -iA nixos.hunspellDicts.en-us

It is not possible to install both in parallel for the same user:

$ nix-env -iA nixos.hunspellDicts.en-us-large
installing 'hunspell-dict-en-us-large-wordlist-2018.04.16'
building '/nix/store/ps7cjjfykwrr1ky9xhdxandr32c709ia-user-environment.drv'...
error: packages '/nix/store/l6nyzg1m4g5zdrx6iv0yvlj6zr1kc24i-hunspell-dict-en-us-wordlist-2018.04.16/share/myspell/dicts/en_US.aff' and '/nix/store/5k4qp490w6gd5gqwb341cjg1q0z0z596-hunspell-dict-en-us-large-wordlist-2018.04.16/share/myspell/dicts/en_US.aff' have the same priority 5; use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' to change the priority of one of the conflicting packages (0 being the highest priority)
builder for '/nix/store/ps7cjjfykwrr1ky9xhdxandr32c709ia-user-environment.drv' failed with exit code 1
error: build of '/nix/store/ps7cjjfykwrr1ky9xhdxandr32c709ia-user-environment.drv' failed
$

I would normally expect the same error to occur at the system level.

Additional context I'm trying to get spellchecking to work in LibreOffice, but if the command-line hunspell cannot find the libraries, I don't expect LibreOffice to do so.

Notify maintainers

Metadata Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.58, NixOS, 20.03.2791.05195accdc5 (Markhor)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.6`
 - channels(root): `"nixos-20.03.2791.05195accdc5"`
 - channels(calvertvl): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
  - hunspell
  - libreoffice-fresh
  - hunspellDicts.en-us
  - hunspellDicts.en-us-large
# a list of nixos modules affected by the problem
module:
sternenseemann commented 4 years ago

What does hunspell -D output for you? I have a similar configuration as you and have no problem:

$ hunspell -D
SEARCH PATH:
.::/home/lukas/.nix-profile/share/hunspell:/etc/profiles/per-user/lukas/share/hunspell:/nix/var/nix/profiles/default/share/hunspell:/run/current-system/sw/share/hunspell:/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/home/lukas/.openoffice.org/3/user/wordbook:/home/lukas/.openoffice.org2/user/wordbook:/home/lukas/.openoffice.org2.0/user/wordbook:/home/lukas/Library/Spelling:/opt/openoffice.org/basis3.0/share/dict/ooo:/usr/lib/openoffice.org/basis3.0/share/dict/ooo:/opt/openoffice.org2.4/share/dict/ooo:/usr/lib/openoffice.org2.4/share/dict/ooo:/opt/openoffice.org2.3/share/dict/ooo:/usr/lib/openoffice.org2.3/share/dict/ooo:/opt/openoffice.org2.2/share/dict/ooo:/usr/lib/openoffice.org2.2/share/dict/ooo:/opt/openoffice.org2.1/share/dict/ooo:/usr/lib/openoffice.org2.1/share/dict/ooo:/opt/openoffice.org2.0/share/dict/ooo:/usr/lib/openoffice.org2.0/share/dict/ooo
AVAILABLE DICTIONARIES (path is not mandatory for -d option):
/run/current-system/sw/share/hunspell/de_DE
/run/current-system/sw/share/hunspell/en_GB
/run/current-system/sw/share/hunspell/en_US
$ grep hunspell /etc/nixos/configuration.nix 
    hunspellDicts.de-de hunspellDicts.en-gb-large hunspellDicts.en-us hunspell
$ nix-env -q | grep hunspell # no hunspell in env
$

I'm on unstable:

 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.53, NixOS, 20.09pre237781.32b46dd897a (Nightingale)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.7`
 - channels(root): `"nixos-20.09pre237781.32b46dd897a"`
 - channels(lukas): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Not sure if there is something else wrong or it's a bug that has been fixed. If you are comfortable with it, you could try updating to unstable. I'm however not sure if it's reversible in your case (it usually is unless there is a nix update then it is possible you won't be able to go back).

calvertvl commented 4 years ago

@sternenseemann , on stable it was broken; the output was above though I only have the hunspellDicts.en-us-large dictionary and hunspell.

I usually run unstable myself (or edge, often plus my own overlay), but this is a machine I manage for someone else and intend to put on auto-update, so I'm not sure it's worth switching to unstable.

Admittedly, I was unable to check how out-of-date the 20.03 stable channel was relative to unstable; my main NixOS box has been out of commission for a while due to LTUAE...and the libreoffice spellcheck is the more important part, anyway (but seems to have other things preventing it from working).

I'll try to get my NixOS dev box up and confirm that this works on unstable by next Monday (and whether or not stable has been fixed), and perhaps attempt to identify what caused the breakage if it is still broken.

sternenseemann commented 4 years ago

Never mind that, I quickly tested it out on 20.03 and can confirm it is broken there for me as well. Now I guess it's a matter of looking through the commits since then to find out which commit fixed it and why?

sternenseemann commented 4 years ago

Okay, I think I have a workaround for 20.03 which is also more nix-y I guess. Use in systemPackages:

hunspellWithDicts [ hunspellDicts.en-us hunspellDicts.en-us-large ]

Instead of installing the dictionaries globally.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

bphenriques commented 1 year ago

I stumbled upon this and I was unable to use the hunspellWithDicts. What I did in my home-manager:

  xdg.configFile = {
    "hunspell/en_US.aff".source = "${pkgs.hunspellDicts.en_US}/share/hunspell/en_US.aff";
    "hunspell/en_US.dic".source = "${pkgs.hunspellDicts.en_US}/share/hunspell/en_US.dic";
    "hunspell/pt_PT.aff".source = "${pkgs.hunspellDicts.pt_PT}/share/hunspell/pt_PT.aff";
    "hunspell/pt_PT.dic".source = "${pkgs.hunspellDicts.pt_PT}/share/hunspell/pt_PT.dic";
  };

  home.sessionVariables = {
    DICPATH = "${config.xdg.configHome}/hunspell";
  };

DICPATH is undocumented but afaik as I found, it can contain a single search path.

Edit: Not using `systemPackages as I prefer an per-user approach. Might look into adding to home-manager.

stereomato commented 1 year ago

in home-manager i juse added the dictionary packages to my home.packages list, lol

bphenriques commented 1 year ago

in home-manager i juse added the dictionary packages to my home.packages list, lol

Interesting.. it wasn't working on my end :| Hunspell was complaining about missing dictionaries.

(I am running in MacOS so I am not sure it is related as sometimes there are small differences in home-manager)

stereomato commented 1 year ago

ah! perhaps its different on macos, yeah.