~ruther/guix-config

60fb3c8d3ded7e1bafac2d68cbcd1d19a56f5443 — Rutherther 7 months ago 1636aa9
feat(home): add support for resetting no longer managed dconf keys
1 files changed, 57 insertions(+), 12 deletions(-)

M home/modules/ruther/home/services/dconf.scm
M home/modules/ruther/home/services/dconf.scm => home/modules/ruther/home/services/dconf.scm +57 -12
@@ 37,21 37,66 @@ the values in there refer to values to set, ie. cursor-theme='my-pretty-cursors'
  (program-file
   "update-dconf-settings"
   #~(begin
       (define (get-dconf-keys config)
         (apply
          append
          (apply
           append
           (map
            (lambda (section)
              (let ((section-name (symbol->string (car section))))
                (map
                 (lambda (section-fields)
                   (map
                    (lambda (section-field)
                      (string-append "/" section-name "/" (symbol->string (car section-field))))
                    section-fields))
                 (cdr section))))
            config))))

       (define (get-deleted-dconf-keys old-config new-config)
         (let ((old-keys (get-dconf-keys old-config))
               (new-keys (get-dconf-keys new-config)))
           (filter
            (lambda (key)
              (not (member key new-keys)))
            old-keys)))

       (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))

       (let* ((dconf #$(file-append dconf "/bin/dconf"))

              (new-home (getenv "GUIX_NEW_HOME"))
              (old-home (getenv "GUIX_OLD_HOME"))
              (new-home-dconf-file (string-append new-home "/" #$home-dconf-settings-file))
              (old-home-dconf-file (when old-home
                                       (string-append old-home "/" #$home-dconf-settings-file)))
              (new-dconf-settings (with-input-from-file new-home-dconf-file read))
              (old-dconf-settings (if old-home-dconf-file
                                      (with-input-from-file old-home-dconf-file read)
                                      '()))

              (deleted-dconf-keys (get-deleted-dconf-keys old-dconf-settings new-dconf-settings))

              (dconf-ini #$(apply string-append
                                  (serialize-ini-config dconf-config
                                                        #:equal-string "="))))
         ;; Remove settings that are not managed anymore
         ;;  TODO
         (display "Removing old dconf keys...")
         (newline)
         (for-each
          (lambda (deleted-key)
            (system* dconf "reset" deleted-key))
          deleted-dconf-keys)
         ;; Load the dconf settings
         (let ((dconf-load-pipe (open-output-pipe (string-append #$(file-append dconf "/bin/dconf")
         (display "Loading dconf...")
         (newline)
         (let ((dconf-load-pipe (open-output-pipe (string-append dconf
                                                                 " load /"))))
           (display dconf-ini dconf-load-pipe)
           (close-pipe dconf-load-pipe))))))
           (close-pipe dconf-load-pipe))
         (display "Configured dconf.")
         (newline)))))

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


@@ 64,15 109,15 @@ the values in there refer to values to set, ie. cursor-theme='my-pretty-cursors'
                 "dconf-settings.scm"
                 #~(call-with-output-file #$output
                     (lambda (port)
                       (display '#$(home-dconf-configuration-config config) port)))))))))
                       (write '#$(home-dconf-configuration-config config) port)))))))))

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

(define home-dconf-service-type
  (service-type

Do not follow this link