;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu home services shells) #:use-module (gnu services configuration) #:autoload (gnu system shadow) (%default-bashrc) #:use-mod
aboutsummaryrefslogtreecommitdiff
path: root/gnu/build
-profile) (serialize-field 'environment-variables))) ,@(list (file-if-not-empty 'bashrc (if (home-bash-configuration-guix-defaults? config) (list (serialize-field 'aliases) (plain-file-content %default-bashrc)) (list (serialize-field 'aliases)))) (file-if-not-empty 'bash-logout))))) (define (add-bash-packages config) (list (home-bash-configuration-package config))) (define-configuration/no-serialization home-bash-extension (environment-variables (alist '()) "Additional environment variables to set. These will be combined with the environment variables from other extensions and the base service to form one coherent block of environment variables.") (aliases (alist '()) "Additional aliases to set. These will be combined with the aliases from other extensions and the base service.") (bash-profile (text-config '()) "Additional text blocks to add to @file{.bash_profile}, which will be combined with text blocks from other extensions and the base service.") (bashrc (text-config '()) "Additional text blocks to add to @file{.bashrc}, which will be combined with text blocks from other extensions and the base service.") (bash-logout (text-config '()) "Additional text blocks to add to @file{.bash_logout}, which will be combined with text blocks from other extensions and the base service.")) (define (home-bash-extensions original-config extension-configs) (match-record original-config (environment-variables aliases bash-profile bashrc bash-logout) (home-bash-configuration (inherit original-config) (environment-variables (append environment-variables (append-map home-bash-extension-environment-variables extension-configs))) (aliases (append aliases (append-map home-bash-extension-aliases extension-configs))) (bash-profile (append bash-profile (append-map home-bash-extension-bash-profile extension-configs))) (bashrc (append bashrc (append-map home-bash-extension-bashrc extension-configs))) (bash-logout (append bash-logout (append-map home-bash-extension-bash-logout extension-configs)))))) (define home-bash-service-type (service-type (name 'home-bash) (extensions (list (service-extension home-files-service-type add-bash-configuration) (service-extension home-profile-service-type add-bash-packages))) (compose identity) (extend home-bash-extensions) (default-value (home-bash-configuration)) (description "Install and configure GNU Bash."))) ;;; ;;; Fish. ;;; (define (serialize-fish-aliases field-name val) #~(string-append #$@(map (match-lambda ((key . value) #~(string-append "alias " #$key " \"" #$value "\"\n")) (_ "")) val))) (define (serialize-fish-abbreviations field-name val) #~(string-append #$@(map (match-lambda ((key . value) #~(string-append "abbr --add " #$key " " #$value "\n")) (_ "")) val))) (define (serialize-fish-env-vars field-name val) #~(string-append #$@(map (match-lambda ((key . #f) "") ((key . #t) #~(string-append "set -x " #$key "\n")) ((key . value) #~(string-append "set -x " #$key " " #$value "\n"))) val))) (define-configuration home-fish-configuration (package (package fish) "The Fish package to use.") (config (text-config '()) "List of file-like objects, which will be added to @file{$XDG_CONFIG_HOME/fish/config.fish}.") (environment-variables (alist '()) "Association list of environment variables to set in Fish." (serializer serialize-fish-env-vars)) (aliases (alist '()) "Association list of aliases for Fish, both the key and the value should be a string. An alias is just a simple function that wraps a command, If you want something more akin to @dfn{aliases} in POSIX shells, see the @code{abbreviations} field." (serializer serialize-fish-aliases)) (abbreviations (alist '()) "Association list of abbreviations for Fish. These are words that, when typed in the shell, will automatically expand to the full text." (serializer serialize-fish-abbreviations))) (define (fish-files-service config) `(("fish/config.fish" ,(mixed-text-file "fish-config.fish" #~(string-append "\ # if we haven't sourced the login config, do it status --is-login; and not set -q __fish_login_config_sourced and begin set --prepend fish_function_path " #$fish-foreign-env "/share/fish/functions fenv source $HOME/.profile set -e fish_function_path[1] set -g __fish_login_config_sourced 1 end\n\n") (serialize-configuration config home-fish-configuration-fields))))) (define (fish-profile-service config) (list (home-fish-configuration-package config))) (define-configuration/no-serialization home-fish-extension (config (text-config '()) "List of file-like objects for extending the Fish initialization file.") (environment-variables (alist '()) "Association list of environment variables to set.") (aliases (alist '()) "Association list of Fish aliases.") (abbreviations (alist '()) "Association list of Fish abbreviations.")) (define (home-fish-extensions original-config extension-configs) (home-fish-configuration (inherit original-config) (config (append (home-fish-configuration-config original-config) (append-map home-fish-extension-config extension-configs))) (environment-variables (append (home-fish-configuration-environment-variables original-config) (append-map home-fish-extension-environment-variables extension-configs))) (aliases (append (home-fish-configuration-aliases original-config) (append-map home-fish-extension-aliases extension-configs))) (abbreviations (append (home-fish-configuration-abbreviations original-config) (append-map home-fish-extension-abbreviations extension-configs))))) ;; TODO: Support for generating completion files ;; TODO: Support for installing plugins (define home-fish-service-type (service-type (name 'home-fish) (extensions (list (service-extension home-xdg-configuration-files-service-type fish-files-service) (service-extension home-profile-service-type fish-profile-service))) (compose identity) (extend home-fish-extensions) (default-value (home-fish-configuration)) (description "\ Install and configure Fish, the friendly interactive shell."))) (define (generate-home-shell-profile-documentation) (generate-documentation `((home-shell-profile-configuration ,home-shell-profile-configuration-fields)) 'home-shell-profile-configuration)) (define (generate-home-bash-documentation) (string-append (generate-documentation `((home-bash-configuration ,home-bash-configuration-fields)) 'home-bash-configuration) "\n\n" (generate-documentation `((home-bash-extension ,home-bash-extension-fields)) 'home-bash-extension))) (define (generate-home-zsh-documentation) (generate-documentation `((home-zsh-configuration ,home-zsh-configuration-fields)) 'home-zsh-configuration)) (define (generate-home-fish-documentation) (string-append (generate-documentation `((home-fish-configuration ,home-fish-configuration-fields)) 'home-fish-configuration) "\n\n" (generate-documentation `((home-fish-extension ,home-fish-extension-fields)) 'home-fish-extension)))