home-services: shells: Add support for declaring fish plugins with home-fish-service

pull/3/head
Luis Guilherme Coelho 2024-07-05 14:38:01 -03:00
parent f8f277f24e
commit 677c6c79f3
No known key found for this signature in database
GPG Key ID: 1F2E76ACE3F531C8
1 changed files with 47 additions and 5 deletions

View File

@ -4,12 +4,17 @@
#:use-module (gnu home services) #:use-module (gnu home services)
#:use-module (gnu packages shells) #:use-module (gnu packages shells)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix store)
#:use-module (guix derivations)
#:use-module (guix packages) #:use-module (guix packages)
#:use-module (guix records) #:use-module (guix records)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-9) #:use-module (srfi srfi-9)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (radix utils)
#:use-module (radix combinators)
#:use-module (radix packages fish-xyz)
#:export (home-fish-service-type #:export (home-fish-service-type
home-fish-configuration home-fish-configuration
@ -62,6 +67,9 @@
(define fish-env-vars? alist?) (define fish-env-vars? alist?)
(define fish-aliases? alist?) (define fish-aliases? alist?)
(define fish-plugins?
(list-of package?))
(define (serialize-fish-abbreviations field-name val) (define (serialize-fish-abbreviations field-name val)
#~(string-append #~(string-append
#$@(map (match-record-lambda <abbreviation> #$@(map (match-record-lambda <abbreviation>
@ -93,6 +101,9 @@
#~(string-append "set -x " #$key " " #$value "\n"))) #~(string-append "set -x " #$key " " #$value "\n")))
val))) val)))
(define serialize-fish-plugins
(@@ (gnu services configuration) empty-serializer))
(define-configuration home-fish-configuration (define-configuration home-fish-configuration
(package (package
(package fish) (package fish)
@ -113,7 +124,11 @@ shells, see the @code{abbreviations} field.")
(abbreviations (abbreviations
(fish-abbreviations '()) (fish-abbreviations '())
"List of abbreviations for Fish. These are words that, when "List of abbreviations for Fish. These are words that, when
typed in the shell, will automatically expand to the full text.")) typed in the shell, will automatically expand to the full text.")
(plugins
(fish-plugins '())
"List of plugins for Fish. These are packages that, provide extra functions,
hooks, and/or abbreviations for fish."))
(define (fish-files-service config) (define (fish-files-service config)
`(("fish/config.fish" `(("fish/config.fish"
@ -152,7 +167,10 @@ end\n\n")
"Association list of Fish aliases.") "Association list of Fish aliases.")
(abbreviations (abbreviations
(fish-abbreviations '()) (fish-abbreviations '())
"Association list of Fish abbreviations.")) "Association list of Fish abbreviations.")
(plugins
(fish-plugins '())
"List of plugins for Fish."))
(define (home-fish-extensions original-config extension-configs) (define (home-fish-extensions original-config extension-configs)
(home-fish-configuration (home-fish-configuration
@ -172,16 +190,40 @@ end\n\n")
(abbreviations (abbreviations
(append (home-fish-configuration-abbreviations original-config) (append (home-fish-configuration-abbreviations original-config)
(append-map (append-map
home-fish-extension-abbreviations extension-configs))))) home-fish-extension-abbreviations extension-configs)))
(plugins
(append (home-fish-configuration-plugins original-config)
(append-map
home-fish-extension-plugins extension-configs)))))
(define (fish-plugin-files-service config)
(let* ((plugins (home-fish-configuration-plugins config))
(plugin-union (fish-plugin-union plugins))
(drv (run-with-store (open-connection)
(with-store %store
(package->derivation plugin-union))))
(path (string-append (derivation->output-path drv) "/share"))
(subdirs (list-contents path)))
(append-map (lambda (subdir)
(map (lambda (content)
(let ((almost-basename (almost-basename content)))
(list (string-append "fish/" almost-basename)
(file-append plugin-union
(string-append "/share/"
almost-basename)))))
(list-contents subdir)))
(filter (negate (cut string-suffix? "doc" <>))
subdirs))))
;; TODO: Support for generating completion files ;; TODO: Support for generating completion files
;; TODO: Support for installing plugins
(define home-fish-service-type (define home-fish-service-type
(service-type (name 'home-fish) (service-type (name 'home-fish)
(extensions (extensions
(list (service-extension (list (service-extension
home-xdg-configuration-files-service-type home-xdg-configuration-files-service-type
fish-files-service) (lambda (config)
(append (fish-files-service config)
(fish-plugin-files-service config))))
(service-extension (service-extension
home-profile-service-type home-profile-service-type
fish-profile-service))) fish-profile-service)))