From: Jakub Czajka Date: Thu, 2 Jun 2022 21:49:35 +0000 (+0200) Subject: [home] Customize the bash service. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=d8f82b2fa6cd7b3f8a05a4d55ad39775cad3c6cf;p=guix.git [home] Customize the bash service. This commit adds a custom service-type for installing bash. It is placed in a separate module. It explicitly requires .bash_profile and .bashrc. --- diff --git a/README b/README index e30020b..99d1f31 100644 --- a/README +++ b/README @@ -8,4 +8,5 @@ Files ----- * home.scm - home directory configuration for the GNU Guix operating system. +* conf/home/ - custom GNU Guix programs and services for the home directory. * / - program-specific dotfiles. diff --git a/conf/home/bash.scm b/conf/home/bash.scm new file mode 100644 index 0000000..e1eb980 --- /dev/null +++ b/conf/home/bash.scm @@ -0,0 +1,49 @@ +;; Copyright (c) 2022 Jakub Czajka +;; License: GPL-3.0 or later. +;; +;; bash.scm - custom bash configuration. + +(define-module (conf home bash) + #:use-module (gnu home services) + #:use-module (gnu packages bash) + #:use-module (gnu services configuration) + #:use-module (guix gexp) + #:use-module (guix packages) + #:export (home-bash-configuration + home-bash-service-type)) + +;; Local file is already a gexp, so just return in. +(define (serialize-local-file field-name value) + value) + +(define-configuration home-bash-configuration + (package + (package bash) + "Packages to be installed by the service.") + (bash-profile + (local-file) + "Dotfile for login shells.") + (bashrc + (local-file) + "Dotfile for interactive non-login shells.")) + +(define (install-bash-packages config) + (list (home-bash-configuration-package config))) + +(define (symlink-bash-dotfiles config) + (list `(".bash_profile" + ,(home-bash-configuration-bash-profile config)) + `(".bashrc" + ,(home-bash-configuration-bashrc config)))) + +(define home-bash-service-type + (service-type + (name 'home-bash) + (extensions + (list (service-extension home-profile-service-type + install-bash-packages) + (service-extension home-files-service-type + symlink-bash-dotfiles))) + (default-value (home-bash-configuration)) + (description "Installs bash packages and symlinks @file{.bash_profile} and +@file{.bashrc}."))) diff --git a/home.scm b/home.scm index 92ab5cf..2e25e08 100644 --- a/home.scm +++ b/home.scm @@ -3,48 +3,17 @@ ;; ;; home.scm - home directory configuration for GNU Guix. -(use-modules (gnu home) +(use-modules (conf home bash) (gnu home services) - (gnu home services shells) - (gnu packages base) - (gnu services) - (guix gexp) - (guix utils) - (ice-9 textual-ports)) - -(define (read-file file) - "Returns contents of FILE as a string." - (unless (access? file R_OK) - (error "Can't access file: " file)) - (call-with-input-file file get-string-all)) - -(define (expand-file-name file dir) - "If FILE is an absolute path, returns FILE. Otherwise, prepends DIR." - (if (absolute-file-name? file) - file - (string-append dir "/" file))) - -(define dot-bash-profile - (plain-file - "bash-profile" - (read-file - (expand-file-name "bash/.bash_profile" (current-source-directory))))) - -(define dot-bashrc - (plain-file - "bashrc" - (read-file - (expand-file-name "bash/.bashrc" (current-source-directory))))) + (gnu packages base) + (guix gexp)) (home-environment (packages (list)) (services - (list - ;; `local-file` for `.bashrc` causes an error. A workaround it to load - ;; `.bashrc`, put it in a `plain-file` (`dot-bashrc`) and then pass it as - ;; argument. - (service home-bash-service-type - (home-bash-configuration - (guix-defaults? #f) - (bash-profile (list dot-bash-profile)) - (bashrc (list dot-bashrc))))))) + (list (service home-bash-service-type + (home-bash-configuration + ;; `local-file` for a name with a dot causes an error. A + ;; workaround it put a different NAME argument. + (bash-profile (local-file "bash/.bash_profile" "bash_profile")) + (bashrc (local-file "bash/.bashrc" "bashrc")))))))