help-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Prepend string to "file" in G-expression


From: Marc Coquand
Subject: Re: Prepend string to "file" in G-expression
Date: Wed, 11 Dec 2024 14:40:11 +0200

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 via email to

[Prev in Thread] Current Thread [Next in Thread]