~ruther/guix-config

35d988f13f2f28e304a1199da7412bacbbbe85c6 — Rutherther 7 months ago de40635
feat(home): add base dconf service
1 files changed, 88 insertions(+), 0 deletions(-)

A home/modules/ruther/home/services/dconf.scm
A home/modules/ruther/home/services/dconf.scm => home/modules/ruther/home/services/dconf.scm +88 -0
@@ 0,0 1,88 @@
(define-module (ruther home services dconf)
  #:use-module (guix gexp)
  #:use-module (guix modules)
  #:use-module (guix monads)
  #:use-module (guix store)

  #:use-module (gnu packages gnome)
  #:use-module (gnu services)
  #:use-module (gnu services configuration)
  #:use-module (gnu home services)

  #:use-module (srfi srfi-1)

  #:use-module (rde serializers ini)

  #:export (home-dconf-configuration
            home-dconf-service-type))

;; The state will be a scm file.
;; Create a file under the home folder that will

(define-configuration home-dconf-configuration
  (dconf (file-like dconf) "The dconf package to use for loading environment")
  (config
   (ini-config '())
   "The configuration of dconf to load. Stuff that's not
declared here is not touched. The stuff that was declared in previous
generation, and got removed, will also be removed from dconf.

The config is fed into dconf load. The ini sections should point to the
location in dconf settings, ie. org/gnome/desktop/interface, and
the values in there refer to values to set, ie. cursor-theme='my-pretty-cursors'."))

(define home-dconf-settings-file "state/dconf-settings.scm")

(define (update-dconf-settings-script dconf dconf-config)
  (program-file
   "update-dconf-settings"
   #~(begin
       (use-modules (ice-9 popen))
       (let* ((new-home (getenv "GUIX_NEW_HOME"))
              ;; (old-home (getenv "GUIX_OLD_HOME"))
              ;; (home-dconf-file (string-append new-home "/" #$home-dconf-settings-file))
              ;; (dconf-settings (with-input-from-file home-dconf-file read))
              (dconf-ini #$(apply string-append
                                  (serialize-ini-config dconf-config
                                                        #:equal-string "="))))
         ;; Remove settings that are not managed anymore
         ;;  TODO
         ;; Load the dconf settings
         (let ((dconf-load-pipe (open-output-pipe (string-append #$(file-append dconf "/bin/dconf")
                                                                 " load /"))))
           (display dconf-ini dconf-load-pipe)
           (close-pipe dconf-load-pipe))))))

(define (dconf-activation config)
  #~(primitive-load #$(update-dconf-settings-script (home-dconf-configuration-dconf config)
                                                    (home-dconf-configuration-config config))))

(define (dconf-entry config)
  (with-monad %store-monad
    (return `((,home-dconf-settings-file
               ,(computed-file
                 "dconf-settings.scm"
                 #~(call-with-output-file #$output
                     (lambda (port)
                       (display '#$(home-dconf-configuration-config config) port)))))))))

(define (home-dconf-extensions original-config fields)
  (home-dconf-configuration
   (inherit original-config)
   (config
    `(,(append
        (home-dconf-configuration-config original-config)
        (apply append fields))))))

(define home-dconf-service-type
  (service-type
   (name 'home-dconf)
   (description "A service to populate dconf settings by given configuration.")
   (extend home-dconf-extensions)
   (compose concatenate)
   (extensions
    (list (service-extension home-service-type
                             dconf-entry)
          (service-extension home-activation-service-type
                             dconf-activation)))
   (default-value (home-dconf-configuration))))

Do not follow this link