From: Tom Willemse <tom@ryuslash.org>
To: Mario Forzanini <mf@marioforzanini.com>, help-guix <help-guix@gnu.org>
Subject: Re: Home service that serializes into an executable file
Date: Wed, 03 May 2023 23:56:17 -0700 [thread overview]
Message-ID: <875y98y48e.fsf@ryuslash.org> (raw)
In-Reply-To: <875yaktx6j.fsf@marioforzanini.com>
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
prev parent reply other threads:[~2023-05-04 7:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 20:53 Home service that serializes into an executable file Mario Forzanini
2023-05-04 6:56 ` Tom Willemse [this message]
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=875y98y48e.fsf@ryuslash.org \
--to=tom@ryuslash.org \
--cc=help-guix@gnu.org \
--cc=mf@marioforzanini.com \
/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.