Subject: [bug#77186] [PATCH v2 10/14] services: Add gitolite-git-configuration.

From: Tomas Volf <[email-masked]>
Date: Tue, 1 Apr 2025 00:10:16 +0200

In preparation for further customizability of the git configuration, extract
the current setup into a separate record type.

* gnu/services/version-control.scm (<gitolite-git-configuration>): New record
type.
(gitolite-git-configuration-compiler): And gexp compiler for it.
(<gitolite-configuration>): Add git-config field.
(gitolite-activation): Use it.
* doc/guix.texi (Version Control Services): Document both.

Change-Id: I7658698a93f938f62f41a4fa45b72de1eeb14414
---
 doc/guix.texi                    | 17 +++++++++++++++
 gnu/services/version-control.scm | 37 ++++++++++++++++++++++++++------
 2 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 299f84bb49..f2f9827cc0 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41009,6 +41009,10 @@ Version Control Services
 A ``file-like'' object (@pxref{G-Expressions, file-like objects}),
 representing the configuration for Gitolite.
 
+@item @code{git-config} (default: @code{(gitolite-git-configuration)})
+A ``file-like'' object (@pxref{G-Expressions, file-like objects}),
+representing the git configuration for Gitolite.
+
 @item @code{admin-pubkey} (default: @code{#f})
 A ``file-like'' object (@pxref{G-Expressions, file-like objects}) used to
 setup Gitolite.  This will be inserted in to the @file{keydir} directory
@@ -41084,6 +41088,19 @@ Version Control Services
 @end table
 @end deftp
 
+@deftp {Data Type} gitolite-git-configuration
+Data type representing the git configuration file for gitolite.
+
+@table @asis
+@item @code{name} (default: @code{"GNU GNU"})
+User name used for commits (e.g. during setting up the admin
+repository).
+
+@item @code{email} (default: @code{"guix@@localhost"})
+Email used for commits (e.g. during setting up the admin repository).
+
+@end table
+@end deftp
 
 @subsubheading Gitile Service
 
diff --git a/gnu/services/version-control.scm b/gnu/services/version-control.scm
index 268b0a47ee..dcdddf8078 100644
--- a/gnu/services/version-control.scm
+++ b/gnu/services/version-control.scm
@@ -67,6 +67,12 @@ (define-module (gnu services version-control)
             gitolite-rc-file-extra-content
             gitolite-rc-file-default-enable
 
+            <gitolite-git-configuration>
+            gitolite-git-configuration
+            gitolite-git-configuration?
+            gitolite-git-configuration-name
+            gitolite-git-configuration-email
+
             gitolite-service-type
 
             gitile-configuration
@@ -321,6 +327,23 @@ (define-gexp-compiler (gitolite-rc-file-compiler
              "# End:\n"
              "# vim: set syn=perl:\n"))))
 
+(define-record-type* <gitolite-git-configuration>
+  gitolite-git-configuration make-gitolite-git-configuration
+  gitolite-git-configuration?
+  (name gitolite-git-configuration-name
+        (default "GNU Guix"))
+  (email gitolite-git-configuration-email
+         (default "guix@localhost")))
+
+(define-gexp-compiler (gitolite-git-configuration-compiler
+                       (config <gitolite-git-configuration>) system target)
+  (match-record config <gitolite-git-configuration>
+                (name email)
+    (apply text-file* "gitconfig"
+           `("[user]\n"
+             "name  = " ,name  "\n"
+             "email = " ,email "\n"))))
+
 (define-record-type* <gitolite-configuration>
   gitolite-configuration make-gitolite-configuration
   gitolite-configuration?
@@ -334,6 +357,8 @@ (define-record-type* <gitolite-configuration>
                   (default "/var/lib/gitolite"))
   (rc-file        gitolite-configuration-rc-file
                   (default (gitolite-rc-file)))
+  (git-config     gitolite-configuration-git-config
+                  (default (gitolite-git-configuration)))
   (admin-pubkey   gitolite-configuration-admin-pubkey))
 
 (define (gitolite-accounts config)
@@ -352,7 +377,8 @@ (define (gitolite-accounts config)
 
 (define (gitolite-activation config)
   (match-record config <gitolite-configuration>
-                (package user group home-directory rc-file admin-pubkey)
+                ( package user group home-directory rc-file admin-pubkey
+                  git-config)
     #~(begin
         (use-modules (ice-9 match)
                      (guix build utils))
@@ -390,12 +416,9 @@ (define (gitolite-activation config)
 
           ;; Set the git configuration, to avoid gitolite trying to use
           ;; the hostname command, as the network might not be up yet
-          (with-output-to-file #$(string-append home-directory "/.gitconfig")
-            (lambda ()
-              (display "[user]
-        name = GNU Guix
-        email = guix@localhost
-")))
+          (copy-file #$git-config
+                     #$(string-append home-directory "/.gitconfig"))
+
           ;; Run Gitolite setup, as this updates the hooks and include the
           ;; admin pubkey if specified. The admin pubkey is required for
           ;; initial setup, and will replace the previous key if run after
-- 
2.49.0