aboutsummaryrefslogtreecommitdiff
path: root/tw/services/git.scm
blob: 168301a5b665c39539838b901993ee3e1d56d2f5 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(define-module (tw services git)
  #:use-module (gnu)
  #:use-module (gnu home services)
  #:use-module (gnu packages terminals)
  #:use-module (gnu packages version-control)
  #:use-module (gnu services configuration)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module ((guix records) #:select (match-record))
  #:use-module (srfi srfi-1)
  #:export (home-git-identity
            home-git-configuration
            home-git-service-type))

(define-configuration/no-serialization home-git-identity
  (name string "Short slug identifying this identity.  Only used to name config files.")
  (root-directory string "Directory under which this identity should apply.")
  (email string "Author commits as this email for this identity.")
  (signing-key string "Sign commits using this key for this identity."))

(define (list-of-identities? thing)
  (and (list? thing) (every home-git-identity? thing)))

(define-configuration/no-serialization home-git-configuration
  (default-email string "Author git commits as this email.")
  (default-signing-key string "Sign git commits using this email.")
  (identities (list-of-identities '()) "Override default configuration values
under specific directories, e.g. to use a work identity in a directory
containing work projects."))

(define (gitconfig-includes identities)
  (if (null? identities) '()
      (cons (match-record (car identities) <home-git-identity> (name root-directory)
              ;; A relative path is relative to the gitconfig file.
              (format #f "[includeIf \"gitdir:~a/**\"]\n\tpath = ~aconfig"
                      (string-trim-right root-directory #\/) name))
            (gitconfig-includes (cdr identities)))))

(define (gitconfig-otherfiles identities)
  (if (null? identities) '()
      (cons (match-record (car identities) <home-git-identity> (name email signing-key)
              (list
               (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 (cdr identities)))))

(define (gitconfig config)
  (match-record config <home-git-configuration> (default-email default-signing-key identities)
    `(,@(gitconfig-otherfiles identities)
      ("git/config" ,(mixed-text-file "gitconfig" "\
# This is Git's per-user configuration file.
[user]
	name = Timo Wilken
	email = " default-email "
	signingkey = " default-signing-key
        (string-join (gitconfig-includes identities) "\n" 'prefix) "
[commit]
	gpgsign = true
[url \"ssh://git@gitlab.cern.ch:7999/\"]
	insteadOf = https://gitlab.cern.ch/
[url \"ssh://git@ssh.github.com/\"]
	insteadOf = gh:
[gui]
	fontui = -family \\\"Fira Sans\\\" -size 10 -weight normal -slant roman -underline 0 -overstrike 0
	fontdiff = -family \\\"Hermit\\\" -size 10 -weight normal -slant roman -underline 0 -overstrike 0
	tabsize = 4
[merge]
	summary = true
	conflictstyle = diff3
[color]
	ui = auto
[pull]
	rebase = false
	ff = only
[alias]
	glog = log --decorate --graph --oneline
	plog = log --decorate --graph --oneline --pretty=tformat:\\\"%C(yellow)%h %Cgreen%as %Cblue%<(10,trunc)%an%Cred%d%Creset %s\\\"
[init]
	defaultBranch = master
[advice]
	detachedHead = false
	addEmptyPathspec = false
# https://sw.kovidgoyal.net/kitty/kittens/diff/
[diff]
	tool = kitty
	guitool = kitty.gui
[difftool]
	prompt = false
	trustExitCode = true
[difftool \"kitty\"]
	cmd = " kitty "/bin/kitty +kitten diff $LOCAL $REMOTE
[difftool \"kitty.gui\"]
	cmd = " kitty "/bin/kitty " kitty "/bin/kitty +kitten diff $LOCAL $REMOTE
")))))

(define home-git-service-type
  (service-type
   (name 'git)
   (extensions
    (list (service-extension home-xdg-configuration-files-service-type gitconfig)))
   (description "Configure Git.")))