aspell: added new patch data-dirs-from-nix-profiles.patch

Aspell will search for dictionaries in all nix profiles even when used as library.
Setting data-dir or dict-dir in ASPELL_CONF will disable this behavior.
This commit is contained in:
Rostislav Beneš 2017-10-08 21:42:22 +02:00
parent 6d86fcb86d
commit ba4cefe4ae
4 changed files with 49 additions and 24 deletions

View File

@ -1,5 +1,9 @@
# Create a derivation that contains aspell and selected dictionaries.
# Composition is done using `pkgs.buildEnv`.
# Beware of that `ASPELL_CONF` used by this derivation is not always
# respected by libaspell (#28815) and in some cases, when used as
# dependency by another derivation, the passed dictionaries will be
# missing. However, invoking aspell directly should be fine.
{ aspell
, aspellDicts

View File

@ -0,0 +1,38 @@
diff --git a/common/info.cpp b/common/info.cpp
index 8291cc7..6216326 100644
--- a/common/info.cpp
+++ b/common/info.cpp
@@ -36,6 +36,7 @@
#include "strtonum.hpp"
#include "lock.hpp"
#include "string_map.hpp"
+#include "file_util.hpp"
#include "gettext.h"
@@ -495,6 +496,25 @@ namespace acommon {
lst.clear();
lst.add(config->retrieve("data-dir"));
lst.add(config->retrieve("dict-dir"));
+ if (config->lookup("data-dir") == NULL && config->lookup("dict-dir") == NULL) {
+ const char* cprofiles = getenv("NIX_PROFILES");
+ if (cprofiles != NULL) {
+ char* profiles = strdup(cprofiles);
+ char* profile = profiles;
+ char* end = profile;
+ while (*end != '\0') {
+ if (*end == ' ') {
+ *end = '\0';
+ lst.add(add_possible_dir(profile, "lib/aspell"));
+ profile = ++end;
+ } else {
+ ++end;
+ }
+ }
+ lst.add(add_possible_dir(profile, "lib/aspell"));
+ free(profiles);
+ }
+ }
}
DictExt::DictExt(ModuleInfo * m, const char * e)

View File

@ -1,4 +1,5 @@
{stdenv, fetchurl, perl}:
{stdenv, fetchurl, perl
, searchNixProfiles ? true}:
stdenv.mkDerivation rec {
name = "aspell-0.60.6.1";
@ -10,6 +11,8 @@ stdenv.mkDerivation rec {
patchPhase = ''
patch interfaces/cc/aspell.h < ${./clang.patch}
'' + stdenv.lib.optionalString searchNixProfiles ''
patch -p1 < ${./data-dirs-from-nix-profiles.patch}
'';
buildInputs = [ perl ];
@ -23,28 +26,6 @@ stdenv.mkDerivation rec {
);
'';
postInstall = ''
local prog="$out/bin/aspell"
local hidden="$out/bin/.aspell-wrapped"
mv "$prog" "$hidden"
cat > "$prog" <<END
#! $SHELL -e
if [ -z "\$ASPELL_CONF" ]; then
for p in \$NIX_PROFILES; do
if [ -d "\$p/lib/aspell" ]; then
ASPELL_CONF="data-dir \$p/lib/aspell"
fi
done
if [ -z "\$ASPELL_CONF" ] && [ -d "\$HOME/.nix-profile/lib/aspell" ]; then
ASPELL_CONF="data-dir \$HOME/.nix-profile/lib/aspell"
fi
export ASPELL_CONF
fi
exec "$hidden" "\$@"
END
chmod +x "$prog"
'';
meta = {
description = "Spell checker for many languages";
homepage = http://aspell.net/;

View File

@ -7769,7 +7769,9 @@ with pkgs;
aspellDicts = recurseIntoAttrs (callPackages ../development/libraries/aspell/dictionaries.nix {});
aspellWithDicts = callPackage ../development/libraries/aspell/aspell-with-dicts.nix { };
aspellWithDicts = callPackage ../development/libraries/aspell/aspell-with-dicts.nix {
aspell = aspell.override { searchNixProfiles = false; };
};
attica = callPackage ../development/libraries/attica { };