help-guix
[Top][All Lists]
Advanced

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

Re: Home service that serializes into an executable file


From: Tom Willemse
Subject: Re: Home service that serializes into an executable file
Date: Wed, 03 May 2023 23:56:17 -0700

Hey Mario!

Mario Forzanini <mf@marioforzanini.com> writes:

> Hello everyone!
>
> I've recently tried to write a simple home service that serializes into
> an ~/.xsession file. As someone pointed out in an older message on this
> list, this file has to be executable; I used to achieve this including
> an external file like: (local-file "xsession" #recursive? #t). Is there
> a procedure that allows changing permission bits while generating a file
> in the store?
>
> This is still in a rough state, but here is the definition of the
> service:

That looks nice :) much more interesting than my xsession home service,
which just joins a few strings together into an .xsession file.

I ran into this issue as well, and what I ended up doing was copying (I
think it was) mixed-text-file and modifying it for my own configuration.

I have:

    (define* (mixed-executable-file name #:key guile #:rest text)
      "Return an object representing store file NAME containing TEXT and having 
the
    executable bit set. TEXT is a sequence of strings and file-like objects, as 
in:
    
      (mixed-executable-file \"profile\"
                             \"export PATH=\" coreutils \"/bin:\" grep 
\"/bin\")"
      (define build
        (let ((text (if guile (drop text 2) text)))
          (gexp (call-with-output-file (ungexp output "out")
                  (lambda (port)
                    (set-port-encoding! port "UTF-8")
                    (display (string-append (ungexp-splicing text)) port)
                    (chmod port #o555))))))
    
      (computed-file name build #:guile guile))

Which really should be just like `mixed-text-file' except the call to
`chmod' has been added. And then I would use it just to replace the
`mixed-text-file'.

> <snip>
>     (define (xsession-file config)
>       (define dot-xsession
>         (mixed-executable-file "xsession"
>          "#!/bin/sh
>     try() {
>     pgrep -q $1 || $@ 2>> "
>          (xsession-serialize-field config 'log-file)
>          "\n}\n"
>          (xsession-serialize-field config 'programs)
>          (xsession-serialize-field config 'window-manager)))
>       `((".xsession" ,dot-xsession)))
> <snap>

I don't know if this is the best solution, but this worked for me.

Hopefully this helps!


Cheers,

Tom



reply via email to

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