Subject: [PATCH 2/2] gnu: Add chimerautils.

From: [email-masked]
Date: Sun, 12 Jan 2025 10:19:26 +0100

From: Sören Tempel <[email-masked]>

* gnu/packages/admin.scm (chimerautils): New procedure.
* gnu/packages/patches/chimerautils-find-getopt-fix.patch: New file.
* gnu/local.mk: Add new patch.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/admin.scm                        | 36 +++++++++++++++++++
 .../chimerautils-find-getopt-fix.patch        | 25 +++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 gnu/packages/patches/chimerautils-find-getopt-fix.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 9201230f35f..54789bf62cb 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1075,6 +1075,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/ceph-disable-cpu-optimizations.patch	\
   %D%/packages/patches/ceph-fix-for-newer-boost.patch		\
   %D%/packages/patches/cf-tool-add-languages.patch		\
+  %D%/packages/patches/chimerautils-find-getopt-fix.patch	\
   %D%/packages/patches/chmlib-inttypes.patch			\
   %D%/packages/patches/cl-asdf-config-directories.patch		\
   %D%/packages/patches/clamav-config-llvm-libs.patch		\
diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index 7fd05341993..a5383682720 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -154,6 +154,7 @@ (define-module (gnu packages admin)
   #:use-module (gnu packages imagemagick)
   #:use-module (gnu packages inkscape)
   #:use-module (gnu packages kerberos)
+  #:use-module (gnu packages libedit)
   #:use-module (gnu packages libbsd)
   #:use-module (gnu packages libunwind)
   #:use-module (gnu packages libusb)
@@ -669,6 +670,41 @@ (define-public daemontools
     (license license:public-domain)
     (home-page "https://cr.yp.to/daemontools.html")))
 
+(define-public chimerautils
+  (package
+    (name "chimerautils")
+    (version "14.2.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/chimera-linux/chimerautils")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (patches (search-patches "chimerautils-find-getopt-fix.patch"))
+       (sha256
+        (base32 "1z23ii57r9li4ffk9fg8q5k6n74rkzvmj2v5bcwb7dgkjanmhrn5"))))
+    (build-system meson-build-system)
+    (arguments
+     (list
+      #:tests? #f)) ;no test suite
+    (inputs (list (list zstd "lib")
+                  zlib
+                  ncurses
+                  acl
+                  libedit
+                  libxo
+                  openssl))
+    (native-inputs (list flex bison pkg-config))
+    (home-page "https://github.com/chimera-linux/chimerautils")
+    (synopsis "The FreeBSD-based core Linux userland from Chimera Linux")
+    (description
+     "This is a port of the FreeBSD userland for Linux provided by
+the Chimera Linux distribution.  Essentially, it is a collection of UNIX tools
+such as @command{grep}, @command{cp}, @command{vi}, etc. and can be used as an
+alternative to the corresponding implementations from the GNU project.")
+    (license license:bsd-2)))
+
 (define-public daemonize
   (package
     (name "daemonize")
diff --git a/gnu/packages/patches/chimerautils-find-getopt-fix.patch b/gnu/packages/patches/chimerautils-find-getopt-fix.patch
new file mode 100644
index 00000000000..8748b877a86
--- /dev/null
+++ b/gnu/packages/patches/chimerautils-find-getopt-fix.patch
@@ -0,0 +1,25 @@
+Patch-Source: https://github.com/chimera-linux/chimerautils/commit/b82903e6fbe37eb4feeeec259600611d46a71282
+
+By default, GNU getopt(3) will continue parsing options after the
+first nonoption. This behavior is incompatible with this find(1)
+implementation, causing parts of the expression to be parsed as
+(invalid) options.
+
+The behavior can be disabled by prefixing the option string with
+a `+` character. Other applets, such as flock or mcookie do it
+already so it would be cool to do this here too to make find(1)
+compatible with glibc.
+
+diff --git a/src.freebsd/findutils/find/main.c b/src.freebsd/findutils/find/main.c
+index 931d811..876d532 100644
+--- a/src.freebsd/findutils/find/main.c
++++ b/src.freebsd/findutils/find/main.c
+@@ -90,7 +90,7 @@ main(int argc, char *argv[])
+ 	p = start = argv;
+ 	Hflag = Lflag = 0;
+ 	ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
+-	while ((ch = getopt(argc, argv, "EHLPXdf:sx")) != -1)
++	while ((ch = getopt(argc, argv, "+EHLPXdf:sx")) != -1)
+ 		switch (ch) {
+ 		case 'E':
+ 			regexp_flags |= REG_EXTENDED;