modules/programs/bash: major clean-up and re-factoring of /etc/profile and /etc/bashrc
* Moved bash-specific code from /etc/profile to /etc/bashrc. * Moved general Bourne shell code from /etc/bashrc to /etc/profile. * Added "include guards" to both files to ensure that they aren't sourced multiple times (which would result in lots of redundancy in $PATH, etc.). * Both files include each other to make sure that the correct system environment is always defined. * When the current user has installed the 'bash-completion' package in her $HOME/.nix-profile, programmable completion is automatically enabled in interactive shells. * The /etc/skel/.bashrc we installed has been dropped because it is redundant. svn path=/nixos/trunk/; revision=29451
This commit is contained in:
parent
c04d1477de
commit
432d71f3ed
@ -26,31 +26,21 @@ in
|
||||
require = [options];
|
||||
|
||||
environment.etc =
|
||||
[ { # /etc/bashrc: script executed when the shell starts as a
|
||||
# non-login shell. /etc/profile also sources this file, so
|
||||
# most global configuration (such as environment variables)
|
||||
# should go into this script.
|
||||
[ { # Script executed when the shell starts as a login shell.
|
||||
source = pkgs.substituteAll {
|
||||
src = ./bashrc.sh;
|
||||
|
||||
bash = pkgs.bash;
|
||||
src = ./profile.sh;
|
||||
wrapperDir = config.security.wrapperDir;
|
||||
modulesTree = config.system.modulesTree;
|
||||
shellInit = config.environment.shellInit;
|
||||
};
|
||||
target = "bashrc";
|
||||
}
|
||||
|
||||
{ # Script executed when the shell starts as a login shell.
|
||||
source = ./profile.sh;
|
||||
target = "profile";
|
||||
}
|
||||
|
||||
{ # Template for ~/.bashrc: script executed when the shell
|
||||
# starts as a non-login shell.
|
||||
source = ./bashrc-user.sh;
|
||||
target = "skel/.bashrc";
|
||||
mode = "0644";
|
||||
{ # /etc/bashrc: executed every time a bash starts. Sources
|
||||
# /etc/profile to ensure that the system environment is
|
||||
# configured properly.
|
||||
source = ./bashrc.sh;
|
||||
target = "bashrc";
|
||||
}
|
||||
|
||||
{ # Configuration for readline in bash.
|
||||
|
@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -f /etc/bashrc ]
|
||||
then
|
||||
source /etc/bashrc
|
||||
fi
|
@ -1,92 +1,40 @@
|
||||
if [ -n "$NOSYSBASHRC" ]; then
|
||||
# /etc/bashrc: DO NOT EDIT -- this file has been generated automatically.
|
||||
|
||||
if [ \( -n "${SYSTEM_ETC_BASHRC_HAS_BEEN_SOURCED:-}" \) -o \( -n "${NOSYSBASHRC:-}" \) ]; then
|
||||
return
|
||||
else
|
||||
SYSTEM_ETC_BASHRC_HAS_BEEN_SOURCED="1"
|
||||
fi
|
||||
|
||||
# In interactive shells, check the window size after every command.
|
||||
. /etc/profile
|
||||
|
||||
# If we are an interactive shell ...
|
||||
if [ -n "$PS1" ]; then
|
||||
# Check the window size after every command.
|
||||
shopt -s checkwinsize
|
||||
fi
|
||||
|
||||
# Initialise a bunch of environment variables.
|
||||
export LD_LIBRARY_PATH=/var/run/opengl-driver/lib:/var/run/opengl-driver-32/lib # !!! only set if needed
|
||||
export MODULE_DIR=@modulesTree@/lib/modules
|
||||
export NIXPKGS_CONFIG=/nix/etc/config.nix
|
||||
export NIXPKGS_ALL=/etc/nixos/nixpkgs
|
||||
export NIX_PATH=nixpkgs=/etc/nixos/nixpkgs:nixos=/etc/nixos/nixos:nixos-config=/etc/nixos/configuration.nix:services=/etc/nixos/services
|
||||
export PAGER="less -R"
|
||||
export EDITOR=nano
|
||||
export LOCATE_PATH=/var/cache/locatedb
|
||||
|
||||
|
||||
# Include the various profiles in the appropriate environment variables.
|
||||
NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER
|
||||
|
||||
NIX_PROFILES="/var/run/current-system/sw /nix/var/nix/profiles/default $HOME/.nix-profile"
|
||||
|
||||
unset PATH INFOPATH PKG_CONFIG_PATH PERL5LIB ALSA_PLUGIN_DIRS GST_PLUGIN_PATH KDEDIRS
|
||||
unset QT_PLUGIN_PATH QTWEBKIT_PLUGIN_PATH STRIGI_PLUGIN_PATH XDG_CONFIG_DIRS XDG_DATA_DIRS
|
||||
|
||||
for i in $NIX_PROFILES; do # !!! reverse
|
||||
# We have to care not leaving an empty PATH element, because that means '.' to Linux
|
||||
export PATH=$i/bin:$i/sbin:$i/lib/kde4/libexec${PATH:+:}$PATH
|
||||
export INFOPATH=$i/info:$i/share/info${INFOPATH:+:}$INFOPATH
|
||||
export PKG_CONFIG_PATH="$i/lib/pkgconfig${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH"
|
||||
|
||||
# "lib/site_perl" is for backwards compatibility with packages
|
||||
# from Nixpkgs <= 0.12.
|
||||
export PERL5LIB="$i/lib/perl5/site_perl:$i/lib/site_perl${PERL5LIB:+:}$PERL5LIB"
|
||||
|
||||
# ALSA plugins
|
||||
export ALSA_PLUGIN_DIRS="$i/lib/alsa-lib${ALSA_PLUGIN_DIRS:+:}$ALSA_PLUGIN_DIRS"
|
||||
|
||||
# GStreamer.
|
||||
export GST_PLUGIN_PATH="$i/lib/gstreamer-0.10${GST_PLUGIN_PATH:+:}$GST_PLUGIN_PATH"
|
||||
|
||||
# KDE/Gnome stuff.
|
||||
export KDEDIRS=$i${KDEDIRS:+:}$KDEDIRS
|
||||
export STRIGI_PLUGIN_PATH=$i/lib/strigi/${STRIGI_PLUGIN_PATH:+:}$STRIGI_PLUGIN_PATH
|
||||
export QT_PLUGIN_PATH=$i/lib/qt4/plugins:$i/lib/kde4/plugins${QT_PLUGIN_PATH:+:}:$QT_PLUGIN_PATH
|
||||
export QTWEBKIT_PLUGIN_PATH=$i/lib/mozilla/plugins/${QTWEBKIT_PLUGIN_PATH:+:}$QTWEBKIT_PLUGIN_PATH
|
||||
export XDG_CONFIG_DIRS=$i/etc/xdg${XDG_CONFIG_DIRS:+:}$XDG_CONFIG_DIRS
|
||||
export XDG_DATA_DIRS=$i/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS
|
||||
done
|
||||
|
||||
@shellInit@
|
||||
|
||||
|
||||
# Search directory for Aspell dictionaries.
|
||||
export ASPELL_CONF="dict-dir $HOME/.nix-profile/lib/aspell"
|
||||
|
||||
|
||||
# ~/bin and the setuid wrappers override other bin directories.
|
||||
export PATH=$HOME/bin:@wrapperDir@:$PATH
|
||||
|
||||
|
||||
# Provide a nice prompt.
|
||||
PROMPT_COLOR="1;31m"
|
||||
let $UID && PROMPT_COLOR="1;32m"
|
||||
PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] "
|
||||
if test "$TERM" = "xterm"; then
|
||||
PS1="\[\033]2;\h:\u:\w\007\]$PS1"
|
||||
fi
|
||||
|
||||
|
||||
# Some aliases.
|
||||
alias ls="ls --color=tty"
|
||||
alias ll="ls -l"
|
||||
alias l="ls -alh"
|
||||
alias which="type -P"
|
||||
|
||||
# The "non-interactive" Bash build does not support programmable
|
||||
# completion so check whether it's available.
|
||||
if false; then
|
||||
#if shopt -q progcomp 2> /dev/null; then
|
||||
# Completion.
|
||||
if [ -z "$BASH_COMPLETION_DIR" -a -d "@bash@/etc/bash_completion.d" ]; then
|
||||
BASH_COMPLETION_DIR="@bash@/etc/bash_completion.d"
|
||||
# Provide a nice prompt.
|
||||
PROMPT_COLOR="1;31m"
|
||||
let $UID && PROMPT_COLOR="1;32m"
|
||||
PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] "
|
||||
if test "$TERM" = "xterm"; then
|
||||
PS1="\[\033]2;\h:\u:\w\007\]$PS1"
|
||||
fi
|
||||
if [ -z "$BASH_COMPLETION" -a -f "@bash@/etc/bash_completion" ]; then
|
||||
BASH_COMPLETION="@bash@/etc/bash_completion"
|
||||
source "$BASH_COMPLETION"
|
||||
|
||||
# Check whether we're running a version of Bash that has support for
|
||||
# programmable completion. If we do, and if the current user has
|
||||
# installed the package 'bash-completion' in her $HOME/.nix-profile,
|
||||
# then completion is enabled automatically.
|
||||
if [ -f "$HOME/.nix-profile/etc/bash_completion" ]; then
|
||||
if [ -d "$HOME/.nix-profile/etc/bash_completion.d" ]; then
|
||||
if shopt -q progcomp &>/dev/null; then
|
||||
BASH_COMPLETION_DIR="$HOME/.nix-profile/etc/bash_completion.d"
|
||||
BASH_COMPLETION="$HOME/.nix-profile/etc/bash_completion"
|
||||
. "$BASH_COMPLETION"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Some aliases.
|
||||
alias which="type -P"
|
||||
fi
|
||||
|
@ -1,10 +1,58 @@
|
||||
# This file is executed by all login shells. Don't ask what a login
|
||||
# shell is, nobody knows. Most global environment variables should go
|
||||
# in /etc/bashrc, which is by default included by non-login shells,
|
||||
# but which we include here as well.
|
||||
# /etc/profile: DO NOT EDIT -- this file has been generated automatically.
|
||||
|
||||
source /etc/bashrc
|
||||
if [ -n "${SYSTEM_ETC_PROFILE_HAS_BEEN_SOURCED:-}" ]; then
|
||||
return
|
||||
else
|
||||
SYSTEM_ETC_PROFILE_HAS_BEEN_SOURCED="1"
|
||||
fi
|
||||
|
||||
# Initialise a bunch of environment variables.
|
||||
export LD_LIBRARY_PATH=/var/run/opengl-driver/lib:/var/run/opengl-driver-32/lib # !!! only set if needed
|
||||
export MODULE_DIR=@modulesTree@/lib/modules
|
||||
export NIXPKGS_CONFIG=/nix/etc/config.nix
|
||||
export NIXPKGS_ALL=/etc/nixos/nixpkgs
|
||||
export NIX_PATH=nixpkgs=/etc/nixos/nixpkgs:nixos=/etc/nixos/nixos:nixos-config=/etc/nixos/configuration.nix:services=/etc/nixos/services
|
||||
export PAGER="less -R"
|
||||
export EDITOR=nano
|
||||
export LOCATE_PATH=/var/cache/locatedb
|
||||
|
||||
# Include the various profiles in the appropriate environment variables.
|
||||
NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER
|
||||
NIX_PROFILES="/var/run/current-system/sw /nix/var/nix/profiles/default $HOME/.nix-profile"
|
||||
|
||||
unset PATH INFOPATH PKG_CONFIG_PATH PERL5LIB ALSA_PLUGIN_DIRS GST_PLUGIN_PATH KDEDIRS
|
||||
unset QT_PLUGIN_PATH QTWEBKIT_PLUGIN_PATH STRIGI_PLUGIN_PATH XDG_CONFIG_DIRS XDG_DATA_DIRS
|
||||
|
||||
for i in $NIX_PROFILES; do # !!! reverse
|
||||
# We have to care not leaving an empty PATH element, because that means '.' to Linux
|
||||
export PATH=$i/bin:$i/sbin:$i/lib/kde4/libexec${PATH:+:}$PATH
|
||||
export INFOPATH=$i/info:$i/share/info${INFOPATH:+:}$INFOPATH
|
||||
export PKG_CONFIG_PATH="$i/lib/pkgconfig${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH"
|
||||
|
||||
# "lib/site_perl" is for backwards compatibility with packages
|
||||
# from Nixpkgs <= 0.12.
|
||||
export PERL5LIB="$i/lib/perl5/site_perl:$i/lib/site_perl${PERL5LIB:+:}$PERL5LIB"
|
||||
|
||||
# ALSA plugins
|
||||
export ALSA_PLUGIN_DIRS="$i/lib/alsa-lib${ALSA_PLUGIN_DIRS:+:}$ALSA_PLUGIN_DIRS"
|
||||
|
||||
# GStreamer.
|
||||
export GST_PLUGIN_PATH="$i/lib/gstreamer-0.10${GST_PLUGIN_PATH:+:}$GST_PLUGIN_PATH"
|
||||
|
||||
# KDE/Gnome stuff.
|
||||
export KDEDIRS=$i${KDEDIRS:+:}$KDEDIRS
|
||||
export STRIGI_PLUGIN_PATH=$i/lib/strigi/${STRIGI_PLUGIN_PATH:+:}$STRIGI_PLUGIN_PATH
|
||||
export QT_PLUGIN_PATH=$i/lib/qt4/plugins:$i/lib/kde4/plugins${QT_PLUGIN_PATH:+:}:$QT_PLUGIN_PATH
|
||||
export QTWEBKIT_PLUGIN_PATH=$i/lib/mozilla/plugins/${QTWEBKIT_PLUGIN_PATH:+:}$QTWEBKIT_PLUGIN_PATH
|
||||
export XDG_CONFIG_DIRS=$i/etc/xdg${XDG_CONFIG_DIRS:+:}$XDG_CONFIG_DIRS
|
||||
export XDG_DATA_DIRS=$i/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS
|
||||
done
|
||||
|
||||
# Search directory for Aspell dictionaries.
|
||||
export ASPELL_CONF="dict-dir $HOME/.nix-profile/lib/aspell"
|
||||
|
||||
# ~/bin and the setuid wrappers override other bin directories.
|
||||
export PATH=$HOME/bin:@wrapperDir@:$PATH
|
||||
|
||||
# Set up the per-user profile.
|
||||
mkdir -m 0755 -p $NIX_USER_PROFILE_DIR
|
||||
@ -13,7 +61,7 @@ if test "$(stat --printf '%u' $NIX_USER_PROFILE_DIR)" != "$(id -u)"; then
|
||||
fi
|
||||
|
||||
if ! test -L $HOME/.nix-profile; then
|
||||
echo "creating $HOME/.nix-profile" >&2
|
||||
echo "creating $HOME/.nix-profile" >&2
|
||||
if test "$USER" != root; then
|
||||
ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile
|
||||
else
|
||||
@ -22,7 +70,6 @@ if ! test -L $HOME/.nix-profile; then
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Create the per-user garbage collector roots directory.
|
||||
NIX_USER_GCROOTS_DIR=/nix/var/nix/gcroots/per-user/$USER
|
||||
mkdir -m 0755 -p $NIX_USER_GCROOTS_DIR
|
||||
@ -30,7 +77,6 @@ if test "$(stat --printf '%u' $NIX_USER_GCROOTS_DIR)" != "$(id -u)"; then
|
||||
echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR" >&2
|
||||
fi
|
||||
|
||||
|
||||
# Set up a default Nix expression from which to install stuff.
|
||||
if test ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr; then
|
||||
echo "creating $HOME/.nix-defexpr" >&2
|
||||
@ -42,8 +88,18 @@ if test ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr; then
|
||||
fi
|
||||
fi
|
||||
|
||||
@shellInit@
|
||||
|
||||
# Some aliases.
|
||||
alias ls="ls --color=tty"
|
||||
alias ll="ls -l"
|
||||
alias l="ls -alh"
|
||||
|
||||
# Read system-wide modifications.
|
||||
if test -f /etc/profile.local; then
|
||||
source /etc/profile.local
|
||||
. /etc/profile.local
|
||||
fi
|
||||
|
||||
if [ -n "${BASH_VERSION:-}" ]; then
|
||||
. /etc/bashrc
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user