summaryrefslogtreecommitdiff
path: root/tw/home.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tw/home.scm')
-rw-r--r--tw/home.scm42
1 files changed, 37 insertions, 5 deletions
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
-"))
+")))))