all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Marc Coquand <marc@coquand.email>
To: Edouard Klein <edou@rdklein.fr>
Cc: help-guix@gnu.org
Subject: Re: Prepend string to "file" in G-expression
Date: Wed, 11 Dec 2024 14:40:11 +0200	[thread overview]
Message-ID: <87a5d2e6l0.fsf@coquand.email> (raw)
In-Reply-To: <87r06esal7.fsf@rdklein.fr> (message from Edouard Klein on Wed, 11 Dec 2024 12:49:56 +0100)


Heya,

Essentially what I'm trying to do is build a program that sends an
email, and then package it in Guix.

The reason is that laminar (a ci tool) expects a script to run
after each job.

My initial idea was to build a shell-script with Guile, but I thought it
might be easier to build a Guile-script instead with Gexpr. So using
guix to construct a file containing the appropriate guile program to
run.

The error in the previous email turned out to not be related to that
code, I was confused because it complained about string-append as I was
using that function.

Since the last email I've now come up with the following:

(define notify-mail-gexp
  (with-imported-modules
   '((guix build utils))
   #~(begin
       (use-modules
	(guix build utils)
	(ice-9 popen)
	(ice-9 receive))
       (let* ((cat-bin #$(file-append coreutils "/bin/cat"))
	      (msmtp-bin #$(file-append msmtp "/bin/msmtp"))
	      (job-name (getenv "JOB"))
	      (result (getenv "RESULT")))
	 (receive (from to pids)
	     (pipeline
	      `(("echo"
		 ,(string-append
		   "To: builds@address\n"
		   "Subject: Build | " job-name "#" result 
		   "From: build-notify@address\n\n"
		   "You can not reply to this email."))
		(,msmtp-bin
		 "--host=smtp.eu.mailgun.org"
		 "--port=587"
		 "--auth=on"
		 "--user=build-notify@address"
		 "--tls=on"
		 "-t"
		 "--read-envelope-from"
		 "--set-from-header=auto"
		 ,(string-append "--passwordeval=" cat-bin " " "/run/secrets/mailgun"))))
	   (close from)
	   (close to))))))

(program-file "notify-mail" notify-mail-gexp)

This kind of works, but piping unix commands this way is not very
ergonomic, so I wonder what a better approach would be. Maybe a
plain-file with a shell-script is simpler.

-- 
Marc

On Wed, Dec 11 2024, Edouard Klein wrote:

> Hi,
>
> I foresee at least two problems with what you are trying to achieve (I
> may be mistaken so take this with a grain of salt):
> - Gexps are for passing info to the build daemon, and at build time
> there is no internet connection, and therefore no way to send an email
> - Any file you reference will be pulled in the store, therefore your
> password will be in the store, for all to read.
>
>
>
> As for the rest, I don't think I understand your question:
> just put the file name after "/bin/cat " (notice the space after cat).
>
> If it's provided by a package, use the #$package-name "/relative/path",
> otherwise you could use something like #$(plain-file "name" "content")
> or #$(local file "fname"). But again, beware, those are going to be
> copied into the store.
>
> Could you please tell us more about what you are trying to achieve ?
>
> Cheers,
>
> Edouard.
> Marc Coquand <marc@coquand.email> writes:
>
>> Heya, I'm trying to grok g-expressions and setting up a small guile
>> program that sends an email.
>>
>> I have the following
>>
>> (define notify-mail-gexp
>>   (with-imported-modules
>>    '((guix build utils))
>>    #~(begin
>>        (use-modules
>> 	(guix build utils))
>>        (let* ((msmtp-bin #$(file-append msmtp "/bin/msmtp"))
>> 	      (run-number (getenv "RUN"))
>> 	      (result (getenv "RESULT"))
>> 	      (job-name (getenv "JOB"))
>> 	      (password-eval-command
>> 	       (string-append
>>                "--password-eval=" #$coreutils "/bin/cat"))) ;; more to come later
>> 	 (invoke msmtp-bin
>> 		 "--user=\"me@address\""
>> 		 password-eval-command
>> 		 "-t"
>> 		 "--read-envelope-from"
>> 		 "--set-from-header=\"auto\""
>> 		 (result-email job-name run-number result))))))
>>
>> (program-file "notify-mail" notify-mail-gexp)
>>
>> What I struggle with is the correct incantation to build an argument to
>> invoke that looks like this:
>>
>> --password-eval=/gnu/blahblah/bin/cat some-file
>>
>> And I'd love any kind of directions for how I'm supposed to write this
>> correctly.
>>
>> Thanks in advance


       reply	other threads:[~2024-12-11 12:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87r06esal7.fsf@rdklein.fr>
2024-12-11 12:40 ` Marc Coquand [this message]
2024-12-11 19:40   ` Prepend string to "file" in G-expression Felix Lechner via
2024-12-12 11:27     ` Marc Coquand
2024-12-11  7:43 Marc Coquand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5d2e6l0.fsf@coquand.email \
    --to=marc@coquand.email \
    --cc=edou@rdklein.fr \
    --cc=help-guix@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.