help-guix
[Top][All Lists]
Advanced

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

Re: How to configure smartd and send notifications?


From: Tomas Volf
Subject: Re: How to configure smartd and send notifications?
Date: Fri, 24 May 2024 12:19:39 +0200

On 2024-05-23 21:25:08 +0200, Tristan Kohl via wrote:
> Well look at me. So focused in my old ways on constructing a shell script 
> that I did not even think about using Guile as the executable :D
>
> Thank you Thomas an Felix for your pointers!
>
> I read up about G-Expressions and got it almost working. But I must miss 
> something because when executing the build result it makes the request 
> successfully (checked return of http-get with pk and logs on the server) but 
> still fails with this error:
>
> Backtrace:
>                 0 (primitive-load "/gnu/store/9gjnc0p...")
>
> ERROR: In procedure primitive-load:
> Wrong type to apply: #<unspecified>
>
>
> (use-module (gnu) (guix modules))
> (use-package-modules tls)
>
> (define smartd-send-ntfy
>   (program-file "smartd-send-ntfy"
>     (with-extensions (list gnutls)
>       (with-imported-modules
>         (source-module-closure '((web client)))
>         #~((use-modules (web client))
>            (http-get "https://example.com";))))))

I think g-exp needs to be a single expression.  In other words, add `begin' in
there.  In your code you are basically trying to apply result of `(use-modules
...)' to result of `(http-get ...)'.  Since use-modules do not return anything,
you get the error above.  You can test it using just plain guile and you will
get the same error:

    guile -c '((use-modules (web client)) (http-get "https://example.org";))'

I think this should work:

      (define smartd-send-ntfy
        (program-file "smartd-send-ntfy"
          (with-extensions (list gnutls)
            (with-imported-modules
              (source-module-closure '((web client)))
              #~(begin (use-modules (web client))
                       (http-get "https://example.com";))))))

Your original code:

      $ guix repl
      Loading Guix REPL meta-commands...
      Increasing build verbosity...
      Disabling grafting...
      GNU Guile 3.0.9
      Copyright (C) 1995-2023 Free Software Foundation, Inc.

      Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
      This program is free software, and you are welcome to redistribute it
      under certain conditions; type `,show c' for details.

      Enter `,help' for help.
      scheme@(guix-user)> ,use (guix)
      scheme@(guix-user)> #~((use-modules (web client)) (http-get 
"https://example.com";))
      $1 = #<gexp ((use-modules (web client)) (http-get "https://example.com";)) 
7f6c48696720>
      scheme@(guix-user)> (program-file "test" $1)
      $2 = #<<program-file> name: "test" gexp: #<gexp ((use-modules (web 
client)) (http-get "https://example.com";)) 7f6c48696720> guile: #f path: 
("/gnu/store/ff1cyww9qlra4849q6k0n30w7q67ziim-guix-module-union/share/guile/site/3.0"
 "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" 
"/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" 
"/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site/3.0" 
"/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site" 
"/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile" 
"/home/wolf/.guix-home/profile/share/guile/site/3.0" 
"/run/current-system/profile/share/guile/site/3.0")>
      scheme@(guix-user)> ,lower $2
      $3 = #<derivation /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv => 
/gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test 7f6c35dd5d70>
      scheme@(guix-user)> ,build $3
      building /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv...
      successfully built /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv
      $4 = "/gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test"
      scheme@(guix-user)> (system $4)
      Backtrace:
                 0 (primitive-load 
"/gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test")

      ERROR: In procedure primitive-load:
      Wrong type to apply: #<unspecified>
      $5 = 256

Now with the `begin':

      scheme@(guix-user)> #~(begin (use-modules (web client)) (http-get 
"https://example.com";))
      $6 = #<gexp (begin (use-modules (web client)) (http-get 
"https://example.com";)) 7f6c35e61a20>
      scheme@(guix-user)> (program-file "test" $6)
      $7 = #<<program-file> name: "test" gexp: #<gexp (begin (use-modules (web 
client)) (http-get "https://example.com";)) 7f6c35e61a20> guile: #f path: 
("/gnu/store/ff1cyww9qlra4849q6k0n30w7q67ziim-guix-module-union/share/guile/site/3.0"
 "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" 
"/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" 
"/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site/3.0" 
"/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site" 
"/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile" 
"/home/wolf/.guix-home/profile/share/guile/site/3.0" 
"/run/current-system/profile/share/guile/site/3.0" 
"/gnu/store/s2cf4ibjw0g6npx0ia54x5xg6hzangn7-wolfsden/share/guile/site/3.0" 
"/gnu/store/czkzwa77lr39ayj016vhqrbhf2da2isr-nonguix/share/guile/site/3.0")>
      scheme@(guix-user)> ,lower $7
      $8 = #<derivation /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv => 
/gnu/store/7ylpw11r0sbdc2z02sir5gcr552dqks6-test 7f6c3606cb40>
      scheme@(guix-user)> ,build $8
      building /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv...
      successfully built /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv
      $9 = "/gnu/store/7ylpw11r0sbdc2z02sir5gcr552dqks6-test"
      scheme@(guix-user)> (system $9)
      $10 = 0

>
>
> On 21 May 2024 17:50:27 CEST, Tomas Volf <~@wolfsden.cz> wrote:
> >On 2024-05-21 17:33:24 +0200, Tristan Kohl via wrote:
> >> Hello Felix,
> >>
> >> my last message was not to critizise your help but rather my frustration 
> >> with my own limited progress. I really appreciate the help!
> >>
> >> program-file at least results in a usable thing however since the script 
> >> gets executed by smard I get the "command not found" in my logs. It seems 
> >> like curl is not in PATH for smartd. Do I need to import something into 
> >> the gexp?
> >>
> >> Also those env variables are defined by smartd during runtime depending on 
> >> which drive produced the error. Therefore I need shell expansion/env 
> >> variables and have to use system (without *) imho.
> >>
> >> This is the current state:
> >>
> >> (define-smartd-send-ntfy
> >>   (program-file "send-ntfy"
> >>     #~(system
> >>       (string-append "curl " "-H \"Title: $SMARTD_SUBJECT\" " ...))))
> >
> >Ignoring the obvious quoting issues here (what Felix does with `getenv' seems
> >much safer, and should produce the same result?),
> >
> >>
> >> Note: when using system* the error is:
> >> In execvp of curl: No such file or directory
> >
> >This should be solvable by using `file-append', so, basing on the system*
> >variant, something like:
> >
> >    #~(system* #$(file-append curl "/bin/curl") <other-arguments-here>)
> >
> >Should invoke curl by absolute path.  (You need import (gnu packages curl) of
> >course.)
> >
> >Hope this helps,
> >Tomas
> >
> >--
> >There are only two hard things in Computer Science:
> >cache invalidation, naming things and off-by-one errors.

Have a nice day,
Tomas

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

Attachment: signature.asc
Description: PGP signature


reply via email to

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