2014-10-07 15:40:31 +00:00
#!/bin/sh
2012-05-22 22:36:54 +00:00
2014-02-10 15:35:59 +00:00
set -e
2012-05-22 22:36:54 +00:00
2014-02-10 15:35:59 +00:00
dest = "/nix"
self = " $( dirname " $0 " ) "
nix = "@nix@"
2014-12-10 15:05:08 +00:00
cacert = "@cacert@"
2014-02-10 15:35:59 +00:00
2017-01-24 18:59:55 +00:00
2016-12-02 13:18:50 +00:00
if ! [ -e " $self /.reginfo " ] ; then
2014-02-10 15:35:59 +00:00
echo " $0 : incomplete installer (.reginfo is missing) " >& 2
fi
if [ -z " $USER " ] ; then
echo " $0 : \$USER is not set " >& 2
exit 1
fi
2017-07-09 17:07:28 +00:00
if [ -z " $HOME " ] ; then
echo " $0 : \$HOME is not set " >& 2
exit 1
fi
# macOS support for 10.10 or higher
if [ " $( uname -s) " = "Darwin" ] ; then
if [ $(( $( sw_vers -productVersion | cut -d '.' -f 2) )) -lt 10 ] ; then
echo " $0 : macOS $( sw_vers -productVersion) is not supported, upgrade to 10.10 or higher "
exit 1
fi
2018-04-19 17:37:54 +00:00
fi
2017-07-09 17:07:28 +00:00
2018-09-01 12:51:32 +00:00
# Determine if we could use the multi-user installer or not
2018-04-19 17:37:54 +00:00
if [ " $( uname -s) " = "Darwin" ] ; then
2018-09-01 12:51:32 +00:00
echo "Note: a multi-user installation is possible. See https://nixos.org/nix/manual/#sect-multi-user-installation" >& 2
2018-04-19 17:37:54 +00:00
elif [ " $( uname -s) " = "Linux" ] && [ -e /run/systemd/system ] ; then
2018-09-01 12:51:32 +00:00
echo "Note: a multi-user installation is possible. See https://nixos.org/nix/manual/#sect-multi-user-installation" >& 2
2018-04-19 17:37:54 +00:00
fi
2018-09-01 12:51:32 +00:00
INSTALL_MODE = no-daemon
2018-04-19 17:37:54 +00:00
# Trivially handle the --daemon / --no-daemon options
if [ " x ${ 1 :- } " = "x--no-daemon" ] ; then
INSTALL_MODE = no-daemon
elif [ " x ${ 1 :- } " = "x--daemon" ] ; then
INSTALL_MODE = daemon
elif [ " x ${ 1 :- } " != "x" ] ; then
(
echo "Nix Installer [--daemon|--no-daemon]"
2018-09-01 12:51:32 +00:00
echo "Choose installation method."
2018-04-19 17:37:54 +00:00
echo ""
2018-09-01 12:51:32 +00:00
echo " --daemon: Installs and configures a background daemon that manages the store,"
echo " providing multi-user support and better isolation for local builds."
echo " Both for security and reproducibility, this method is recommended if"
echo " supported on your platform."
echo " See https://nixos.org/nix/manual/#sect-multi-user-installation"
2018-04-19 17:37:54 +00:00
echo ""
2018-09-01 12:51:32 +00:00
echo " --no-daemon: Simple, single-user installation that does not require root and is"
echo " trivial to uninstall."
echo " (default)"
2018-04-19 17:37:54 +00:00
echo ""
) >& 2
exit
2018-03-28 13:16:13 +00:00
fi
2018-04-19 17:37:54 +00:00
if [ " $INSTALL_MODE " = "daemon" ] ; then
2018-03-28 13:16:13 +00:00
printf '\e[1;31mSwitching to the Daemon-based Installer\e[0m\n'
exec " $self /install-multi-user "
2017-07-09 17:07:28 +00:00
exit 0
fi
2014-02-10 15:35:59 +00:00
if [ " $( id -u) " -eq 0 ] ; then
2014-11-18 13:49:42 +00:00
printf '\e[1;31mwarning: installing Nix as root is not supported by this script!\e[0m\n'
2014-02-10 15:35:59 +00: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 19:02:48 +00:00
echo " directory $dest does not exist; creating it by running ' $cmd ' using sudo " >& 2
2014-02-10 15:35:59 +00:00
if ! sudo sh -c " $cmd " ; then
2017-07-30 11:27:57 +00:00
echo " $0 : please manually run ' $cmd ' as root to create $dest " >& 2
2014-02-10 15:35:59 +00:00
exit 1
fi
fi
if ! [ -w $dest ] ; then
2017-07-30 11:27:57 +00: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 15:35:59 +00:00
exit 1
fi
mkdir -p $dest /store
2016-12-02 13:18:50 +00:00
printf "copying Nix to %s..." " ${ dest } /store " >& 2
2014-02-10 15:35:59 +00:00
2016-12-02 13:18:50 +00:00
for i in $( cd " $self /store " >/dev/null && echo ./*) ; do
printf "." >& 2
2014-02-10 15:35:59 +00:00
i_tmp = " $dest /store/ $i . $$ "
if [ -e " $i_tmp " ] ; then
rm -rf " $i_tmp "
fi
if ! [ -e " $dest /store/ $i " ] ; then
2014-02-26 16:23:23 +00:00
cp -Rp " $self /store/ $i " " $i_tmp "
2014-10-07 15:40:31 +00:00
chmod -R a-w " $i_tmp "
chmod +w " $i_tmp "
2014-02-10 15:35:59 +00:00
mv " $i_tmp " " $dest /store/ $i "
2014-10-07 15:40:31 +00:00
chmod -w " $dest /store/ $i "
2014-02-10 15:35:59 +00:00
fi
done
echo "" >& 2
2016-12-02 13:18:50 +00:00
if ! " $nix /bin/nix-store " --load-db < " $self /.reginfo " ; then
2014-02-10 15:35:59 +00:00
echo " $0 : unable to register valid paths " >& 2
exit 1
fi
2012-05-22 22:36:54 +00:00
2016-12-02 13:18:50 +00:00
. " $nix /etc/profile.d/nix.sh "
2014-02-10 15:35:59 +00:00
2016-12-02 13:18:50 +00:00
if ! " $nix /bin/nix-env " -i " $nix " ; then
2014-02-10 15:35:59 +00:00
echo " $0 : unable to install Nix into your default profile " >& 2
2012-05-22 22:36:54 +00:00
exit 1
fi
2014-12-13 15:53:21 +00:00
# Install an SSL certificate bundle.
2016-12-02 13:18:50 +00:00
if [ -z " $NIX_SSL_CERT_FILE " ] || ! [ -f " $NIX_SSL_CERT_FILE " ] ; then
2014-12-13 15:53:21 +00:00
$nix /bin/nix-env -i " $cacert "
2016-10-13 15:09:10 +00:00
export NIX_SSL_CERT_FILE = " $HOME /.nix-profile/etc/ssl/certs/ca-bundle.crt "
2014-12-13 15:53:21 +00:00
fi
2014-02-10 09:50:29 +00:00
# Subscribe the user to the Nixpkgs channel and fetch it.
if ! $nix /bin/nix-channel --list | grep -q "^nixpkgs " ; then
2014-12-10 10:35:56 +00:00
$nix /bin/nix-channel --add https://nixos.org/channels/nixpkgs-unstable
2014-02-10 09:50:29 +00:00
fi
2014-11-18 13:49:42 +00:00
if [ -z " $_NIX_INSTALLER_TEST " ] ; then
2019-02-13 10:28:28 +00:00
if ! $nix /bin/nix-channel --update nixpkgs; then
echo "Fetching the nixpkgs channel failed. (Are you offline?)"
echo "To try again later, run \"nix-channel --update nixpkgs\"."
fi
2014-11-18 13:49:42 +00:00
fi
2014-02-10 09:50:29 +00:00
2014-02-10 15:35:59 +00:00
added =
2016-11-03 17:02:29 +00:00
if [ -z " $NIX_INSTALLER_NO_MODIFY_PROFILE " ] ; then
# Make the shell source nix.sh during login.
p = $HOME /.nix-profile/etc/profile.d/nix.sh
for i in .bash_profile .bash_login .profile; do
fn = " $HOME / $i "
if [ -w " $fn " ] ; then
if ! grep -q " $p " " $fn " ; then
echo " modifying $fn ... " >& 2
2016-12-02 13:18:50 +00:00
echo " if [ -e $p ]; then . $p ; fi # added by Nix installer " >> " $fn "
2016-11-03 17:02:29 +00:00
fi
added = 1
break
2014-02-10 15:35:59 +00:00
fi
2016-11-03 17:02:29 +00:00
done
fi
2014-02-10 15:35:59 +00:00
if [ -z " $added " ] ; then
cat >& 2 <<EOF
Installation finished! To ensure that the necessary environment
2012-05-22 22:36:54 +00:00
variables are set, please add the line
2014-02-10 15:35:59 +00:00
. $p
2012-05-22 22:36:54 +00:00
to your shell profile ( e.g. ~/.profile) .
EOF
2014-02-10 15:35:59 +00: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 09:50:29 +00:00
fi