unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Prepend string to "file" in G-expression
@ 2024-12-11  7:43 Marc Coquand
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Coquand @ 2024-12-11  7:43 UTC (permalink / raw)
  To: help-guix


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


-- 
Marc


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Prepend string to "file" in G-expression
       [not found] <87r06esal7.fsf@rdklein.fr>
@ 2024-12-11 12:40 ` Marc Coquand
  2024-12-11 19:40   ` Felix Lechner via
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Coquand @ 2024-12-11 12:40 UTC (permalink / raw)
  To: Edouard Klein; +Cc: help-guix


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Prepend string to "file" in G-expression
  2024-12-11 12:40 ` Prepend string to "file" in G-expression Marc Coquand
@ 2024-12-11 19:40   ` Felix Lechner via
  0 siblings, 0 replies; 3+ messages in thread
From: Felix Lechner via @ 2024-12-11 19:40 UTC (permalink / raw)
  To: Marc Coquand; +Cc: Edouard Klein, help-guix

Hi Marc,

On Wed, Dec 11 2024, Marc Coquand wrote:

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

Maybe you could pipe an appropriately formatted text to 'sendmail'?
Here is an example. [1]

Kind regards
Felix

[1] https://codeberg.org/lechner/system-config/src/commit/4335818ba8da818f21810b5b402db51c77d3b344/host/wallace-server/operating-system.scm#L899-L908


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-12  1:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87r06esal7.fsf@rdklein.fr>
2024-12-11 12:40 ` Prepend string to "file" in G-expression Marc Coquand
2024-12-11 19:40   ` Felix Lechner via
2024-12-11  7:43 Marc Coquand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).