From 506d9e9f98ac498389f6c2428c760bf0819c32d7 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Mon, 24 Jul 2023 13:12:11 +0200 Subject: Fix git work identity config The work gitconfig wasn't getting applied. Explicitly include it in the main gitconfig in an extensible way. --- tw/home.scm | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'tw/home.scm') diff --git a/tw/home.scm b/tw/home.scm index 754fb008..584907ae 100644 --- a/tw/home.scm +++ b/tw/home.scm @@ -1,4 +1,5 @@ (define-module (tw home) + #:use-module (ice-9 match) #:use-module (ice-9 string-fun) #:use-module (gnu) #:use-module (gnu home services) @@ -571,13 +572,44 @@ auto-expand-secmem (gnupg-services #:gui-pinentry? #t))) -(define-public (gitconfig email signing-key) - (mixed-text-file "gitconfig" "\ +(define gitconfig-includes + (match-lambda + (() '()) + (((name path _ _) rest ...) + ;; The relative path is relative to the gitconfig file. + (cons (format #f "[includeIf \"gitdir:~a/**\"]\n\tpath = ~aconfig" + (string-trim-right path #\/) name) + (gitconfig-includes rest))) + ((id rest ...) + (cons (format #f "# warning: ignored malformed identity: ~s" id) + (gitconfig-includes rest))))) + +(define gitconfig-otherfiles + (match-lambda + (() '()) + (((name _ email signing-key) rest ...) + `((,(string-append "git/" name "config") + ,(plain-file (string-append "git" name "config") + (string-append + "[user]\n" + (if email (string-append "\temail = " email "\n") "") + (if signing-key (string-append "\tsigningkey = " signing-key "\n") "")))) + ,@(gitconfig-otherfiles rest))) + ((id rest ...) + (format (current-error-port) "warning: ignored malformed gitconfig identity: ~s~%" id) + (gitconfig-otherfiles rest)))) + +(export gitconfig) +(define* (gitconfig default-email default-signing-key #:rest identities) + (simple-service 'gitconfig home-xdg-configuration-files-service-type + `(,@(gitconfig-otherfiles identities) + ("git/config" ,(mixed-text-file "gitconfig" "\ # This is Git's per-user configuration file. [user] name = Timo Wilken - email = " email " - signingkey = " signing-key " + email = " default-email " + signingkey = " default-signing-key + (string-join (gitconfig-includes identities) "\n" 'prefix) " [commit] gpgsign = true [url \"ssh://git@gitlab.cern.ch:7999/\"] @@ -615,4 +647,4 @@ auto-expand-secmem cmd = " kitty "/bin/kitty +kitten diff $LOCAL $REMOTE [difftool \"kitty.gui\"] cmd = " kitty "/bin/kitty " kitty "/bin/kitty +kitten diff $LOCAL $REMOTE -")) +"))))) -- cgit v1.2.3