Archived
1
0
Fork 0

system, home: Factorize default '.bashrc'.

* gnu/system/shadow.scm (%default-bashrc): New variable.  Source
/etc/bashrc only if it exists.
(default-skeletons): Use it.
* gnu/home/services/shells.scm (guix-bashrc): Remove.
(add-bash-configuration): Refer to '%default-bashrc' instead.
This commit is contained in:
Ludovic Courtès 2022-12-27 17:50:57 +01:00
parent 73684dc90e
commit 2127e56bd8
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 18 additions and 49 deletions

View file

@ -19,6 +19,7 @@
(define-module (gnu home services shells) (define-module (gnu home services shells)
#:use-module (gnu services configuration) #:use-module (gnu services configuration)
#:autoload (gnu system shadow) (%default-bashrc)
#:use-module (gnu home services utils) #:use-module (gnu home services utils)
#:use-module (gnu home services) #:use-module (gnu home services)
#:use-module (gnu packages shells) #:use-module (gnu packages shells)
@ -370,43 +371,6 @@ Used for executing user's commands at the exit of login shell. It
won't be read in some cases (if the shell terminates by exec'ing won't be read in some cases (if the shell terminates by exec'ing
another process for example).")) another process for example)."))
;; TODO: Use value from (gnu system shadow)
(define guix-bashrc
"\
# Bash initialization for interactive non-login shells and
# for remote shells (info \"(bash) Bash Startup Files\").
# Export 'SHELL' to child processes. Programs such as 'screen'
# honor it and otherwise use /bin/sh.
export SHELL
if [[ $- != *i* ]]
then
# We are being invoked from a non-interactive shell. If this
# is an SSH session (as in \"ssh host command\"), source
# /etc/profile so we get PATH and other essential variables.
[[ -n \"$SSH_CLIENT\" ]] && source /etc/profile
# Don't do anything else.
return
fi
# Source the system-wide file.
if [[ -e /etc/bashrc ]]; then
source /etc/bashrc
fi
# Adjust the prompt depending on whether we're in 'guix environment'.
if [ -n \"$GUIX_ENVIRONMENT\" ]
then
PS1='\\u@\\h \\w [env]\\$ '
else
PS1='\\u@\\h \\w\\$ '
fi
alias ls='ls -p --color=auto'
alias ll='ls -l'
alias grep='grep --color=auto'\n")
(define (add-bash-configuration config) (define (add-bash-configuration config)
(define (filter-fields field) (define (filter-fields field)
(filter-configuration-fields home-bash-configuration-fields (filter-configuration-fields home-bash-configuration-fields
@ -449,7 +413,8 @@ if [ -f ~/.bashrc ]; then source ~/.bashrc; fi
,@(list (file-if-not-empty ,@(list (file-if-not-empty
'bashrc 'bashrc
(if (home-bash-configuration-guix-defaults? config) (if (home-bash-configuration-guix-defaults? config)
(list (serialize-field 'aliases) guix-bashrc) (list (serialize-field 'aliases)
(plain-file-content %default-bashrc))
(list (serialize-field 'aliases)))) (list (serialize-field 'aliases))))
(file-if-not-empty 'bash-logout))))) (file-if-not-empty 'bash-logout)))))

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2013-2020, 2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Alex Griffin <a@ajgrf.com> ;;; Copyright © 2016 Alex Griffin <a@ajgrf.com>
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il> ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
@ -63,7 +63,8 @@
user-group-id user-group-id
user-group-system?) user-group-system?)
#:export (default-skeletons #:export (%default-bashrc
default-skeletons
skeleton-directory skeleton-directory
%base-groups %base-groups
%base-user-accounts %base-user-accounts
@ -118,14 +119,8 @@
(create-home-directory? #f) (create-home-directory? #f)
(system? #t)))) (system? #t))))
(define (default-skeletons) (define %default-bashrc
"Return the default skeleton files for /etc/skel. These files are copied by (plain-file "bashrc" "\
'useradd' in the home directory of newly created user accounts."
(let ((profile (plain-file "bash_profile" "\
# Honor per-interactive-shell startup file
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n"))
(bashrc (plain-file "bashrc" "\
# Bash initialization for interactive non-login shells and # Bash initialization for interactive non-login shells and
# for remote shells (info \"(bash) Bash Startup Files\"). # for remote shells (info \"(bash) Bash Startup Files\").
@ -145,7 +140,7 @@ then
fi fi
# Source the system-wide file. # Source the system-wide file.
source /etc/bashrc [ -f /etc/bashrc ] && source /etc/bashrc
# Adjust the prompt depending on whether we're in 'guix environment'. # Adjust the prompt depending on whether we're in 'guix environment'.
if [ -n \"$GUIX_ENVIRONMENT\" ] if [ -n \"$GUIX_ENVIRONMENT\" ]
@ -157,6 +152,15 @@ fi
alias ls='ls -p --color=auto' alias ls='ls -p --color=auto'
alias ll='ls -l' alias ll='ls -l'
alias grep='grep --color=auto'\n")) alias grep='grep --color=auto'\n"))
(define (default-skeletons)
"Return the default skeleton files for /etc/skel. These files are copied by
'useradd' in the home directory of newly created user accounts."
(let ((profile (plain-file "bash_profile" "\
# Honor per-interactive-shell startup file
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n"))
(bashrc %default-bashrc)
(zprofile (plain-file "zprofile" "\ (zprofile (plain-file "zprofile" "\
# Honor system-wide environment variables # Honor system-wide environment variables
source /etc/profile\n")) source /etc/profile\n"))