Subject: [bug#57146] [PATCH] gnu: polkit: Fix cross-compiling

From: Andrew Patterson <[email-masked]>
Date: Thu, 11 Aug 2022 19:11:00 -0400

The polkit package used to refer to docbook-xsl via inputs rather native inputs,
which obviously doesn't work when cross-compiling.
---
 gnu/packages/polkit.scm | 165 ++++++++++++++++++++--------------------
 1 file changed, 83 insertions(+), 82 deletions(-)

diff --git a/gnu/packages/polkit.scm b/gnu/packages/polkit.scm
index a75608cd43..dd0cf42e5d 100644
--- a/gnu/packages/polkit.scm
+++ b/gnu/packages/polkit.scm
@@ -9,6 +9,7 @@
 ;;; Copyright © 2018 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2021 Morgan Smith <[email-masked]>
 ;;; Copyright © 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2022 Andrew Patterson <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -27,6 +28,7 @@
 
 (define-module (gnu packages polkit)
   #:use-module ((guix licenses) #:select (lgpl2.0+))
+  #:use-module (guix gexp)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix memoization)
@@ -55,92 +57,91 @@ (define-public polkit-mozjs
     (name "polkit")
     (version "0.120")
     (source (origin
-             (method url-fetch)
-             (uri (string-append
-                   "https://www.freedesktop.org/software/polkit/releases/"
-                   name "-" version ".tar.gz"))
-             (sha256
-              (base32
-               "00zfg9b9ivkcj2jcf5b92cpvvyljz8cmfwj86lkvy5rihnd5jypf"))
-             (patches (search-patches "polkit-configure-elogind.patch"
-                                      "polkit-CVE-2021-4034.patch"))
-             (modules '((guix build utils)))
-             (snippet
-              '(begin
-                 (use-modules (guix build utils))
-                 ;; Disable broken test.
-                 (substitute* "test/Makefile.in"
-                   (("SUBDIRS = mocklibc . polkit polkitbackend")
-                    "SUBDIRS = mocklibc . polkit"))
-                 ;; Disable a test that requires Python, D-Bus and a few
-                 ;; libraries and fails with "ERROR: timed out waiting for bus
-                 ;; process to terminate".
-                 (substitute* "test/polkitbackend/Makefile.am"
-                   (("TEST_PROGS \\+= polkitbackendjsauthoritytest-wrapper.py")
-                    ""))
-                 ;; Guix System's polkit
-                 ;; service stores actions under /etc/polkit-1/actions.
-                 (substitute* "src/polkitbackend/polkitbackendinteractiveauthority.c"
-                   (("PACKAGE_DATA_DIR \"/polkit-1/actions\"")
-                    "PACKAGE_SYSCONF_DIR \"/polkit-1/actions\""))
-                 ;; Set the setuid helper's real location.
-                 (substitute* "src/polkitagent/polkitagentsession.c"
-                   (("PACKAGE_PREFIX \"/lib/polkit-1/polkit-agent-helper-1\"")
-                    "\"/run/setuid-programs/polkit-agent-helper-1\""))))))
+              (method url-fetch)
+              (uri (string-append
+                    "https://www.freedesktop.org/software/polkit/releases/"
+                    name "-" version ".tar.gz"))
+              (sha256
+               (base32
+                "00zfg9b9ivkcj2jcf5b92cpvvyljz8cmfwj86lkvy5rihnd5jypf"))
+              (patches (search-patches "polkit-configure-elogind.patch"
+                                       "polkit-CVE-2021-4034.patch"))
+              (modules '((guix build utils)))
+              (snippet '(begin
+                          (use-modules (guix build utils))
+                          ;; Disable broken test.
+                          (substitute* "test/Makefile.in"
+                            (("SUBDIRS = mocklibc . polkit polkitbackend")
+                             "SUBDIRS = mocklibc . polkit"))
+                          ;; Disable a test that requires Python, D-Bus and a few
+                          ;; libraries and fails with "ERROR: timed out waiting for bus
+                          ;; process to terminate".
+                          (substitute* "test/polkitbackend/Makefile.am"
+                            (("TEST_PROGS \\+= polkitbackendjsauthoritytest-wrapper.py")
+                             ""))
+                          ;; Guix System's polkit
+                          ;; service stores actions under /etc/polkit-1/actions.
+                          (substitute* "src/polkitbackend/polkitbackendinteractiveauthority.c"
+                            (("PACKAGE_DATA_DIR \"/polkit-1/actions\"")
+                             "PACKAGE_SYSCONF_DIR \"/polkit-1/actions\""))
+                          ;; Set the setuid helper's real location.
+                          (substitute* "src/polkitagent/polkitagentsession.c"
+                            (("PACKAGE_PREFIX \"/lib/polkit-1/polkit-agent-helper-1\"")
+                             "\"/run/setuid-programs/polkit-agent-helper-1\""))))))
     (build-system gnu-build-system)
-    (inputs
-     (list expat linux-pam elogind mozjs nspr))
-    (propagated-inputs
-     (list glib)) ; required by polkit-gobject-1.pc
-    (native-inputs
-     (list pkg-config
-           `(,glib "bin")                         ;for glib-mkenums
-           intltool
-           gobject-introspection
-           libxslt                                ;for man page generation
-           docbook-xsl))                          ;for man page generation
+    (inputs (list expat linux-pam elogind mozjs nspr))
+    (propagated-inputs (list glib)) ;required by polkit-gobject-1.pc
+    (native-inputs (list pkg-config
+                         `(,glib "bin") ;for glib-mkenums
+                         intltool
+                         gobject-introspection
+                         libxslt ;for man page generation
+                         docbook-xsl)) ;for man page generation
     (arguments
-     `(#:configure-flags '("--sysconfdir=/etc"
-                           "--enable-man-pages"
-                           ;; Prevent ‘configure: error: cannot check for
-                           ;; file existence when cross compiling’.
-                           ,@(if (%current-target-system)
-                                 '("--with-os-type=unknown")
-                                 '()))
-       #:phases
-       (modify-phases %standard-phases
-         (add-after
-          'unpack 'fix-introspection-install-dir
-          (lambda* (#:key outputs #:allow-other-keys)
-            (let ((out (assoc-ref outputs "out")))
-              (substitute* (find-files "." "Makefile.in")
-                (("@INTROSPECTION_GIRDIR@")
-                 (string-append out "/share/gir-1.0/"))
-                (("@INTROSPECTION_TYPELIBDIR@")
-                 (string-append out "/lib/girepository-1.0/"))))))
-         (add-after 'unpack 'fix-manpage-generation
-           (lambda* (#:key inputs #:allow-other-keys)
-             (let ((xsldoc (string-append (assoc-ref inputs "docbook-xsl")
-                                          "/xml/xsl/docbook-xsl-"
-                                          ,(package-version docbook-xsl))))
-               (substitute* '("docs/man/Makefile.am" "docs/man/Makefile.in")
-                 (("http://docbook.sourceforge.net/release/xsl/current")
-                  xsldoc)))))
-         (replace
-          'install
-          (lambda* (#:key outputs (make-flags '()) #:allow-other-keys)
-            ;; Override sysconfdir during "make install", to avoid attempting
-            ;; to install in /etc, and to instead install the skeletons in the
-            ;; output directory.
-            (let ((out (assoc-ref outputs "out")))
-             (apply invoke "make" "install"
-                           (string-append "sysconfdir=" out "/etc")
-                           (string-append "polkit_actiondir="
-                                          out "/share/polkit-1/actions")
-                           make-flags)))))))
+     (list #:configure-flags `(list "--sysconfdir=/etc" "--enable-man-pages"
+                                    ;; Prevent ‘configure: error: cannot check for
+                                    ;; file existence when cross compiling’.
+                                    ,@(if (%current-target-system)
+                                          '("--with-os-type=unknown")
+                                          '()))
+           #:phases #~(modify-phases %standard-phases
+                        (add-after 'unpack 'fix-introspection-install-dir
+                          (lambda* (#:key outputs #:allow-other-keys)
+                            (let ((out (assoc-ref outputs "out")))
+                              (substitute* (find-files "." "Makefile.in")
+                                (("@INTROSPECTION_GIRDIR@")
+                                 (string-append out "/share/gir-1.0/"))
+                                (("@INTROSPECTION_TYPELIBDIR@")
+                                 (string-append out "/lib/girepository-1.0/"))))))
+                        (add-after 'unpack 'fix-manpage-generation
+                          (lambda* (#:key native-inputs #:allow-other-keys)
+                            (let ((xsldoc (string-append (assoc-ref
+                                                          native-inputs
+                                                          "docbook-xsl")
+                                           "/xml/xsl/docbook-xsl-"
+                                           #$(package-version docbook-xsl))))
+                              (substitute* '("docs/man/Makefile.am"
+                                             "docs/man/Makefile.in")
+                                (("http://docbook.sourceforge.net/release/xsl/current")
+                                 xsldoc)))))
+                        (replace 'install
+                          (lambda* (#:key outputs
+                                    (make-flags '()) #:allow-other-keys)
+                            ;; Override sysconfdir during "make install", to avoid attempting
+                            ;; to install in /etc, and to instead install the skeletons in the
+                            ;; output directory.
+                            (let ((out (assoc-ref outputs "out")))
+                              (apply invoke
+                                     "make"
+                                     "install"
+                                     (string-append "sysconfdir=" out "/etc")
+                                     (string-append "polkit_actiondir=" out
+                                                    "/share/polkit-1/actions")
+                                     make-flags)))))))
     (home-page "https://www.freedesktop.org/wiki/Software/polkit/")
     (synopsis "Authorization API for privilege management")
-    (description "Polkit is an application-level toolkit for defining and
+    (description
+     "Polkit is an application-level toolkit for defining and
 handling the policy that allows unprivileged processes to speak to
 privileged processes.  It is a framework for centralizing the decision
 making process with respect to granting access to privileged operations
-- 
2.37.1