about summary refs log tree commit diff
path: root/pkgs/tools/misc/mandoc
diff options
context:
space:
mode:
authorsternenseemann <sternenseemann@systemli.org>2021-09-19 20:42:54 +0200
committersternenseemann <sternenseemann@systemli.org>2021-09-23 21:24:10 +0200
commit35e8d91d921b412c9e6046e59ee279738dc43050 (patch)
tree68fd229361ce82c86a27d70ccf67f18fd67a864b /pkgs/tools/misc/mandoc
parent342cabea954fab61dc68b0d9deaa51983b8123e1 (diff)
mandoc: fix UTF-8-support detection and make more robust at runtime
locale(1) is not available in pkgsMusl.stdenv, but it is also not really
necessary. We just need to tell mandoc about *any* UTF-8 locale that is
also available at runtime.

For macOS C.UTF-8 is not available sadly, so we need to use
en_US.UTF-8. Using locale(1) for this is out of the question as NetBSD's
locale(1) depends on mandoc.
Diffstat (limited to 'pkgs/tools/misc/mandoc')
-rw-r--r--pkgs/tools/misc/mandoc/default.nix18
1 files changed, 17 insertions, 1 deletions
diff --git a/pkgs/tools/misc/mandoc/default.nix b/pkgs/tools/misc/mandoc/default.nix
index 9bdb43b3586e4..5eae82c14a55f 100644
--- a/pkgs/tools/misc/mandoc/default.nix
+++ b/pkgs/tools/misc/mandoc/default.nix
@@ -1,5 +1,15 @@
 { lib, stdenv, fetchurl, zlib, perl }:
 
+let
+  # Name of an UTF-8 locale _always_ present at runtime, used for UTF-8 support
+  # (locale set by the user may differ). This would usually be C.UTF-8, but
+  # darwin has no such locale.
+  utf8Locale =
+    if stdenv.hostPlatform.isDarwin
+    then "en_US.UTF-8"
+    else "C.UTF-8";
+in
+
 stdenv.mkDerivation rec {
   pname = "mandoc";
   version = "1.14.6";
@@ -12,12 +22,18 @@ stdenv.mkDerivation rec {
   buildInputs = [ zlib ];
 
   configureLocal = ''
-    HAVE_WCHAR=1
     MANPATH_DEFAULT="/run/current-system/sw/share/man"
     OSNAME="NixOS"
     PREFIX="$out"
     LD_OHASH="-lutil"
     CC=${stdenv.cc.targetPrefix}cc
+    # Bypass the locale(1)-based check for UTF-8 support since it causes trouble:
+    # * We only have meaningful locale(1) implementations for glibc and macOS
+    # * NetBSD's locale(1) (used for macOS) depends on mandoc
+    # * Sandbox and locales cause all kinds of trouble
+    # * build and host libc (and thus locale handling) may differ
+    HAVE_WCHAR=1
+    UTF8_LOCALE=${utf8Locale}
   '';
 
   preConfigure = ''