summaryrefslogtreecommitdiff
path: root/dotfiles/.dmd.d/init.scm
blob: 45d950c06ae13cbde2fa6f112bdc1d0154b92c2d (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
(use-modules (ice-9 match))

(define-syntax-rule (forever body ...)
  (while #t body ...))

(define-syntax-rule (with-fork body ...)
  (match (primitive-fork)
    (0 (begin body ...))
    (pid pid)))

(define (touch-file file)
  (close-port (open-file file "a0b")))

(define (run-command command)
  (zero? (status:exit-val (apply system* command))))

(define (make-system-constructor command)
  (lambda _
    (run-command command)))

(define (make-system-destructor command)
  (lambda _
    (not (run-command command))))

(define (simple-service program)
  (make <service>
    #:provides (list (string->symbol program))
    #:requires '()
    #:start (make-forkexec-constructor (list program))
    #:stop (make-kill-destructor)))

(define %home (getenv "HOME"))

(register-services
 ;; Emacs
 (make <service>
   #:provides '(emacs)
   #:requires '()
   #:start (make-system-constructor '("emacs" "--daemon"))
   #:stop (make-system-destructor '("emacsclient" "--eval" "(kill-emacs)")))
 ;; Customize X key bindings.
 (make <service>
   #:provides '(xmodmap)
   #:requires '()
   #:start (make-forkexec-constructor
            (list "xmodmap" (string-append %home "/.xmodmap"))))
 ;; GPG/SSH agent.
 (make <service>
   #:provides '(gpg-agent)
   #:requires '()
   #:start (make-system-constructor
            (list "gpg-agent" "--daemon" "--enable-ssh-support"
                  "--pinentry-program"
                  (string-append %home "/.guix-profile/bin/pinentry-gtk-2")))
   #:stop (make-system-destructor
           '("gpg-connect-agent" "killagent" "/bye")))
 ;; Mailbox sync.
 (make <service>
   #:provides '(offlineimap)
   #:requires '()
   #:start (lambda args
             (with-fork
              ;; OfflineIMAP's "autorefresh" mode consistently
              ;; consumes all of the RAM on my machine, so let's just
              ;; run it in a loop instead.
              (forever
               (system* "offlineimap")
               (sleep 20))))
   #:stop (make-kill-destructor))
 ;; FUSE
 (make <service>
   #:provides '(sshfs)
   #:requires '()
   #:start (make-forkexec-constructor
            (list "sshfs" "aigis:Music" (string-append %home "/Music"))))
 ;; Music.
 (make <service>
   #:provides '(mpd)
   #:requires '()
   #:start (lambda args
             (define (scope file)
               (string-append %home "/.config/mpd/" file))

             (unless (file-exists? (scope "playlists"))
               (mkdir (scope "playlists")))
             (touch-file (scope "database"))
             (fork+exec-command
              (list "mpd" (scope "mpd.conf")))))
 (simple-service "mpdscribble"))

;; Send dmd into the background
(action 'dmd 'daemonize)

;; Services to start when dmd starts:
(for-each start '(emacs xmodmap gpg-agent offlineimap sshfs mpd))