~ruther/guix-config

ff76e3e69aedbcaf9d02c4a591ebb5d2d0e41418 — Rutherther 7 months ago 49b1433
feat: add cursor and icon themes gtk service support
M home/home-configuration.scm => home/home-configuration.scm +16 -3
@@ 87,10 87,23 @@
                                                   "bash_profile")))))

         (service home-gtk-service-type
                  (let ((theme (make-graphite-gtk-theme #:theme "orange" #:color "dark")))
                  (let ((gtk-theme (make-graphite-gtk-theme #:theme "orange" #:color "dark"))
                        (icon-theme (make-tela-circle-icon-theme #:variant "orange"))
                        (cursor-theme (make-catppuccin-cursors #:flavor "frappe" #:accent "sapphire")))
                    (home-gtk-configuration
                     (theme-package theme)
                     (theme-name (assoc-ref (package-properties theme) 'theme-name))
                     (gtk-theme
                      (gtk-theme-configuration
                       (package gtk-theme)
                       (name (assoc-ref (package-properties gtk-theme) 'theme-name))))
                     (cursor-theme
                      (gtk-theme-configuration
                       (package cursor-theme)
                       (name (assoc-ref (package-properties cursor-theme) 'cursor-theme-name))
                       (size 16)))
                     (icon-theme
                      (gtk-theme-configuration
                       (package icon-theme)
                       (name (assoc-ref (package-properties icon-theme) 'dark-icon-theme-name))))
                     (font-name "Ubuntu 12"))))

         (service home-zsh-service-type

M home/modules/ruther/home/services/gtk.scm => home/modules/ruther/home/services/gtk.scm +104 -62
@@ 3,83 3,122 @@
  #:use-module (gnu services)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module (guix build-system trivial)
  #:use-module (gnu home services)
  #:export (home-gtk-configuration
            gtk-theme-configuration
            home-gtk-service-type))

(define (serialize-string name value)
  (format #f "~a=~a~%" name value))
;; So... it will make the gtk files
;;
;; ~/.gtkrc-2.0
(define (maybe-string? str)
  (or (nil? str)
      (string? str)))
(define (maybe-package? pkg)
  (or (nil? pkg)
      (package? pkg)))

;; gtk-icon-theme-name = theme-name
;; gtk-theme-name = theme-name
;; gtk-font-name = font-name
(define-configuration/no-serialization gtk-theme-configuration
  (package (maybe-package #f) "The package to add to profile, including theme {name}")
  (name (maybe-string #f) "Name of the theme")
  (size (integer 16) "Size of the pointer. Applies only for cursor-theme"))

(define-configuration/no-serialization home-gtk-configuration
  (gtk-theme
   (gtk-theme-configuration (gtk-theme-configuration))
   "The theme")
  (icon-theme
   (gtk-theme-configuration (gtk-theme-configuration))
   "The icon theme")
  (cursor-theme
   (gtk-theme-configuration (gtk-theme-configuration))
   "The cursor theme")
  (font-name
   (maybe-string #f)
   "Name of the font to use"))

;; $XDG_CONFIG_HOME/gtk-3.0/settings.ini

;; [Settings]
;; gtk-icon-theme-name = theme-name
;; gtk-theme-name = theme-name
;; gtk-font-name = font-name
;; (gtk-config-file )

(define (gtk2-config-file name theme font)
  `(,name
    "gtk-icon-theme-name = \"" ,theme "\"\n"
    "gtk-theme-name = \"" ,theme "\"\n"
    "gtk-font-name = \"" ,font "\"\n"))
(define* (serialize-field name value #:key (gtk2? #f))
  (if gtk2?
      (format #f "~a = \"~a\"~%" name value)
      (format #f "~a = ~a~%" name value)))

(define (gtk-config-file name prefix theme font)
  `(,name
    "[Settings]\n"
    "gtk-icon-theme-name = " ,theme "\n"
    "gtk-theme-name = " ,theme "\n"
    "gtk-font-name = " ,font "\n"))
(define* (serialize-cons field #:key (gtk2? #f))
  (serialize-field (car field) (cdr field) #:gtk2? gtk2?))

(define (gtk4-css-import-file theme-package theme-name)
  `("gtk.css"
    "@import url(\"file://" ,theme-package "/share/themes/" ,theme-name "/gtk-4.0/gtk.css\");"))

(define-configuration home-gtk-configuration
  (theme-package
   package
   "The package with theme under share/themes/{theme-name}")
  (theme-name
   string
   "The name of the theme in the package")
  (font-name
   (string "DejaVu Sans 12")
   "Name of the font to use"))
(define (map-gtk-configuration-to-gtk-config config)
  (filter (lambda (x) (not (nil? (cdr x))))
          `((gtk-theme-name . ,(gtk-theme-configuration-name (home-gtk-configuration-gtk-theme config)))
            (gtk-icon-theme-name . ,(gtk-theme-configuration-name (home-gtk-configuration-icon-theme config)))
            (gtk-cursor-theme-name . ,(gtk-theme-configuration-name (home-gtk-configuration-cursor-theme config)))
            (gtk-cursor-theme-size . ,(gtk-theme-configuration-size (home-gtk-configuration-cursor-theme config)))
            (gtk-font-name . ,(home-gtk-configuration-font-name config)))))

(define* (serialize-gtk-config config #:key (gtk2? #f))
  (let* ((mapped (map-gtk-configuration-to-gtk-config config))
        (serialized (map (lambda (x) (serialize-cons x #:gtk2? gtk2?)) mapped)))
    (if gtk2?
        serialized
        (cons* "[Settings]\n"
               serialized))))

(define (add-gtk-theme-package config)
  (list
   (home-gtk-configuration-theme-package config)))
(define (add-gtk-theme-packages config)
  (filter
   (lambda (x) (not (nil? x)))
   (list
    (gtk-theme-configuration-package (home-gtk-configuration-gtk-theme config))
    (gtk-theme-configuration-package (home-gtk-configuration-icon-theme config))
    (gtk-theme-configuration-package (home-gtk-configuration-cursor-theme config))
    (if (nil? (gtk-theme-configuration-name (home-gtk-configuration-cursor-theme config)))
        '()
        (package
         (name "default-icon-inherits")
         (version "0.0.0")
         (source #f)
         (build-system trivial-build-system)
         (home-page #f)
         (synopsis #f)
         (description #f)
         (license #f)
         (arguments
          (list
           #:builder
           (with-imported-modules
            '((guix build utils))
            #~(begin
                (use-modules (guix build utils))
                (mkdir-p (string-append #$output "/share/icons/default"))
                (call-with-output-file (string-append #$output "/share/icons/default/index.theme")
                  (lambda (port)
                    (format port
                            "[Icon Theme]~%Inherits=~a~%"
                            #$(gtk-theme-configuration-name (home-gtk-configuration-cursor-theme config))))))))))))))

(define (add-xcursor-environment config)
  (let* ((cursor-theme (home-gtk-configuration-cursor-theme config))
        (cursor-name (gtk-theme-configuration-name cursor-theme))
        (cursor-package (gtk-theme-configuration-package cursor-theme))
        (cursor-size (gtk-theme-configuration-size cursor-theme)))
    (if (nil? cursor-name)
        '()
        `(("XCURSOR_THEME" . ,cursor-name)
           ("XCURSOR_SIZE" . ,(format #f "~a" cursor-size)))))) ;; TODO: this path should not be hardcoded here

(define (add-gtk-config-file config)
  `((".gtkrc-2.0"
     ,(apply mixed-text-file (gtk2-config-file
                              "gtkrc-2.0"
                              (home-gtk-configuration-theme-name config)
                              (home-gtk-configuration-font-name config))))
    (".config/gtk-3.0/settings.ini"
     ,(apply mixed-text-file (gtk-config-file
                              "settings.ini"
                              "[Settings]"
                              (home-gtk-configuration-theme-name config)
                              (home-gtk-configuration-font-name config))))
    (".config/gtk-4.0/settings.ini"
     ,(apply mixed-text-file (gtk-config-file
                              "settings.ini"
                              "[Settings]"
                              (home-gtk-configuration-theme-name config)
                              (home-gtk-configuration-font-name config))))
    (".config/gtk-4.0/gtk.css"
     ,(apply mixed-text-file (gtk4-css-import-file
                              (home-gtk-configuration-theme-package config)
                              (home-gtk-configuration-theme-name config))))))
  (append
   `((".gtkrc-2.0"
      ,(apply mixed-text-file (cons* "gtkrc-2.0" (serialize-gtk-config config #:gtk2? #t))))
     (".config/gtk-3.0/settings.ini"
      ,(apply mixed-text-file (cons* "settings.ini" (serialize-gtk-config config))))
     (".config/gtk-4.0/settings.ini"
      ,(apply mixed-text-file (cons* "settings.ini" (serialize-gtk-config config)))))
   (if (nil? (gtk-theme-configuration-package (home-gtk-configuration-gtk-theme config)))
       '()
       `((".config/gtk-4.0/gtk.css"
          ,(apply mixed-text-file (gtk4-css-import-file
                                   (gtk-theme-configuration-package (home-gtk-configuration-gtk-theme config))
                                   (gtk-theme-configuration-name (home-gtk-configuration-gtk-theme config)))))))))

(define-public home-gtk-service-type
  (service-type (name 'home-gtk)


@@ 89,5 128,8 @@
                        add-gtk-config-file)
                       (service-extension
                        home-profile-service-type
                        add-gtk-theme-package)))
                        add-gtk-theme-packages)
                       (service-extension
                        home-environment-variables-service-type
                        add-xcursor-environment)))
                (description "Create gtk theme configuration files for gtk2 and gtk3")))

M home/modules/ruther/home/themes.scm => home/modules/ruther/home/themes.scm +83 -30
@@ 1,9 1,10 @@
(define-module (ruther home themes)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages web)
  #:use-module (gnu packages inkscape)
  #:use-module (gnu packages xorg)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix build utils)


@@ 12,9 13,10 @@
  #:use-module (guix download)
  #:use-module (guix git-download)

  #:export (make-graphite-gtk-theme))
  #:export (make-graphite-gtk-theme
            make-tela-circle-icon-theme
            make-catppuccin-cursors))

; (make-graphite-theme #:theme "orange" #:color "dark")
(define* (make-graphite-gtk-theme #:key
                              theme
                              (color "standard")


@@ 49,35 51,86 @@
                       "install.sh"
                       "-t" ,theme
                       "-c" ,color
                       "-d" (string-append (assoc-ref %outputs "out") "/share/themes"))
                      )))))
    ;; (arguments
    ;;  (list
    ;;   #:builder
    ;;   (with-imported-modules '((guix build utils))
    ;;     #~(begin
    ;;         (use-modules (guix build utils))
    ;;         ;; (setenv "PATH" (string-join (map (lambda (x) (string-append (cdr x) "/bin")) %build-inputs) ":"))
    ;;         (display (invoke "ls"))
    ;;         (invoke "bash" "install.sh")))
    ;;   ;; (with-imported-modules '((guix build utils))

    ;;   ;;   ;; #~(begin
    ;;   ;;   ;;     (use-modules (guix build utils))

    ;;   ;;   ;;     #$(with-build-variables #$inputs #$outputs
    ;;   ;;   ;;         (setenv "PATH" (string-join (map (lambda (x) (string-append x "/bin")) %build-inputs)) ":")
    ;;   ;;   ;;         (invoke "bash"
    ;;   ;;   ;;                 "-t" #$theme
    ;;   ;;   ;;                 "-c" #$color
    ;;   ;;   ;;                 "install.sh"
    ;;   ;;   ;;                 "-d" (string-append #$output "/share/themes")))
    ;;   ;;   ;;     )
    ;;   ;;   )
    ;;   ))
                       "-d" (string-append (assoc-ref %outputs "out") "/share/themes")))))))
    (synopsis "Graphite gtk theme")
    (description "Graphite gtk theme")
    (home-page "https://github.com/vinceliuice/Graphite-gtk-theme")
    (license license:gpl3)))

;; (make-graphite-gtk-theme #:theme "orange" #:color "dark")
(define* (make-tela-circle-icon-theme #:key (variant "standard"))
  (package
    (name (string-append "tela-circle-" variant "-icon-theme"))
    (version "2024-04-19")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/vinceliuice/Tela-circle-icon-theme")
             (commit version)))
       (sha256
        (base32 "1w7m6wqc205y5v3lrwd2a27df0hfhp3xv4sgz12kv5qih2g2dldy"))
       (snippet
        #~(begin (use-modules (guix build utils))
                 (substitute* "install.sh"
                   (("gtk-update-icon-cache.*") ""))))))
    (build-system gnu-build-system)
    (inputs
     (list gnome-themes-extra))
    (properties
     `((icon-theme-name . ,(string-append "Tela-circle-" variant))
       (dark-icon-theme-name . ,(string-append "Tela-circle-" variant "-dark"))
       (light-icon-theme-name . ,(string-append "Tela-circle-" variant "-light"))))
    (arguments
     `(#:phases (modify-phases %standard-phases
                  (delete 'configure)
                  (delete 'build)
                  (delete 'check)
                  (replace 'install
                    (lambda* (#:key inputs outputs #:allow-other-keys)
                      (invoke
                       "bash"
                       "install.sh"
                       "-c" ,variant
                       "-d" (string-append (assoc-ref %outputs "out") "/share/icons")))))))
    (synopsis "Tela icon theme")
    (description "Tela icon theme")
    (home-page "https://github.com/vinceliuice/Tela-circle-icon-theme")
    (license #f)))

(define* (make-catppuccin-cursors #:key flavor accent)
  (package
    (name (string-append "cattpuccin-cursors-" flavor "-" accent))
    (version "0.3.1")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/catppuccin/cursors")
             (commit (string-append "v" version))))
       (sha256
        (base32 "0pb393jlsrjfz8jhrgydhmv4hygf5wjs5jbc5m5628nixzlc7v0a"))))
    (build-system gnu-build-system)
    (native-inputs
     (list inkscape xcursorgen))
    (properties
     `((cursor-theme-name . ,(string-append "catppuccin-" flavor "-" accent "-cursors"))))
    (arguments
     `(#:phases (modify-phases %standard-phases
                  (delete 'configure)
                  (delete 'check)
                  (replace 'build
                    (lambda* _
                      (invoke
                       "bash"
                       "build"
                       "-f" ,flavor
                       "-a" ,accent)))
                  (replace 'install
                    (lambda* _
                      (copy-recursively
                       "dist"
                       (string-append (assoc-ref %outputs "out") "/share/icons")))))))
    (synopsis "Catppuccin cursors")
    (description "Catppuccin cursors")
    (home-page "https://github.com/catppuccin/cursors/tree/main")
    (license license:gpl2)))

Do not follow this link