all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: raingloom@riseup.net
To: Giovanni Biscuolo <g@xelera.eu>
Cc: help-guix@gnu.org
Subject: Re: how to use a variable in a plain-file object?
Date: Thu, 16 May 2024 16:15:21 +0000	[thread overview]
Message-ID: <77eb920ccc94157785c38a49db5bceb0@riseup.net> (raw)
In-Reply-To: <87le493g1o.fsf@xelera.eu>

On 2024-05-16 17:57, Giovanni Biscuolo wrote:
> Hello,
> 
> sorry for the very guile-absolute-beginner question, but I'd like to use
> a declared variable in a plain-file object, so I can write something
> like in this pseudo-code snippet:
> 
> --8<---------------cut here---------------start------------->8---
> 
> (define variable1 "var1-value")
> (define variable2 "var2-value")
> 
> [...]
> 
> (define %my-file-object
>   ,(plain-file "something.conf" "
> # This is an example configuration file
> 
> attribute1 =" variable1 " 
> 
> attribute2 =" variable2 "
> 
> "))
> 
> --8<---------------cut here---------------end--------------->8---
> 
> and obtain a "something.conf" file like this:
> 
> --8<---------------cut here---------------start------------->8---
> # This is an example configuration file
> 
> attribute1 = var1-value
> 
> attribute2 = var2-value
> 
> --8<---------------cut here---------------end--------------->8---
> 
> how can I do, please?
> 
> Thanks, Gio'

You probably want a G-expression.

Short untested example:

(define name "Giovanni")
(define greeting-gexp
  #~(begin (with-output-to-file #$output (lambda _ (write (string-append
"Hello, " #$name "!"))))))

You should be able to use greeting-gexp in place of %my-file-object.

I highly recommend reading the relevant docs in Guix's info pages.
Online version:
https://guix.gnu.org/manual/en/html_node/G_002dExpressions.html
Related blog post:
https://guix.gnu.org/en/blog/2023/dissecting-guix-part-3-g-expressions/


  reply	other threads:[~2024-05-16 16:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-16 15:57 how to use a variable in a plain-file object? Giovanni Biscuolo
2024-05-16 16:15 ` raingloom [this message]
2024-05-17  8:45   ` Giovanni Biscuolo
2024-05-16 18:39 ` Tomas Volf
2024-05-17  8:24   ` Giovanni Biscuolo

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=77eb920ccc94157785c38a49db5bceb0@riseup.net \
    --to=raingloom@riseup.net \
    --cc=g@xelera.eu \
    --cc=help-guix@gnu.org \
    /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.