[bug#77352,v2] home: services: define hyprland home service

Message ID 88ab5741-089a-4cd3-bad5-e4cac1f039ef@icloud.com
State New
Headers
Series [bug#77352,v2] home: services: define hyprland home service |

Commit Message

Andrew Wong March 31, 2025, 1:14 a.m. UTC
  Hello,
I've suggested some small changes which I've attached as patches. I also 
have some questions and comments:

On 3/30/25 1:11p, Carmine Margiotta wrote:> +;;; Gexp executables will 
be serialized on a program-file
> +(define (serialize-executable name value)
> +  (if (string? value) value
> +      (program-file (symbol->string name) value
> +                    #:module-path %load-path))
How will you serialize g-expressions? It seems that they are to be added 
to the store as scripts with 'program-file', but I can't figure out how 
to extract the file path from the resulting object; I tried in a REPL, 
program-file objects cannot be used as strings like this function seems 
to suggest, and none of the their properties seem to clearly give their 
location in the store.

Also, how are you testing your work? I asked in the IRC channel and they 
suggested spooling up a VM via 'guix system vm' with an operating-system 
definition containing the experimental service, but perhaps you have 
your own method.
  

Comments

Carmine Margiotta March 31, 2025, 8:14 p.m. UTC | #1
Hello Andrew,
thank you for your patches!

On 3/31/25 03:14, Andrew Wong wrote:
> How will you serialize g-expressions? It seems that they are to be added 
> to the store as scripts with 'program-file', but I can't figure out how 
> to extract the file path from the resulting object; I tried in a REPL, 
> program-file objects cannot be used as strings like this function seems 
> to suggest, and none of the their properties seem to clearly give their 
> location in the store.

As stated in the define-configuration documentation[1], serialization 
procedures should return strings or g-expressions; in case of 
program-file a g-expression that will ungexp to the script's path will 
be returned and the result will be something like:
"exec = /gnu/store/h98yjz6b2rhmxr48c11cy84d3nwf6a7x-exec"

> Also, how are you testing your work? I asked in the IRC channel and they 
> suggested spooling up a VM via 'guix system vm' with an operating-system 
> definition containing the experimental service, but perhaps you have 
> your own method.

This matches my current workflow perfectly. I used to develop this 
service directly in my system configuration, but that wasn’t the best 
way to test this kind of code. Using a VM is actually pretty 
straightforward! If you need anything about that, feel free to ask me.

[1] https://guix.gnu.org/manual/en/html_node/Complex-Configurations.html
  

Patch

From 70dd0149f777eae9f4ea4a4c7d92ca058b1e76bf Mon Sep 17 00:00:00 2001
Message-ID: <70dd0149f777eae9f4ea4a4c7d92ca058b1e76bf.1743381801.git.wongandj@icloud.com>
In-Reply-To: <0d2c72441d9b4a94aded6d53028d63b253f5e7ae.1743381801.git.wongandj@icloud.com>
References: <0d2c72441d9b4a94aded6d53028d63b253f5e7ae.1743381801.git.wongandj@icloud.com>
From: Andrew Wong <wongandj@icloud.com>
Date: Sun, 30 Mar 2025 17:20:31 -0400
Subject: [PATCH 5/5] home: services: hyprland: Localize 'indent'

home: services: hyprland(serialize-block-entry): Localize 'indent'.
home: services: hyprland(indent): Delete.
home: services: hyprland(repeat): Delete.
Change-Id: Id36e4eac964bf424ac4f8e2b411d69da402d9b5b
---
 gnu/home/services/hyprland.scm | 52 +++++++++++-----------------------
 1 file changed, 16 insertions(+), 36 deletions(-)

diff --git a/gnu/home/services/hyprland.scm b/gnu/home/services/hyprland.scm
index cade4402ac..36e5ae951a 100644
--- a/gnu/home/services/hyprland.scm
+++ b/gnu/home/services/hyprland.scm
@@ -42,23 +42,6 @@  (define-module (home home services hyprland)
 ;;;
 ;;; Code:
 
-;;;
-;;; Helper functions.
-;;;
-
-;;; Repeat v n times
-(define (repeat v n)
-  (if (eq? n 0)
-      '()
-      `(,v ,@(repeat v
-                     (- n 1)))))
-
-;;; Generate an indenter string of n tabs
-(define (indent tabs)
-  (if (<= tabs 0) ""
-      (apply string-append
-             (repeat "\t" tabs))))
-
 ;;;
 ;;; Definition of configurations.
 ;;;
@@ -242,25 +225,22 @@  (define (serialize-block-entry value tabs)
          (() "")
          (((? symbol? name)
            value)
-          (string-append
-           (indent tabs)
-           (symbol->string name)
-           (match value
-             ((? string? v)
-              (string-append " = " v))
-             ((? number? v)
-              (string-append " = "
-                             (number->string v)))
-             ((? boolean? v)
-              (if v " = true" " = false"))
-             ((? block-entries? v)
-              (string-append
-               " {\n"
-               (serialize-block-entries
-                #f v
-                (+ tabs 1))
-               (indent tabs) "}")))
-           "\n"))
+          (let (indent (make-string (max 0 tabs) #\tab))
+            (string-append
+             (indent tabs)
+             (symbol->string name)
+             (match value
+               ((? string? v)
+                (string-append " = " v))
+               ((? number? v)
+                (string-append " = " (number->string v)))
+               ((? boolean? v)
+                (if v " = true" " = false"))
+               ((? block-entries? v)
+                (string-append " {\n"
+                               (serialize-block-entries #f v (+ tabs 1))
+                               (indent tabs) "}")))
+             "\n")))
          ((_)
           #f)) "\n")))
 
-- 
2.49.0