help-guix
[Top][All Lists]
Advanced

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

Re: how to use a variable in a plain-file object?


From: Giovanni Biscuolo
Subject: Re: how to use a variable in a plain-file object?
Date: Fri, 17 May 2024 10:45:39 +0200

Hello raingloom

thank you for you quick reply!

raingloom@riseup.net writes:

[...]

> 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've tested it with this code:

--8<---------------cut here---------------start------------->8---

(use-modules (guix gexp))

(define var1 "var1-value")
(define var2 "var2-value")

(define %another-file-object
  #~(begin (with-output-to-file #$output (lambda _ (write (string-append "\
# This is an example configuration file
# stored in %another-file-object
attribute1 = " #$var1 "
attribute2 = " #$var2 "
"))))))

%another-file-object

--8<---------------cut here---------------end--------------->8---

And this is the result:

--8<---------------cut here---------------start------------->8---

[~/tmp]
giovanni@roquette [genv]\: cat $(guix build --no-offload -e '(load 
"guix-output-to-file-example.scm")')
"# This is an example configuration file\n# stored in 
%another-file-object\nattribute1 = var1-value\nattribute2 = var2-value\n"

--8<---------------cut here---------------end--------------->8---

The output cannot be used in place of %my-file-object, right?

AFAIU the solution is to use mixed-text-file as suggested by Tomas Volf
yesterday in this thread.

Happy hacking! Gio'

[...]

-- 
Giovanni Biscuolo

Xelera IT Infrastructures

Attachment: signature.asc
Description: PGP signature


reply via email to

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