all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Liliana Marie Prikler <liliana.prikler@gmail.com>
To: "Andrew Tropin" <andrew@trop.in>,
	guix-devel@gnu.org, "Oleg Pykhalov" <go.wigust@gmail.com>,
	"Ludovic Courtès" <ludo@gnu.org>
Cc: Xinglu Chen <public@yoctocell.xyz>, guix-maintainers@gnu.org
Subject: Re: Return back original implementation for text-config serialization
Date: Sun, 09 Jan 2022 20:44:46 +0100	[thread overview]
Message-ID: <888e529cb04bb74bfd98f8e07db0c522efee9251.camel@gmail.com> (raw)
In-Reply-To: <871r1g4x6e.fsf@trop.in>

Hi,

Am Sonntag, dem 09.01.2022 um 20:48 +0300 schrieb Andrew Tropin:
> On 2022-01-09 12:19, Liliana Marie Prikler wrote:
> 
> > Hi Andrew,
> > 
> > Am Sonntag, dem 09.01.2022 um 12:12 +0300 schrieb Andrew Tropin:
> > 
> > > Before fee0bc serialization for text-config worked this way:
> > > --8<---------------cut here---------------start------------->8---
> > > `("string here"
> > >   ,#~"string valued gexp"
> > >   "source \"
> > >   ,(local-file "blabla.sh"))
> > > --8<---------------cut here---------------end--------------->8---
> > > 
> > > would yield something like:
> > > 
> > > --8<---------------cut here---------------start------------->8---
> > > string here
> > > string valued gexp
> > > source \
> > > /gnu/store/00fl96dj2aak4i1vqvdqzlhbmmskc7fx-blabla.sh
> > > --8<---------------cut here---------------end--------------->8---
> > > 
> > > [...]
> > > 
> > > The new text-config serialization implementation (after fee0bc
> > > commit) doesn't support gexps and tries to insert the literal
> > > content
> > > of the file in place where file-like object was used[.]
> > I agree that the old one looks nicer in this context, but wasn't
> > the new one introduced to solve the issue of (slurp-file-gexp) in
> > the importer?  Meaning whichever way we go, we need something that
> > allows us to insert literal file contents of another file at more
> > or less G- exp compile time.
> > 
> 
> From my experience the usage of slurp-file-gexp is somewhat really
> rare, so I didn't upstream it originally, keeping in mind that it is
> possible to use the gexp mentioned below directly and that later we
> can add slurp-file-gexp or alternative if necessary.  Just missed
> that importer already uses it.
> 
> We could just do something like that instead of slurp-file-gexp:
> --8<---------------cut here---------------start------------->8---
> #~(call-with-input-file #$(local-file "./files/bashrc")
>     (@ (ice-9 textual-ports) get-string-all))
> --8<---------------cut here---------------end--------------->8---
> 
> Or just take the implementation
> https://git.sr.ht/~abcdw/rde/tree/47f6c65c82a4f6761fa1ff5b9405b363cfda6482/gnu/home-services-utils.scm#L90
> and rename it to read-file-content-gexp or somewhat more apropriate
> and use it.
Using ill-defined slurp-patterns at all just adds ways of shooting
yourself in the foot.  You're turning Guix into an ouroboros that reads
itself inside-out.  Better restrict such patterns to where they cause
the least harm and make their effects very explicit.

> > Perhaps that issue could be solved, if instead the importer just
> > reads the file contents and declares it as a variable as in (define
> > %bashrc " ;; Original contents of bashrc ") (define bashrc (plain-
> > file %bashrc)).
> > 
> > WDYT?
> 
> Another possible solution, but I would prefer to stick with the
> direct usage of gexp with the code for reading a file, because
> importer is intended for creation of an example configuration and
> user will need to continue the work on it and copying the content of
> bashrc and other configs to scheme files, escaping string can be a
> little tedious.
There is certainly a tradeoff here, but I think explicitly showing
(plain-file CONTENT) is the right approach here.  Users are going to
figure out mixed-text-file exists soon enough.  As for proper string
escaping, that's not really an excuse imo -- pretty-print exists and
you can use it. 

> read-everything-from-file is just a shorthand for
> 
> --8<---------------cut here---------------start------------->8---
> #~(begin
>     (use-modules (ice-9 rdelim))
>     (with-fluids ((%default-port-encoding "UTF-8"))
>       (with-input-from-file #$COMPUTED_FILE_CALL_HERE read-string)))
> --8<---------------cut here---------------end--------------->8---
> 
> a gexp used in
> https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/configuration.scm?h=2c451db39aabc69bdbf186f412ee6e0b4e180ccb#n386
> 
> The example was already verbose, so I decided to simplify it a little
> bit.
> 
> Actually, it's very similar to what slurp-file-gexp does, but it's
> moved inside serializer and hidden from user.  Why not to give it to
> the user and eleminate two more layers of wrapping in gexps and file-
> likes.
That's like saying "memory management already exists, but it's hidden
from the user, why not let them play around with malloc?"  In
programming languages that aren't C/C++, abstractions ought to make it
harder to shoot yourself in the foot.  You (in my POV correctly)
pointed out that our current handling of text configs makes it very
easy to shoot yourself in the foot and is therefore badly abstracted. 
The point I'm making is that we shouldn't swap out one bad abstraction
for another, but pave the road towards good abstractions, e.g. G-
expressions in the way the rest of Guix typically uses them.

Now one thing I had not considered back in my previous mail was that we
want to be able to compose bashrc together from multiple sources, so
having the field be just one file-like object probably won't cut it. 
However, we can let it be a list of file like objects (with a field
sanitizer transparently turning a single file-like object into a list
either silently or loudly).  And within those file-like objects, we can
use the usual semantics.

I'm not sure how the current implementation of Guix Home handles
composition, but I believe the root of the issue probably stems from
there in some capacity.  Might want to check what our requirements are.


Cheers


  reply	other threads:[~2022-01-09 19:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-09  9:12 Return back original implementation for text-config serialization Andrew Tropin
2022-01-09 11:19 ` Liliana Marie Prikler
2022-01-09 17:48   ` Andrew Tropin
2022-01-09 19:44     ` Liliana Marie Prikler [this message]
2022-01-10  9:49       ` Andrew Tropin
2022-01-10 20:12         ` Liliana Marie Prikler
2022-01-12 15:05           ` Andrew Tropin
2022-01-09 12:17 ` Maxime Devos
2022-01-09 12:19 ` Maxime Devos
2022-01-09 17:59   ` Andrew Tropin
2022-01-09 19:00     ` Maxime Devos
2022-01-18 14:26 ` Ludovic Courtès
2022-01-20 13:20   ` Andrew Tropin
2022-01-21  9:30     ` Maxime Devos
2022-01-26  8:34       ` Andrew Tropin
2022-01-27  5:04         ` Maxim Cournoyer
2022-01-28 15:48           ` Andrew Tropin
2022-02-05 11:09           ` Ludovic Courtès
2022-02-13 14:14             ` Andrew Tropin
2022-01-26  8:36       ` Andrew Tropin
2022-02-05 11:34         ` Maxime Devos
2022-02-13 14:09           ` Andrew Tropin
2022-01-24 15:37     ` Ludovic Courtès
2022-01-26  9:11       ` Andrew Tropin
2022-01-26  9:21         ` Andrew Tropin
2022-02-05 14:43     ` Xinglu Chen

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=888e529cb04bb74bfd98f8e07db0c522efee9251.camel@gmail.com \
    --to=liliana.prikler@gmail.com \
    --cc=andrew@trop.in \
    --cc=go.wigust@gmail.com \
    --cc=guix-devel@gnu.org \
    --cc=guix-maintainers@gnu.org \
    --cc=ludo@gnu.org \
    --cc=public@yoctocell.xyz \
    /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.