* Use /etc/profile into a separate file.

* Automatically set up a per-user profile in
  /nix/var/nix/profiles/per-user/$USER.
* Initialise ~/.nix-defexpr and ~/.nix-profile.

svn path=/nixos/trunk/; revision=7680
This commit is contained in:
Eelco Dolstra 2007-01-15 14:43:56 +00:00
parent ee55c0048b
commit 045d9fdc88
4 changed files with 89 additions and 52 deletions

View File

@ -87,55 +87,24 @@ EOF
fi fi
# Additional path for the interactive shell.
PATH=@wrapperDir@:@fullPath@/bin:@fullPath@/sbin
cat > /etc/profile <<EOF
export PATH=$PATH
export MODULE_DIR=@kernel@/lib/modules
export NIX_CONF_DIR=/nix/etc/nix
export PAGER=less
export ACLOCAL_PATH=$HOME/.nix-profile/share/aclocal
PROMPT_COLOR="1;31m"
PS1="\n\[\033[\$PROMPT_COLOR\][\u@\h:\w]\$\[\033[0m\] "
if test "x\$TERM" == "xxterm"; then
PS1="\033]2;\h:\u:\w\007\033]1;\$PS1"
fi
if test "\$USER" != root; then
export NIX_REMOTE=daemon
fi
source $(dirname $(readlink -f $(type -tp nix-env)))/../etc/profile.d/nix.sh
alias ls="ls --color=tty"
alias ll="ls -l"
alias which="type -p"
if test -f /etc/profile.local; then
source /etc/profile.local
fi
test -r \$HOME/.bashrc && source \$HOME/.bashrc
EOF
# Nix initialisation. # Nix initialisation.
mkdir -m 0755 -p /nix/var/nix/db mkdir -m 0755 -p /nix/var/nix/db
mkdir -m 0755 -p /nix/var/nix/gcroots mkdir -m 0755 -p /nix/var/nix/gcroots
mkdir -m 0755 -p /nix/var/nix/temproots mkdir -m 0755 -p /nix/var/nix/temproots
mkdir -m 0755 -p /nix/var/nix/profiles
mkdir -m 1777 -p /nix/var/nix/profiles/per-user
ln -sf /nix/var/nix/profiles /nix/var/nix/gcroots/ ln -sf /nix/var/nix/profiles /nix/var/nix/gcroots/
# Make a few setuid programs work. # Make a few setuid programs work.
PATH=@systemPath@/bin:@systemPath@/sbin:$PATH
wrapperDir=@wrapperDir@ wrapperDir=@wrapperDir@
if test -d $wrapperDir; then rm -f $wrapperDir/*; fi if test -d $wrapperDir; then rm -f $wrapperDir/*; fi
mkdir -p $wrapperDir mkdir -p $wrapperDir
for i in @setuidPrograms@; do for i in @setuidPrograms@; do
program=$(type -tp $i) program=$(type -tp $i)
cp $(type -tp setuid-wrapper) $wrapperDir/$i cp "$(type -tp setuid-wrapper)" $wrapperDir/$i
echo -n $program > $wrapperDir/$i.real echo -n $program > $wrapperDir/$i.real
chown root.root $wrapperDir/$i chown root.root $wrapperDir/$i
chmod 4755 $wrapperDir/$i chmod 4755 $wrapperDir/$i

View File

@ -1,4 +1,4 @@
{pkgs, upstartJobs}: {pkgs, upstartJobs, systemPath, wrapperDir}:
import ../helpers/make-etc.nix { import ../helpers/make-etc.nix {
inherit (pkgs) stdenv; inherit (pkgs) stdenv;
@ -59,6 +59,15 @@ import ../helpers/make-etc.nix {
}; };
target = "dhclient-exit-hooks"; target = "dhclient-exit-hooks";
} }
{ # Script executed when the shell starts.
source = pkgs.substituteAll {
src = ./etc/profile.sh;
inherit systemPath wrapperDir;
inherit (pkgs) kernel;
};
target = "profile";
}
] ]
# A bunch of PAM configuration files for various programs. # A bunch of PAM configuration files for various programs.

56
system/etc/profile.sh Normal file
View File

@ -0,0 +1,56 @@
export PATH=@wrapperDir@:@systemPath@/bin:@systemPath@/sbin
export MODULE_DIR=@kernel@/lib/modules
export NIX_CONF_DIR=/nix/etc/nix
export PAGER=less
PROMPT_COLOR="1;31m"
PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]$\[\033[0m\] "
if test "x$TERM" == "xxterm"; then
PS1="\033]2;\h:\u:\w\007\033]1;$PS1"
fi
if test "$USER" != root; then
export NIX_REMOTE=daemon
fi
# Set up the per-user profile.
NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER
mkdir -m 0755 -p $NIX_USER_PROFILE_DIR
if test "$(stat --printf '%U' $NIX_USER_PROFILE_DIR)" != "$USER"; then
echo "WARNING: bad ownership on $_NIX_PROFILE_DIR" >&2
fi
if ! test -L $HOME/.nix-profile; then
echo "creating $HOME/.nix-profile" >&2
ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile
fi
NIX_PROFILES="/nix/var/nix/profiles/default $NIX_USER_PROFILE_DIR/profile"
for i in $NIX_PROFILES; do # !!! reverse
export PATH=$i/bin:$PATH
done
# Set up a default Nix expression from which to install stuff.
if ! test -L $HOME/.nix-defexpr; then
echo "creating $HOME/.nix-defexpr" >&2
ln -s /etc/nixos/install-source.nix $HOME/.nix-defexpr
fi
# Some aliases.
alias ls="ls --color=tty"
alias ll="ls -l"
alias which="type -p"
# Read system-wide modifications.
if test -f /etc/profile.local; then
source /etc/profile.local
fi
# Read user modifications.
test -r $HOME/.bashrc && source $HOME/.bashrc

View File

@ -123,20 +123,22 @@ rec {
# The static parts of /etc. # The static parts of /etc.
etc = import ./etc.nix { etc = import ./etc.nix {
inherit pkgs upstartJobs; inherit pkgs upstartJobs systemPath wrapperDir;
}; };
# The wrapper setuid programs (since we can't have setuid programs # The wrapper setuid programs (since we can't have setuid programs
# in the Nix store). # in the Nix store).
wrapperDir = "/var/setuid-wrappers";
setuidWrapper = import ../helpers/setuid { setuidWrapper = import ../helpers/setuid {
inherit (pkgs) stdenv; inherit (pkgs) stdenv;
wrapperDir = "/var/setuid-wrappers"; inherit wrapperDir;
}; };
# The packages you want in the boot environment. # The packages you want in the boot environment.
fullPath = [ systemPathList = [
pkgs.bash pkgs.bash
pkgs.bzip2 pkgs.bzip2
pkgs.coreutils pkgs.coreutils
@ -178,6 +180,18 @@ rec {
]; ];
# We don't want to put all of `startPath' and `path' in $PATH, since
# then we get an embarrassingly long $PATH. So use the user
# environment builder to make a directory with symlinks to those
# packages.
systemPath = pkgs.buildEnv {
name = "system-path";
paths = systemPathList;
pathsToLink = ["/bin" "/sbin" "/man" "/share"];
ignoreCollisions = true;
};
# The script that activates the configuration, i.e., it sets up # The script that activates the configuration, i.e., it sets up
# /etc, accounts, etc. It doesn't do anything that can only be done # /etc, accounts, etc. It doesn't do anything that can only be done
# at boot time (such as start `init'). # at boot time (such as start `init').
@ -185,12 +199,11 @@ rec {
src = ./activate-configuration.sh; src = ./activate-configuration.sh;
isExecutable = true; isExecutable = true;
inherit etc; inherit etc wrapperDir systemPath;
inherit (pkgs) kernel; inherit (pkgs) kernel;
readOnlyRoot = config.get ["boot" "readOnlyRoot"]; readOnlyRoot = config.get ["boot" "readOnlyRoot"];
hostName = config.get ["networking" "hostName"]; hostName = config.get ["networking" "hostName"];
setuidPrograms = config.get ["security" "setuidPrograms"]; setuidPrograms = config.get ["security" "setuidPrograms"];
wrapperDir = setuidWrapper.wrapperDir;
path = [ path = [
pkgs.coreutils pkgs.gnugrep pkgs.findutils pkgs.coreutils pkgs.gnugrep pkgs.findutils
@ -198,16 +211,6 @@ rec {
pkgs.pwdutils pkgs.pwdutils
]; ];
# We don't want to put all of `startPath' and `path' in $PATH, since
# then we get an embarrassingly long $PATH. So use the user
# environment builder to make a directory with symlinks to those
# packages.
fullPath = pkgs.buildEnv {
name = "boot-stage-2-path";
paths = fullPath;
pathsToLink = ["/bin" "/sbin" "/man" "/share"];
ignoreCollisions = true;
};
}; };