Hello everyone,

I was trying to understand how to use `define-configuration` with some
practice and couldn't understand what goes wrong.

It took for example to write a `luanti-game-configuration` that could,
when serialized, generate a configuration file for the Luanti server. I
only started with 1 parameter.

When I try to serialize a configuration instance to a file, the content
of this file is empty.

Here is the code defining my `luanti-game-configuration`:


    ;; -*- mode: scheme; -*-
    ;; Luanti game configuration
    
    (use-modules (gnu services configuration)
                 (guix gexp))
    
    ;; Define the maybe string
    (define-maybe string)
    
    
    ;; Define serializer functions
    (define (serialize-luanti-admin-name field-name value)
      "Serialize the Luanti admin name field for the config file."
      (let ((field-real-name "name"))
        #~(string-append #$field-real-name " = " #$value)))
    
    ;; Define the Luanti Game configuration 
    (define-configuration luanti-game-configuration
      (admin-name
       maybe-string
       "Username of the administrator."
       (serializer serialize-luanti-admin-name)))
    
    ;; Define Luanti game configuration file generator
    (define (minetest.conf config)
      "Return the Luanti config file."
      (plain-file "minetest.conf"
       (with-output-to-string
         (lambda ()
           (serialize-configuration
            config
            luanti-game-configuration-fields)))))


After I evaluate this on the `guix repl`, I create an instance of my new config
and serialize it to a file object doing like this:

    (define test
      (luanti-game-configuration
       (admin-name "mememe")))
    (minetest.conf test)


The REPL return me this:

    $7 = #<<plain-file> name: "minetest.conf" content: "" references: ()>


As reference, I based my practical test code on what I could read on
some system services code and on the actual devel manual:
https://guix.gnu.org/manual/devel/en/html_node/Complex-Configurations.html

What did I miss ?



Best regards

-------
Gendre Sébastien

Reply via email to