From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:56444) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsqXI-00019R-Oy for guix-patches@gnu.org; Wed, 31 Jul 2019 11:29:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsqXG-0006gR-S0 for guix-patches@gnu.org; Wed, 31 Jul 2019 11:29:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44088) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsqXF-0006gC-VP for guix-patches@gnu.org; Wed, 31 Jul 2019 11:29:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hsqXF-0002e9-Qm for guix-patches@gnu.org; Wed, 31 Jul 2019 11:29:01 -0400 Subject: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs. Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:56166) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsqWZ-0000uA-S2 for guix-patches@gnu.org; Wed, 31 Jul 2019 11:28:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsqWY-00065V-Lk for guix-patches@gnu.org; Wed, 31 Jul 2019 11:28:19 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:33840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsqWY-00064Q-Cd for guix-patches@gnu.org; Wed, 31 Jul 2019 11:28:18 -0400 Received: by mail-pf1-x436.google.com with SMTP id b13so32066758pfo.1 for ; Wed, 31 Jul 2019 08:28:18 -0700 (PDT) Received: from x200 ([240f:c7:38e9:1:314b:485c:9ba4:72c6]) by smtp.gmail.com with ESMTPSA id h9sm81692648pgk.10.2019.07.31.08.28.15 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 08:28:16 -0700 (PDT) From: Maxim Cournoyer Date: Thu, 01 Aug 2019 09:27:45 +0900 Message-ID: <875znhbugu.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 36875@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Hello! This follows up to my second post under the thread at (https://lists.gnu.org/archive/html/help-guix/2019-07/msg00180.html). It aims to shed some light on (more) complex mcron job Guile scripting with the aid of Guix features (such as program-file). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-doc-Document-the-use-of-program-file-for-mcron-jobs.patch Content-Transfer-Encoding: quoted-printable From=204d2c5929f056e547b6bd138f69bd1e09e7cfc89f Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 1 Aug 2019 07:34:17 +0900 Subject: [PATCH] doc: Document the use of `program-file' for mcron jobs. * doc/guix.texi (Scheduled Job Execution): Explain why using `program-file' for an mcron job can be necessary. Add an example. =2D-- doc/guix.texi | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index e6047a4909..418dbce16b 100644 =2D-- a/doc/guix.texi +++ b/doc/guix.texi @@ -12444,6 +12444,41 @@ gexps to introduce job definitions that are passed= to mcron %base-services))) @end lisp =20 +For more complex jobs defined in Scheme, it is safer to pass the job as a +script to mcron; otherwise, imported syntax definitions wouldn't work +correctly, as these must be strictly imported at the top level of a Guile +module. This can be achieved using the @code{program-file} procedure from= the +@code{(guix gexp)} module, as shown in the example below. + +@lisp +(define %battery-alert-job + ;; Beep the system when the battery reaches %MIN-LEVEL or less + ;; battery percent. + #~(job + '(next-minute (range 0 60 1)) + #$(program-file + "battery-alert.scm" + (with-imported-modules (source-module-closure + '((guix build utils))) + #~(begin + (define %min-level 20) + (use-modules (guix build utils) + (ice-9 popen) + (ice-9 regex) + (ice-9 textual-ports) + (srfi srfi-26)) + (setenv "LC_ALL" "C") + (let* ((input-pipe (open-pipe* OPEN_READ + #$(file-append acpi "/bin/acpi"))) + (output (get-string-all input-pipe)) + (m (string-match "Discharging, ([0-9]+)%" output)) + (level (and=3D> m (compose string->number + (cut match:substring <> 1))))) + (when (and=3D> level (cut <=3D <> %min-level)) + (format #t "warning: Battery level is low (~a%)~%" level) + (invoke #$(file-append beep "/bin/beep") "-r5")))))))) +@end lisp + @xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron}, for more information on mcron job specifications. Below is the reference of the mcron service. =2D-=20 2.21.0 --=-=-= Content-Type: text/plain Thanks, Maxim --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEJ9WGpPiQCFQyn/CfEmDkZILmNWIFAl1CMgIACgkQEmDkZILm NWLpDQ/9FmZSVw7FNg9IWrTwGUX0HqVmUpJ/EexwVfOfJPdWrcYQjIJ9BpLNN+Xf MQ6dO0nEck+zw8SgJPbCKiNUo65bKFs+W6nRk9nuvIW53I0/uNWqys4HGB+UWjER W3S8nXWdRKpJ/WH1ELWnS3eVHh047l8HPtr+f2T4O83zKk6BS1WJjiYChyn4HYAJ u5JQfZSGEIXkYbkw2U2iYK1HGdVPbY4Sx8ACSHf7YNaP9QN8+iYx5mEPlGZpdMG4 tAOQhJqhU20YyOUn3WsxUrbNe3Wm528+N2EuT5DS2zA/HkeE9Z1daDSyLdL23vlS fxYa3gwozfJN+ayYIkiuUyOTxw+mnJHD5V0Sib52dgX2fE1fhfXFZLdOtvn98o70 IJm4/27gjUaRoe0VkFJQvBS4e6enTnD+s9c7XqE9DemJki1UvXvr7QahW33TQbzd XreQKd3jyVGB0IBL6w1fbQTyJiXyFi2YeNdmiSC1YAtnWo6YUQ0aJPXxkRwf3vZR 09U4w4k1xjWXEtiWZNiRELFOjcf7d8tCDm1bg2S3+EFulHSizEbQe4LkfP7hRKlh GuGcBs43g4SeT7MszgsZG3CSv5Db6EjYkM8lrLACoiWf7sKQOtwZiGKA5F511U+A 0mvouRxrFZGqUo7zPmZODsYSdhwc2hPXlsCX/UlvyZQc5nDuSNc= =KTL7 -----END PGP SIGNATURE----- --==-=-=--