2014-02-10 16:42:36 +00:00
|
|
|
|
#! /usr/bin/env bash
|
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@"
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
echo "warning: installing Nix as root is not recommended" >&2
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "performing a single-user installation of Nix..." >&2
|
|
|
|
|
|
|
|
|
|
if ! [ -e $dest ]; then
|
|
|
|
|
cmd="mkdir -m 0755 $dest && chown $USER $dest"
|
2014-08-20 15:00:17 +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
|
2014-08-20 15:00:17 +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
|
2014-08-20 15:00:17 +00:00
|
|
|
|
echo "$0: directory $dest exists, but is not writable by you; please run ‘chown -R $USER $dest’ as root" >&2
|
2014-02-10 15:35:59 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
mkdir -p $dest/store
|
|
|
|
|
|
|
|
|
|
echo -n "copying Nix to $dest/store..." >&2
|
|
|
|
|
|
|
|
|
|
for i in $(cd $self/store && echo *); do
|
|
|
|
|
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 16:23:23 +00:00
|
|
|
|
cp -Rp "$self/store/$i" "$i_tmp"
|
2014-02-10 15:35:59 +00:00
|
|
|
|
mv "$i_tmp" "$dest/store/$i"
|
|
|
|
|
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-22 22:36:54 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2014-02-10 15:35:59 +00:00
|
|
|
|
if ! $nix/bin/nix-store --load-db < $self/.reginfo; then
|
|
|
|
|
echo "$0: unable to register valid paths" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2012-05-22 22:36:54 +00:00
|
|
|
|
|
2014-02-10 15:35:59 +00:00
|
|
|
|
. $nix/etc/profile.d/nix.sh
|
|
|
|
|
|
|
|
|
|
if ! $nix/bin/nix-env -i $nix; then
|
|
|
|
|
echo "$0: unable to install Nix into your default profile" >&2
|
2012-05-22 22:36:54 +00:00
|
|
|
|
exit 1
|
|
|
|
|
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-08-07 13:36:54 +00:00
|
|
|
|
if [ -n "$SSL_CERT_FILE" ]; then
|
|
|
|
|
$nix/bin/nix-channel --add https://nixos.org/channels/nixpkgs-unstable
|
|
|
|
|
else
|
|
|
|
|
$nix/bin/nix-channel --add http://nixos.org/channels/nixpkgs-unstable
|
|
|
|
|
fi
|
2014-02-10 09:50:29 +00:00
|
|
|
|
fi
|
|
|
|
|
$nix/bin/nix-channel --update nixpkgs
|
|
|
|
|
|
2014-07-29 15:12:15 +00:00
|
|
|
|
# Install an SSL certificate bundle.
|
|
|
|
|
$nix/bin/nix-env -iA nixpkgs.cacert || true
|
|
|
|
|
|
2014-02-10 15:35:59 +00:00
|
|
|
|
# Make the shell source nix.sh during login.
|
2012-05-22 22:36:54 +00:00
|
|
|
|
p=$NIX_LINK/etc/profile.d/nix.sh
|
|
|
|
|
|
2014-02-10 15:35:59 +00:00
|
|
|
|
added=
|
|
|
|
|
for i in .bash_profile .bash_login .profile; do
|
|
|
|
|
fn="$HOME/$i"
|
|
|
|
|
if [ -e "$fn" ]; then
|
|
|
|
|
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-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
|