From unknown Sun Jun 22 17:17:56 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 31 Jul 2019 15:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 36875 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 36875@debbugs.gnu.org X-Debbugs-Original-To: guix-patches Received: via spool by submit@debbugs.gnu.org id=B.156458690410122 (code B ref -1); Wed, 31 Jul 2019 15:29:01 +0000 Received: (at submit) by debbugs.gnu.org; 31 Jul 2019 15:28:24 +0000 Received: from localhost ([127.0.0.1]:52909 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsqWc-0002dB-P1 for submit@debbugs.gnu.org; Wed, 31 Jul 2019 11:28:24 -0400 Received: from lists.gnu.org ([209.51.188.17]:47220) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsqWb-0002d3-1U for submit@debbugs.gnu.org; Wed, 31 Jul 2019 11:28:21 -0400 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 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: ** X-Spam-Status: No, score=2.7 required=5.0 tests=BAYES_50, DATE_IN_FUTURE_06_12, FREEMAIL_FROM,URIBL_BLOCKED autolearn=disabled version=3.3.2 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=uBFRomUgIwkaq93qk1uID3BMuXC7RRlghKkLK0N+Uy0=; b=i2YfES4c/XCFjIeJL0f+/FpNE99v1rvREz9Er9x5HEK3jyR/tgJNxRzoayFacDunnX dQyR1u+KFdEU68LI6iIfT5ywTTYEDoFefOB5yciLXj2PrU1AKddUqBJJ2w1xVoQ427Wl f7MoJ/OoxQUhPtL4UZe8iPtifHfrOWzbEwJ1kS3WLYv11dRwbCqPd38YJ4aYaNOSPEo0 JMK2upWd79yzdHRFDYgEenPrAgkYy+FOSKHEUmCxTggVM1HcSnKwi3beS/cb0hY1BXoa tEo9d23OJvUSwP1Hnx0rDxyicrzLh+R7CgQYFZeIyyawHNYhW/AE39xPV2DVAM8eYHDi O+sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=uBFRomUgIwkaq93qk1uID3BMuXC7RRlghKkLK0N+Uy0=; b=RUF0y+TBLV0xKNZ2wn1lX4RkxdY1Y0pE5vOg5KzabKgX26n+HIbzKftF+5niLvlpv2 0xAyS60h3udx2fYMg6QZpendc4t/DadbHbNvLYGca2qgOrgHEcLnzvWBvgcyKNl1yC/+ NMyJ8kP9Br1PRJI6KY0E4ngphwoQlcnwDoKV0y4uvK5Sw4gyy/2UGYwiIWPtONqF3Z0i yQC05/ColfZqZVDCMW2JO8dySmyZGuYXc6+eTTq4Hks/uFk5Ak7Vwaby7IpR0p69eUuJ Ad5l0PSidqzwGDgy2wjbVhGIDPbII9oRlTxuEgH6L+i4x6P8sN2zALZFreM+IWp+Zxjv kMkw== X-Gm-Message-State: APjAAAUGlJOCPvZKfJGAp8ObwydqY8X/PuyCCD3MrS5CyMod74/6NXEz wFQMxickmUS9Og/ZkQE1QMM9dSMU X-Google-Smtp-Source: APXvYqzVZ8a4C7YtCUvtXpx8XLSQUB/xrtIIgWhmUuT+5iIYH1oZhemdrBkV5lbhwAJsC65hJ3jAEw== X-Received: by 2002:a63:1045:: with SMTP id 5mr113717367pgq.165.1564586897043; Wed, 31 Jul 2019 08:28:17 -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" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::436 X-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --==-=-= 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----- --==-=-=-- From unknown Sun Jun 22 17:17:56 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs. Resent-From: Ricardo Wurmus Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 31 Jul 2019 19:40:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36875 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxim Cournoyer Cc: 36875@debbugs.gnu.org Received: via spool by 36875-submit@debbugs.gnu.org id=B36875.15646019895635 (code B ref 36875); Wed, 31 Jul 2019 19:40:04 +0000 Received: (at 36875) by debbugs.gnu.org; 31 Jul 2019 19:39:49 +0000 Received: from localhost ([127.0.0.1]:53119 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsuRv-0001Sj-1W for submit@debbugs.gnu.org; Wed, 31 Jul 2019 15:39:47 -0400 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21236) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsuRs-0001Sa-PP for 36875@debbugs.gnu.org; Wed, 31 Jul 2019 15:39:45 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1564601982; cv=none; d=zoho.com; s=zohoarc; b=DE5Mbk1QdX70WgoPS5et8j+HCfAoEH3zplywqFIG4+8gY12miP2n0PSrlv3QGcRCkdvtVMjfD27Yl9WdwqNv5FPzJf3TakpvNc4Pq5QJiLOFMnbGsXf4HwWQj99tdDpwH0YuNQiHHvxXE0O9yk8B1tluD0ct++N4dBDM7ebeXeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564601982; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=6SkpPBxYXA/B3hqoK80GeFGxlNCJbVKgSX+1cULA7qo=; b=XGtpCdA6XCsK+DJwgOsbsRGrtrF9GkiOzIVScUu9/e2KMeGzwHQCw+prl2wU8VZ4BspmVsK7PXgkWG+OU57MXLOZawMkIwydcJZEtdvcbXoCHf+XPRH0W5kMB6DjE51nbt/Fp5XbdIAriM5CkR9fGi4cEVsDhCPobXKGD6uIBUQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1564601982; s=zoho; d=elephly.net; i=rekado@elephly.net; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; l=1112; bh=6SkpPBxYXA/B3hqoK80GeFGxlNCJbVKgSX+1cULA7qo=; b=V+pzQ5KT101NTTlznv23iVzMnCFkADbbAi4trVkIWsABS3/jHpjeKIdfSq/b/eb7 EQ5ueTANmqzfXPXyNzuqkai/P7IEs6ocxih/5WyLKD/MhWMi+k3z34S10CmjEfQOBzu DuM4GbrWJlwDA88FH6OAgV3aAHlDRg3vHwlqwXzs= Received: from localhost (p54AD4E9C.dip0.t-ipconnect.de [84.173.78.156]) by mx.zohomail.com with SMTPS id 1564601981420968.3432525888157; Wed, 31 Jul 2019 12:39:41 -0700 (PDT) References: <875znhbugu.fsf@gmail.com> User-agent: mu4e 1.2.0; emacs 26.2 From: Ricardo Wurmus In-reply-to: <875znhbugu.fsf@gmail.com> X-URL: https://elephly.net X-PGP-Key: https://elephly.net/rekado.pubkey X-PGP-Fingerprint: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC Date: Wed, 31 Jul 2019 21:39:37 +0200 Message-ID: <87h872t2me.fsf@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Maxim, > 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). I wonder if this can be worked around some other way, e.g. by adding srfi-26 to the =E2=80=9Cwith-imported-modules=E2=80=9D clause. I don=E2=80=99t fully understand the problem as described in the addition t= o the manual. What does =E2=80=9Cimported syntax definitions wouldn't work corre= ctly=E2=80=9D mean? It would be useful to state that this is something to do with srfi-26. About the patch: - please replace tabs with spaces. - =E2=80=9CBeep the system when the battery reaches %MIN-LEVEL or less batt= ery percent.=E2=80=9D sounds odd. How about =E2=80=9CBeep when the battery p= ercentage falls below %MIN-LEVEL.=E2=80=9D? - Can the example be simplified further? Is (setenv "LC_ALL" "C") really needed here? - instead of let* and when I=E2=80=99d probably use and-let*. -- Ricardo From unknown Sun Jun 22 17:17:56 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 01 Aug 2019 15:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36875 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ricardo Wurmus Cc: 36875@debbugs.gnu.org Received: via spool by 36875-submit@debbugs.gnu.org id=B36875.156467188022225 (code B ref 36875); Thu, 01 Aug 2019 15:05:02 +0000 Received: (at 36875) by debbugs.gnu.org; 1 Aug 2019 15:04:40 +0000 Received: from localhost ([127.0.0.1]:54882 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1htCdD-0005mO-QU for submit@debbugs.gnu.org; Thu, 01 Aug 2019 11:04:40 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46475) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1htCdB-0005m8-6E for 36875@debbugs.gnu.org; Thu, 01 Aug 2019 11:04:37 -0400 Received: by mail-pf1-f194.google.com with SMTP id c3so11095323pfa.13 for <36875@debbugs.gnu.org>; Thu, 01 Aug 2019 08:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=fXuMUCFcyGXFjFSJ4GUNZTkkqQ5rwy6moPEJ6zmB5Hc=; b=iy68SG06jjzCgz5812V06VnEz/CgK2eQryyygw0Fg0Pc/LKWQ1tMvmPN7hLLAP4x4l frnbUId2B56fEySNqW1/X4cHikaIjQdVzwBb+vpYTHnB9FI3TDFbAcA/ygHMDbMsmrWu L8KpLtpQXPOYVdTJW6O5eVFiNOc/BXXZ3R4Qa7oVlpF9zIjj0iKeVqZOFjMH5CDj2CCp 6J9DLqf5rqdZc57figQZrtv4ajfSNTb5aSzGgouQKlPaOFbkCVQJh20jXst1FmCsMEg7 A4n66SYYMNZOf1Csdjs41dU5koEOBYI28vtfFXFU8N/z2obKn9+F8rkG8uBjh4wjy0l/ RVpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=fXuMUCFcyGXFjFSJ4GUNZTkkqQ5rwy6moPEJ6zmB5Hc=; b=IOlQFM4cD4HbPNNQ/Fp5WYzdcJw1ztJ1HuCattNWhJBi9aRZ4Thi7CjM3HW+YPi67N KBnip026Ck107VwG6wC4/dE280SwKI/ixMeOHWQB/d4P1rmbkXiy651yDTyagZ2hnMUD 6a8q8oWMf28OrMGJtEO3ust4K/nFqBbCOOWSuFo8Ooz+LPMk9WxRSWY753h5JA18y9le VA8/wP2kCBSBwmhmC1w9Q4HDF3l9fJ6shI7ouBDZ82PbgmkYykIPtV8+bV94JSG1iazW zmMKPgGKOYRGrwF7OnTWVb1DfBjQmanhWZZ9/XZgeUVA1SQTNmQjtQuYLmUWsx2xuWLN JZBw== X-Gm-Message-State: APjAAAVKt7PXt8EGpxUftItwQcfqFJ7MknT+aiTeMig6hi/2/oLoRar/ xCH1KHhCl8920H8H+/cxwZWDjpk4 X-Google-Smtp-Source: APXvYqwWw2viUEwm7+AYxv6z6fqRYOpbnSdWEQgDFZsKaTVjihKbsY1JHkXDdCsmoSeJAHYmudrtJw== X-Received: by 2002:a62:2b81:: with SMTP id r123mr52236562pfr.108.1564671870888; Thu, 01 Aug 2019 08:04:30 -0700 (PDT) Received: from x200 ([240f:c7:38e9:1:314b:485c:9ba4:72c6]) by smtp.gmail.com with ESMTPSA id m20sm79795105pff.79.2019.08.01.08.04.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 08:04:27 -0700 (PDT) From: Maxim Cournoyer References: <875znhbugu.fsf@gmail.com> <87h872t2me.fsf@elephly.net> Date: Fri, 02 Aug 2019 09:03:54 +0900 In-Reply-To: <87h872t2me.fsf@elephly.net> (Ricardo Wurmus's message of "Wed, 31 Jul 2019 21:39:37 +0200") Message-ID: <87wofwa0wl.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Ricardo! Ricardo Wurmus writes: > Hi Maxim, > >> 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). > > I wonder if this can be worked around some other way, e.g. by adding > srfi-26 to the =E2=80=9Cwith-imported-modules=E2=80=9D clause. No; srfi-26 is already present in the Guile load path. `with-imported-modules' is used to import non-builtin Guile modules into the generated script load paths. In the current example, passing (srfi srfi-26) to (with-imported-modules ...) doesn't change the hash of the compiled gexps (because it is already included). > I don=E2=80=99t fully understand the problem as described in the addition= to the > manual. What does =E2=80=9Cimported syntax definitions wouldn't work cor= rectly=E2=80=9D > mean? That any macro imported with (use-modules ...) in a mcron job defined using a lambda would not be expanded correctly. > It would be useful to state that this is something to do with srfi-26. It is not just about srfi-26; but about any syntax definitions (macros) tha= t a user might want to use in a mcron script, such as `guard' from srfi-34. Consider the mcron job defined as below: =2D-8<---------------cut here---------------start------------->8--- (define %macros-in-a-mcron-lambda-job-dont-work (with-imported-modules (source-module-closure '((guix build utils))) #~(job '(next-minute (range 0 60 1)) (lambda _ (use-modules (guix build utils) (srfi srfi-34)) (guard (c ((invoke-error? c)) (format #t "Guard worked as expected.")) (invoke "false")))))) =2D-8<---------------cut here---------------end--------------->8--- Then upon running, it would fail with the following backtrace: =2D-8<---------------cut here---------------start------------->8--- Backtrace: 9 (apply-smob/1 #) In ice-9/boot-9.scm: 829:9 8 (catch _ _ # ?) In mcron/scripts/mcron.scm: 99:7 7 (_) In mcron/base.scm: 234:12 6 (_ #) In srfi/srfi-1.scm: 640:9 5 (for-each # (#< user: #(?>)) In mcron/base.scm: 186:10 4 (run-job _) In ice-9/eval.scm: 159:9 3 (_ #(#(#) ())) 182:19 2 (proc #(#(#) #)) 142:16 1 (compile-top-call _ (7 . c) ((10 (10 (13 15 . #) #)) #)) In unknown file: 0 (%resolve-variable (7 . c) #) ERROR: In procedure %resolve-variable: Unbound variable: c =2D-8<---------------cut here---------------end--------------->8--- Which I found quite puzzling, and can easily imagine other mcron users stumbling onto. The solution (to use the program-file Gexp facility) is not an obvious one, so is worth being documented, in my opinion. I've attempted to clarify the text is the revised patch (attached). > About the patch: > > - please replace tabs with spaces. Done. > - =E2=80=9CBeep the system when the battery reaches %MIN-LEVEL or less ba= ttery > percent.=E2=80=9D sounds odd. How about =E2=80=9CBeep when the battery= percentage > falls below %MIN-LEVEL.=E2=80=9D? Done (and modified the logic to match it). ) > - Can the example be simplified further? Is (setenv "LC_ALL" "C") > really needed here? It's to ensure that the output of the 'acpi' command is in English, which the script depends on (setting the locale of the system to something else could affect this, if acpi is internationalized (I don't know, but I'm protecting against it, in case)). > - instead of let* and when I=E2=80=99d probably use and-let*. Done. Reworked patch is attached. Thanks for the feedback! :-) Maxim --=-=-= 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=200fffed46b4899bf0485926399d3971a4b5e94408 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..dd06efa9c2 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, macros defined or imported with @code{use-modu= les} +wouldn't expand correctly, as Guile requires macros to be strictly defined= or +imported at the top level of a Guile module. This can be achieved using t= he +@code{program-file} procedure from the @code{(guix gexp)} module, as shown= in +the example below. + +@lisp +(define %battery-alert-job + ;; Beep when the battery percentage falls below %MIN-LEVEL. + #~(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-2)) + (setenv "LC_ALL" "C") + (and-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 (string->number (match:substring m 1))) + ((< level %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: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEJ9WGpPiQCFQyn/CfEmDkZILmNWIFAl1DfeoACgkQEmDkZILm NWJnvQ//b4qpwmEA2yGDu4VdR8Qu1WmwyoZ/nM/JlWs1BZ6wbMijVcm6xki2s1b+ SEvkC2Srj9Bp5yU+ETklrGpldE/rDQ81QkBaGWuU022pIpMM/bUdP6NOS6N8w35p TFksKnPmlxxh3qUmO1bpc+5M2yLdy2w0T4X0sy0PlQ665Nrc8XUJpCVv7srVKtPS F250Dl+XMLrM4qT3LEgs7b6BLT5lLtGo7CxTwAqoAUfJDEX5U6odp50OUZB7Jey1 e1q8TPBb9Vvcr2A1almrZrXvTk5QWAFHaUuWgexFwnG53F0ETTUtOLfhvn5KJCcL /RIelrdnensjCF2W914uxOrvZGPSYRdGr0Sx6NGaUK1dn2FrBqbQsgbgrpITT6H4 M2yb3igLYBbdEn4sqGfyOfFxGIAdDXkZQJADqqc04Goad+ANq7rOD1lpYBQDooJr tKWda3Ra3sbpaJBHniGxP3rfGiqgU7u+9cugwNd8dX26b9Hp6JLPBFP/MxkK8TkM grHUhr/JudEa1354Lk7YCzcTmtTY1GzFyQp1732syCrsJlvFR15lOan+NoPOdTnD xiK1ob4JpZJZBPraUJmKEMj5jvsUbCDy1NVlrgr7K6w8dOUX3pqklwgV+HkSeypA VrkmCuReRPGn/zXUo0qvkNhbazfdrLi7bRd7nLWxDCR5O3FYI7A= =+p0u -----END PGP SIGNATURE----- --==-=-=-- From unknown Sun Jun 22 17:17:56 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 17 Aug 2019 20:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36875 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxim Cournoyer Cc: Ricardo Wurmus , 36875@debbugs.gnu.org Received: via spool by 36875-submit@debbugs.gnu.org id=B36875.156607241524271 (code B ref 36875); Sat, 17 Aug 2019 20:07:01 +0000 Received: (at 36875) by debbugs.gnu.org; 17 Aug 2019 20:06:55 +0000 Received: from localhost ([127.0.0.1]:56882 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hz4yU-0006JP-RS for submit@debbugs.gnu.org; Sat, 17 Aug 2019 16:06:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46401) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hz4yS-0006JC-J7 for 36875@debbugs.gnu.org; Sat, 17 Aug 2019 16:06:53 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47870) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hz4yN-00029Z-8f; Sat, 17 Aug 2019 16:06:47 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=50520 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hz4yM-0007ra-PC; Sat, 17 Aug 2019 16:06:47 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <875znhbugu.fsf@gmail.com> <87h872t2me.fsf@elephly.net> <87wofwa0wl.fsf@gmail.com> Date: Sat, 17 Aug 2019 22:06:44 +0200 In-Reply-To: <87wofwa0wl.fsf@gmail.com> (Maxim Cournoyer's message of "Fri, 02 Aug 2019 09:03:54 +0900") Message-ID: <87y2zrd0a3.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello! Maxim Cournoyer skribis: > From 0fffed46b4899bf0485926399d3971a4b5e94408 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-fil= e' > for an mcron job can be necessary. Add an example. [...] > +For more complex jobs defined in Scheme, it is safer to pass the job as a > +script to mcron; otherwise, macros defined or imported with @code{use-mo= dules} > +wouldn't expand correctly, as Guile requires macros to be strictly defin= ed or > +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 sho= wn in > +the example below. Macros are a very good example of the problem, but I wonder if it would be clearer to simply write something like: For more complex jobs defined in Scheme where you need control over the top level, for instance to introduce a @code{use-modules} form, you can move your code to a separate program using the @code{program-file} procedure of the @code{(guix gexp)} module (@pxref{G-Expressions}). The example below illustrates that. Anyway, your patch looks like a great improvement (and a funny example :-)) so IMO you should push one version or another! Thanks, Ludo=E2=80=99. From unknown Sun Jun 22 17:17:56 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Maxim Cournoyer Subject: bug#36875: closed (Re: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs.) Message-ID: References: <8736hog8jh.fsf@gmail.com> <875znhbugu.fsf@gmail.com> X-Gnu-PR-Message: they-closed 36875 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 36875@debbugs.gnu.org Date: Sun, 25 Aug 2019 13:57:06 +0000 Content-Type: multipart/mixed; boundary="----------=_1566741426-30611-1" This is a multi-part message in MIME format... ------------=_1566741426-30611-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #36875: [PATCH] doc: Document the use of `program-file' for mcron jobs. which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 36875@debbugs.gnu.org. --=20 36875: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D36875 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1566741426-30611-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 36875-done) by debbugs.gnu.org; 25 Aug 2019 13:56:18 +0000 Received: from localhost ([127.0.0.1]:44919 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i1t0E-0007vQ-Bj for submit@debbugs.gnu.org; Sun, 25 Aug 2019 09:56:18 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37394) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i1t09-0007vK-BQ for 36875-done@debbugs.gnu.org; Sun, 25 Aug 2019 09:56:13 -0400 Received: by mail-pl1-f194.google.com with SMTP id bj8so8492451plb.4 for <36875-done@debbugs.gnu.org>; Sun, 25 Aug 2019 06:56:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=LDDp7RjZCcjkRC6KPN0/tHhU20qZzfTiW933paNzMYU=; b=um+7/5rm/X8GAWJ9uACpCpysYUP9yPXDS2PV1f3QyuslNHM5afwLcbn36JYiIDDXD8 iQycyvG9c4Aj2BCfq2ZW98r3qu53zUBshReu95rucB7U0YjihV4z+kYeKRp0l7PWroQh rPTwsOjvBAuCHu8JZLeVqIAaaYZJ9kE3EtlFA4CR/79RtrCmlFFmryglVJ1fUyaSVQW6 5YyBUEUbzR+8MQL0rfS42Z1lg2YxsaFvkh/ga7dltjo1pbQuZTc3G30wk7DbfUAN/TFn /bWGnyWZm9Jni3ZV+oTKKAnYLIF9yuRMyU8tyAPhCVlIEflUS/ZWtOwEywxKvIZk/q1i 8v1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=LDDp7RjZCcjkRC6KPN0/tHhU20qZzfTiW933paNzMYU=; b=D74RKiV7PS4AjsernJsncr3v88TNu/9By+aHj60t31uXHmucyVtmTDEgTL6qCvgYL+ 1Z9RPIv3nUkY+rtsbM55/Gp5r4lbOEXDPdqc04k6Uk/2BYdL33oQ5X4XyY5La4TrnyMT tYb8LgJVfvOhfQTJ+Og6+Q9VU3MBVDJPIdaQn27vWGPzOv7jk4UuMSsRFITR6volU8Rz gFjyn69cl8J6BNcz2M4a4gFoHoMPYEj1gRAWFnq/pc8pGB0xLNWHNnF3b89kSZa/DNnF +kZ7cI4KTJQrRB3R3k/46jehA55evis3eBRg3Oq6fcQiVjDPqLVFI3EM5QgMWj9vl0FL 7YGA== X-Gm-Message-State: APjAAAU8cZv4gFjhAto6lOguAh3h5/uvEH5BdJcj1iiOwVACbQvz+yez YrH6GA/zM7BrSd347uRWtTG/o8Ea X-Google-Smtp-Source: APXvYqytDONC63roWbDcfb56qWl5alYay6Sf2d5ifo5XXU9mTOB5Y7gjlrvz1x65HL4o40k3UGoDUQ== X-Received: by 2002:a17:902:7842:: with SMTP id e2mr14066340pln.49.1566741367161; Sun, 25 Aug 2019 06:56:07 -0700 (PDT) Received: from x200 ([240f:c7:38e9:1:314b:485c:9ba4:72c6]) by smtp.gmail.com with ESMTPSA id t23sm9239518pfl.154.2019.08.25.06.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2019 06:56:05 -0700 (PDT) From: Maxim Cournoyer To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs. References: <875znhbugu.fsf@gmail.com> <87h872t2me.fsf@elephly.net> <87wofwa0wl.fsf@gmail.com> <87y2zrd0a3.fsf@gnu.org> Date: Mon, 26 Aug 2019 07:54:58 +0900 In-Reply-To: <87y2zrd0a3.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sat, 17 Aug 2019 22:06:44 +0200") Message-ID: <8736hog8jh.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 36875-done Cc: Ricardo Wurmus , 36875-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello Ludovic! Ludovic Court=C3=A8s writes: > Hello! > > Maxim Cournoyer skribis: > >> From 0fffed46b4899bf0485926399d3971a4b5e94408 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-fi= le' >> for an mcron job can be necessary. Add an example. > > [...] > >> +For more complex jobs defined in Scheme, it is safer to pass the job as= a >> +script to mcron; otherwise, macros defined or imported with @code{use-m= odules} >> +wouldn't expand correctly, as Guile requires macros to be strictly defi= ned or >> +imported at the top level of a Guile module. This can be achieved usin= g the >> +@code{program-file} procedure from the @code{(guix gexp)} module, as sh= own in >> +the example below. > > Macros are a very good example of the problem, but I wonder if it would > be clearer to simply write something like: > > For more complex jobs defined in Scheme where you need control over > the top level, for instance to introduce a @code{use-modules} form, you > can move your code to a separate program using the @code{program-file} > procedure of the @code{(guix gexp)} module (@pxref{G-Expressions}). > The example below illustrates that. I like your version, which feels to me more elegant. But, from my experimentation, using (use-modules) in a nested form is fine for anything else than syntax (macros). Also, the Guile Reference only says that macros must be *defined* at the top level; it doesn't explicitly mention that importing macros is equivalent to defining macros, and are thus subjected to the same restrictions. So, I've amended it to mention the problem more precisely: --8<---------------cut here---------------start------------->8--- For more complex jobs defined in Scheme where you need control over the top level, for instance to introduce a @code{use-modules} form that defines syn= tax (macros), you can move your code to a separate program using the @code{program-file} procedure of the @code{(guix gexp)} module (@pxref{G-Expressions}). The example below illustrates that. --8<---------------cut here---------------end--------------->8--- > Anyway, your patch looks like a great improvement (and a funny example > :-)) so IMO you should push one version or another! This is now live as commit 1407ebeaa1. Thanks for feedback/review! :-) Maxim ------------=_1566741426-30611-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 31 Jul 2019 15:28:24 +0000 Received: from localhost ([127.0.0.1]:52909 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsqWc-0002dB-P1 for submit@debbugs.gnu.org; Wed, 31 Jul 2019 11:28:24 -0400 Received: from lists.gnu.org ([209.51.188.17]:47220) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsqWb-0002d3-1U for submit@debbugs.gnu.org; Wed, 31 Jul 2019 11:28:21 -0400 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 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: ** X-Spam-Status: No, score=2.7 required=5.0 tests=BAYES_50, DATE_IN_FUTURE_06_12, FREEMAIL_FROM,URIBL_BLOCKED autolearn=disabled version=3.3.2 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=uBFRomUgIwkaq93qk1uID3BMuXC7RRlghKkLK0N+Uy0=; b=i2YfES4c/XCFjIeJL0f+/FpNE99v1rvREz9Er9x5HEK3jyR/tgJNxRzoayFacDunnX dQyR1u+KFdEU68LI6iIfT5ywTTYEDoFefOB5yciLXj2PrU1AKddUqBJJ2w1xVoQ427Wl f7MoJ/OoxQUhPtL4UZe8iPtifHfrOWzbEwJ1kS3WLYv11dRwbCqPd38YJ4aYaNOSPEo0 JMK2upWd79yzdHRFDYgEenPrAgkYy+FOSKHEUmCxTggVM1HcSnKwi3beS/cb0hY1BXoa tEo9d23OJvUSwP1Hnx0rDxyicrzLh+R7CgQYFZeIyyawHNYhW/AE39xPV2DVAM8eYHDi O+sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=uBFRomUgIwkaq93qk1uID3BMuXC7RRlghKkLK0N+Uy0=; b=RUF0y+TBLV0xKNZ2wn1lX4RkxdY1Y0pE5vOg5KzabKgX26n+HIbzKftF+5niLvlpv2 0xAyS60h3udx2fYMg6QZpendc4t/DadbHbNvLYGca2qgOrgHEcLnzvWBvgcyKNl1yC/+ NMyJ8kP9Br1PRJI6KY0E4ngphwoQlcnwDoKV0y4uvK5Sw4gyy/2UGYwiIWPtONqF3Z0i yQC05/ColfZqZVDCMW2JO8dySmyZGuYXc6+eTTq4Hks/uFk5Ak7Vwaby7IpR0p69eUuJ Ad5l0PSidqzwGDgy2wjbVhGIDPbII9oRlTxuEgH6L+i4x6P8sN2zALZFreM+IWp+Zxjv kMkw== X-Gm-Message-State: APjAAAUGlJOCPvZKfJGAp8ObwydqY8X/PuyCCD3MrS5CyMod74/6NXEz wFQMxickmUS9Og/ZkQE1QMM9dSMU X-Google-Smtp-Source: APXvYqzVZ8a4C7YtCUvtXpx8XLSQUB/xrtIIgWhmUuT+5iIYH1oZhemdrBkV5lbhwAJsC65hJ3jAEw== X-Received: by 2002:a63:1045:: with SMTP id 5mr113717367pgq.165.1564586897043; Wed, 31 Jul 2019 08:28:17 -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 To: guix-patches Subject: [PATCH] doc: Document the use of `program-file' for mcron jobs. 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" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::436 X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --==-=-= 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----- --==-=-=-- ------------=_1566741426-30611-1-- From unknown Sun Jun 22 17:17:56 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Aug 2019 08:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36875 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxim Cournoyer Cc: Ricardo Wurmus , 36875-done@debbugs.gnu.org Received: via spool by 36875-done@debbugs.gnu.org id=D36875.156680822216793 (code D ref 36875); Mon, 26 Aug 2019 08:31:02 +0000 Received: (at 36875-done) by debbugs.gnu.org; 26 Aug 2019 08:30:22 +0000 Received: from localhost ([127.0.0.1]:45563 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i2AOM-0004Mn-CX for submit@debbugs.gnu.org; Mon, 26 Aug 2019 04:30:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39389) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i2AOK-0004Ma-Ij for 36875-done@debbugs.gnu.org; Mon, 26 Aug 2019 04:30:20 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:36244) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1i2AOF-00048h-3d; Mon, 26 Aug 2019 04:30:15 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=47238 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1i2AOB-0006pZ-KT; Mon, 26 Aug 2019 04:30:14 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <875znhbugu.fsf@gmail.com> <87h872t2me.fsf@elephly.net> <87wofwa0wl.fsf@gmail.com> <87y2zrd0a3.fsf@gnu.org> <8736hog8jh.fsf@gmail.com> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 9 Fructidor an 227 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Mon, 26 Aug 2019 10:30:09 +0200 In-Reply-To: <8736hog8jh.fsf@gmail.com> (Maxim Cournoyer's message of "Mon, 26 Aug 2019 07:54:58 +0900") Message-ID: <87mufw1g8e.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi Maxim, Maxim Cournoyer skribis: > Ludovic Court=C3=A8s writes: > >> Hello! >> >> Maxim Cournoyer skribis: >> >>> From 0fffed46b4899bf0485926399d3971a4b5e94408 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-f= ile' >>> for an mcron job can be necessary. Add an example. >> >> [...] >> >>> +For more complex jobs defined in Scheme, it is safer to pass the job a= s a >>> +script to mcron; otherwise, macros defined or imported with @code{use-= modules} >>> +wouldn't expand correctly, as Guile requires macros to be strictly def= ined or >>> +imported at the top level of a Guile module. This can be achieved usi= ng the >>> +@code{program-file} procedure from the @code{(guix gexp)} module, as s= hown in >>> +the example below. >> >> Macros are a very good example of the problem, but I wonder if it would >> be clearer to simply write something like: >> >> For more complex jobs defined in Scheme where you need control over >> the top level, for instance to introduce a @code{use-modules} form, you >> can move your code to a separate program using the @code{program-file} >> procedure of the @code{(guix gexp)} module (@pxref{G-Expressions}). >> The example below illustrates that. > > I like your version, which feels to me more elegant. But, from my > experimentation, using (use-modules) in a nested form is fine for > anything else than syntax (macros). That=E2=80=99s right, but I strongly recommend not relying on non-toplevel =E2=80=98use-modules=E2=80=99 because (1) it=E2=80=99s =E2=80=9Cugly=E2=80= =9D because it introduces new bindings at run time, and (2) it=E2=80=99s not guaranteed to work in the future=E2= =80=94in fact, the just-released Guile 2.9.4 introduces =E2=80=9Cdeclarative modules=E2=80= =9D, which is probably a first step in the direction of less run-time trickery with modules. > This is now live as commit 1407ebeaa1. Thanks for feedback/review! :-) Great, thank you! Ludo=E2=80=99. From unknown Sun Jun 22 17:17:56 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 27 Aug 2019 02:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36875 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: Ricardo Wurmus , 36875-done@debbugs.gnu.org Received: via spool by 36875-done@debbugs.gnu.org id=D36875.1566871243306 (code D ref 36875); Tue, 27 Aug 2019 02:01:02 +0000 Received: (at 36875-done) by debbugs.gnu.org; 27 Aug 2019 02:00:43 +0000 Received: from localhost ([127.0.0.1]:47409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i2Qmp-0008WV-E9 for submit@debbugs.gnu.org; Mon, 26 Aug 2019 22:00:43 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42861) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i2Qmn-0008WD-BG for 36875-done@debbugs.gnu.org; Mon, 26 Aug 2019 22:00:42 -0400 Received: by mail-pf1-f196.google.com with SMTP id i30so13008529pfk.9 for <36875-done@debbugs.gnu.org>; Mon, 26 Aug 2019 19:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=BVjCwpUFTYlO9XjHIUD+9UPuQ9rhgFN6xffVfeJ8U2E=; b=M3OEOyo+P/ni0+c65gQ0sCXpyivVuh3nYME1qyVcfVxZpMZ2/TaxcHFLbjB882Mx6Q v+9hsMqIn8AaCrJw+KGxJagUrMImjfGJP1axdcGRhKJIJbxDHyaV39e+rWzOxgLC/tPW Cqvse0WL2DdTHpckguvpvGhvcMwrgsSyUeBIjpOx/xLSMU+I11vM6fuxnLGPa/oeq12y c/GYebane1Mcexd6eEdHltouneDWWvYdMzxmkNF+/hkriL+Qtotw85GASCH5F81tYVMq 0m21XNPTOkH0X0TjXBC+SQeguaCPQh9Ll1ccCzUz2zoikwI2wn1vfHCxiQUgIjryJbeq JO3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=BVjCwpUFTYlO9XjHIUD+9UPuQ9rhgFN6xffVfeJ8U2E=; b=e3frC4q+4mQ9Re4xBFU8Nd9zM7B9d/ft1eDuj1oOjFB8SA2PQP/9ULSOVEkpK8q7YT 17LeQwJhjH72rW0jF1t69k+tj2JqY/gHruWWckrmWpW8AUFGuzyut6T9Z2IwLpJ+7rtQ kHwBO+SDUejTtv3l6xjUnEJSIIjOGrIgJWPnclHNbK9upB/TOvs/DQei4YhlnQSRZdXU eb+aNgCjkbHCETcQGkGA6hb9wkRQ/NYK/GmyvpvSPPsH0iLJ0e0fg7LkSPmBlWeTXG9o yRp/D968PNbrQK0hy4+Mma0NhPef2UsRE5BiJO/xU6sBzbOR3+R0l0Alaq2ePFvZopRB /q1Q== X-Gm-Message-State: APjAAAXFRfmBgHEMDYOIqYErSMDvJTKqNmgGG7RBcj+hi1sxXJPJlC0b HKV19nXX6QqitAZSp/hCGJRtMRRU X-Google-Smtp-Source: APXvYqwcUUEmtKILoSmFcUbuUwoW/gZtNXHmv3kXLvi1ZfIzLuXjDeG5U1pp8gIgfaquKUJNSsKeIA== X-Received: by 2002:a17:90a:c70e:: with SMTP id o14mr23086076pjt.56.1566871235020; Mon, 26 Aug 2019 19:00:35 -0700 (PDT) Received: from x200 ([240f:c7:38e9:1:314b:485c:9ba4:72c6]) by smtp.gmail.com with ESMTPSA id t15sm12297347pfc.47.2019.08.26.19.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2019 19:00:33 -0700 (PDT) From: Maxim Cournoyer References: <875znhbugu.fsf@gmail.com> <87h872t2me.fsf@elephly.net> <87wofwa0wl.fsf@gmail.com> <87y2zrd0a3.fsf@gnu.org> <8736hog8jh.fsf@gmail.com> <87mufw1g8e.fsf@gnu.org> Date: Tue, 27 Aug 2019 19:59:25 +0900 In-Reply-To: <87mufw1g8e.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Mon, 26 Aug 2019 10:30:09 +0200") Message-ID: <87o90aeuwi.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello Ludovic, Ludovic Court=C3=A8s writes: > Hi Maxim, > > Maxim Cournoyer skribis: > >> Ludovic Court=C3=A8s writes: >> >>> Hello! >>> >>> Maxim Cournoyer skribis: >>> >>>> From 0fffed46b4899bf0485926399d3971a4b5e94408 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 job= s. >>>> >>>> * doc/guix.texi (Scheduled Job Execution): Explain why using `program-= file' >>>> for an mcron job can be necessary. Add an example. [...] >>> Macros are a very good example of the problem, but I wonder if it would >>> be clearer to simply write something like: >>> >>> For more complex jobs defined in Scheme where you need control over >>> the top level, for instance to introduce a @code{use-modules} form, y= ou >>> can move your code to a separate program using the @code{program-file} >>> procedure of the @code{(guix gexp)} module (@pxref{G-Expressions}). >>> The example below illustrates that. >> >> I like your version, which feels to me more elegant. But, from my >> experimentation, using (use-modules) in a nested form is fine for >> anything else than syntax (macros). > > That=E2=80=99s right, but I strongly recommend not relying on non-toplevel > =E2=80=98use-modules=E2=80=99 because (1) it=E2=80=99s =E2=80=9Cugly=E2= =80=9D because it introduces new bindings > at run time, and (2) it=E2=80=99s not guaranteed to work in the future=E2= =80=94in fact, > the just-released Guile 2.9.4 introduces =E2=80=9Cdeclarative modules=E2= =80=9D, which is > probably a first step in the direction of less run-time trickery with > modules. Oh! That's good to know! Then using your proposed text as-is makes even more sense. Done in commit 4183105de0. Thank you! Maxim