]> git.ekhem.eu.org Git - guix.git/commitdiff
[home] Customize the bash service.
authorJakub Czajka <jakub@ekhem.eu.org>
Thu, 2 Jun 2022 21:49:35 +0000 (23:49 +0200)
committerJakub Czajka <jczajka@google.com>
Sun, 24 Dec 2023 18:53:07 +0000 (19:53 +0100)
This commit adds a custom service-type for installing bash. It is
placed in a separate module. It explicitly requires .bash_profile and
.bashrc.

README
conf/home/bash.scm [new file with mode: 0644]
home.scm

diff --git a/README b/README
index e30020bdd591656a43aa2428a926cca910966ed5..99d1f31fc7ff1085a3705fa319d04da92b9eb918 100644 (file)
--- 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>/ - program-specific dotfiles.
diff --git a/conf/home/bash.scm b/conf/home/bash.scm
new file mode 100644 (file)
index 0000000..e1eb980
--- /dev/null
@@ -0,0 +1,49 @@
+;; 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}.")))
index 92ab5cffbdbc37d680c183718d169d9f681a105c..2e25e08bb7cab2d0d9082b86c359e56a712d3237 100644 (file)
--- 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")))))))