-----
* home.scm - home directory configuration for the GNU Guix operating system.
+* conf/home/ - custom GNU Guix programs and services for the home directory.
* <program>/ - program-specific dotfiles.
--- /dev/null
+;; Copyright (c) 2022 Jakub Czajka <jakub@ekhem.eu.org>
+;; 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}.")))
;;
;; 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")))))))