2014-10-07 17:40:31 +02:00
#!/bin/sh
2012-05-23 00:36:54 +02:00
2014-02-10 16:35:59 +01:00
set -e
2012-05-23 00:36:54 +02:00
2014-02-10 16:35:59 +01:00
dest = "/nix"
self = " $( dirname " $0 " ) "
nix = "@nix@"
2014-12-10 16:05:08 +01:00
cacert = "@cacert@"
2014-02-10 16:35:59 +01:00
if ! [ -e $self /.reginfo ] ; then
echo " $0 : incomplete installer (.reginfo is missing) " >& 2
exit 1
fi
if [ -z " $USER " ] ; then
echo " $0 : \$USER is not set " >& 2
exit 1
fi
if [ " $( id -u) " -eq 0 ] ; then
2014-11-18 14:49:42 +01:00
printf '\e[1;31mwarning: installing Nix as root is not supported by this script!\e[0m\n'
2014-02-10 16:35:59 +01:00
fi
echo "performing a single-user installation of Nix..." >& 2
if ! [ -e $dest ] ; then
cmd = " mkdir -m 0755 $dest && chown $USER $dest "
2016-05-18 21:02:48 +02:00
echo " directory $dest does not exist; creating it by running ' $cmd ' using sudo " >& 2
2014-02-10 16:35:59 +01:00
if ! sudo sh -c " $cmd " ; then
2014-08-20 17:00:17 +02:00
echo " $0 : please manually run ‘ $cmd ’ as root to create $dest " >& 2
2014-02-10 16:35:59 +01:00
exit 1
fi
fi
if ! [ -w $dest ] ; then
2015-12-06 18:00:03 +01:00
echo " $0 : directory $dest exists, but is not writable by you. This could indicate that another user has already performed a single-user installation of Nix on this system. If you wish to enable multi-user support see http://nixos.org/nix/manual/#ssec-multi-user. If you wish to continue with a single-user install for $USER please run ‘ chown -R $USER $dest ’ as root." >& 2
2014-02-10 16:35:59 +01:00
exit 1
fi
mkdir -p $dest /store
echo -n " copying Nix to $dest /store... " >& 2
2015-02-11 19:39:14 +01:00
for i in $( cd $self /store >/dev/null && echo *) ; do
2014-02-10 16:35:59 +01:00
echo -n "." >& 2
i_tmp = " $dest /store/ $i . $$ "
if [ -e " $i_tmp " ] ; then
rm -rf " $i_tmp "
fi
if ! [ -e " $dest /store/ $i " ] ; then
2014-02-26 17:23:23 +01:00
cp -Rp " $self /store/ $i " " $i_tmp "
2014-10-07 17:40:31 +02:00
chmod -R a-w " $i_tmp "
chmod +w " $i_tmp "
2014-02-10 16:35:59 +01:00
mv " $i_tmp " " $dest /store/ $i "
2014-10-07 17:40:31 +02:00
chmod -w " $dest /store/ $i "
2014-02-10 16:35:59 +01:00
fi
done
echo "" >& 2
echo "initialising Nix database..." >& 2
if ! $nix /bin/nix-store --init; then
echo " $0 : failed to initialize the Nix database " >& 2
2012-05-23 00:36:54 +02:00
exit 1
fi
2014-02-10 16:35:59 +01:00
if ! $nix /bin/nix-store --load-db < $self /.reginfo; then
echo " $0 : unable to register valid paths " >& 2
exit 1
fi
2012-05-23 00:36:54 +02:00
2014-02-10 16:35:59 +01:00
. $nix /etc/profile.d/nix.sh
2014-12-10 16:05:08 +01:00
if ! $nix /bin/nix-env -i " $nix " ; then
2014-02-10 16:35:59 +01:00
echo " $0 : unable to install Nix into your default profile " >& 2
2012-05-23 00:36:54 +02:00
exit 1
fi
2014-12-13 16:53:21 +01:00
# Install an SSL certificate bundle.
2016-10-13 17:09:10 +02:00
if [ -z " $NIX_SSL_CERT_FILE " -o ! -f " $NIX_SSL_CERT_FILE " ] ; then
2014-12-13 16:53:21 +01:00
$nix /bin/nix-env -i " $cacert "
2016-10-13 17:09:10 +02:00
export NIX_SSL_CERT_FILE = " $HOME /.nix-profile/etc/ssl/certs/ca-bundle.crt "
2014-12-13 16:53:21 +01:00
fi
2014-02-10 10:50:29 +01:00
# Subscribe the user to the Nixpkgs channel and fetch it.
if ! $nix /bin/nix-channel --list | grep -q "^nixpkgs " ; then
2014-12-10 11:35:56 +01:00
$nix /bin/nix-channel --add https://nixos.org/channels/nixpkgs-unstable
2014-02-10 10:50:29 +01:00
fi
2014-11-18 14:49:42 +01:00
if [ -z " $_NIX_INSTALLER_TEST " ] ; then
$nix /bin/nix-channel --update nixpkgs
fi
2014-02-10 10:50:29 +01:00
2014-02-10 16:35:59 +01:00
# Make the shell source nix.sh during login.
2016-05-31 15:14:24 +02:00
p = $HOME /.nix-profile/etc/profile.d/nix.sh
2012-05-23 00:36:54 +02:00
2014-02-10 16:35:59 +01:00
added =
for i in .bash_profile .bash_login .profile; do
fn = " $HOME / $i "
2015-05-25 06:49:44 +02:00
if [ -w " $fn " ] ; then
2014-02-10 16:35:59 +01:00
if ! grep -q " $p " " $fn " ; then
echo " modifying $fn ... " >& 2
echo " if [ -e $p ]; then . $p ; fi # added by Nix installer " >> $fn
fi
added = 1
break
fi
done
if [ -z " $added " ] ; then
cat >& 2 <<EOF
Installation finished! To ensure that the necessary environment
2012-05-23 00:36:54 +02:00
variables are set, please add the line
2014-02-10 16:35:59 +01:00
. $p
2012-05-23 00:36:54 +02:00
to your shell profile ( e.g. ~/.profile) .
EOF
2014-02-10 16:35:59 +01:00
else
cat >& 2 <<EOF
Installation finished! To ensure that the necessary environment
variables are set, either log in again, or type
. $p
in your shell.
EOF
2014-02-10 10:50:29 +01:00
fi