From: "Ludovic Courtès" <ludo@gnu.org>
To: 60365@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#60365] [PATCH 1/4] system, home: Factorize default '.bashrc'.
Date: Tue, 27 Dec 2022 22:26:15 +0100 [thread overview]
Message-ID: <20221227212618.18063-1-ludo@gnu.org> (raw)
In-Reply-To: <20221227212342.17939-1-ludo@gnu.org>
* 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.
---
gnu/home/services/shells.scm | 41 +++---------------------------------
gnu/system/shadow.scm | 26 +++++++++++++----------
2 files changed, 18 insertions(+), 49 deletions(-)
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index b529c8e798..d7dd579293 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -19,6 +19,7 @@
(define-module (gnu home services shells)
#:use-module (gnu services configuration)
+ #:autoload (gnu system shadow) (%default-bashrc)
#:use-module (gnu home services utils)
#:use-module (gnu home services)
#:use-module (gnu packages shells)
@@ -370,43 +371,6 @@ (define-configuration home-bash-configuration
won't be read in some cases (if the shell terminates by exec'ing
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 (filter-fields field)
(filter-configuration-fields home-bash-configuration-fields
@@ -449,7 +413,8 @@ (define* (file-if-not-empty field #:optional (extra-content #f))
,@(list (file-if-not-empty
'bashrc
(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))))
(file-if-not-empty 'bash-logout)))))
diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index 59f0a02c8b..4360a5ebd1 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -1,5 +1,5 @@
;;; 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 © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
@@ -63,7 +63,8 @@ (define-module (gnu system shadow)
user-group-id
user-group-system?)
- #:export (default-skeletons
+ #:export (%default-bashrc
+ default-skeletons
skeleton-directory
%base-groups
%base-user-accounts
@@ -118,14 +119,8 @@ (define %base-user-accounts
(create-home-directory? #f)
(system? #t))))
-(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 (plain-file "bashrc" "\
+(define %default-bashrc
+ (plain-file "bashrc" "\
# Bash initialization for interactive non-login shells and
# for remote shells (info \"(bash) Bash Startup Files\").
@@ -145,7 +140,7 @@ (define (default-skeletons)
fi
# 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'.
if [ -n \"$GUIX_ENVIRONMENT\" ]
@@ -157,6 +152,15 @@ (define (default-skeletons)
alias ls='ls -p --color=auto'
alias ll='ls -l'
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" "\
# Honor system-wide environment variables
source /etc/profile\n"))
--
2.38.1
next prev parent reply other threads:[~2022-12-27 21:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-27 21:23 [bug#60365] [PATCH 0/4] Rationalize 'PS1' handling in home, system, and shell Ludovic Courtès
2022-12-27 21:26 ` Ludovic Courtès [this message]
2022-12-27 21:26 ` [bug#60365] [PATCH 2/4] system: Define default 'PS1' in /etc/bashrc rather than ~/.bashrc Ludovic Courtès
2022-12-27 21:26 ` [bug#60365] [PATCH 3/4] environment: Simplify 'PS1' suggestion on '--check' Ludovic Courtès
2022-12-27 21:26 ` [bug#60365] [PATCH 4/4] environment: Avoid false positive on 'PS1' check Ludovic Courtès
2022-12-28 7:23 ` [bug#60365] [PATCH 0/4] Rationalize 'PS1' handling in home, system, and shell Andrew Tropin
2023-01-03 22:46 ` Ludovic Courtès
2023-01-04 6:00 ` Andrew Tropin
2023-01-05 14:20 ` bug#60365: " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221227212618.18063-1-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=60365@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).