@@ -0,0 +1,128 @@
1+#!/bin/sh
2+
3+set -e
4+
5+dest="/nix"
6+self="."
7+nix="@nix@"
8+cacert="@cacert@"
9+
10+if ! [ -e $self/.reginfo ]; then
11+ echo "$0: incomplete installer (.reginfo is missing)" >&2
12+ exit 1
13+fi
14+
15+if [ -z "$USER" ]; then
16+ echo "$0: \$USER is not set" >&2
17+ exit 1
18+fi
19+
20+if [ "$(id -u)" -eq 0 ]; then
21+ printf '\e[1;31mwarning: installing Nix as root is not supported by this script!\e[0m\n'
22+fi
23+
24+echo "performing a single-user installation of Nix..." >&2
25+
26+if ! [ -e $dest ]; then
27+ cmd="mkdir -m 0755 $dest && chown $USER $dest"
28+ echo "directory $dest does not exist; creating it by running '$cmd' using sudo" >&2
29+ if ! sudo sh -c "$cmd"; then
30+ echo "$0: please manually run ‘$cmd’ as root to create $dest" >&2
31+ exit 1
32+ fi
33+fi
34+
35+if ! [ -w $dest ]; then
36+ 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
37+ exit 1
38+fi
39+
40+mkdir -p $dest/store
41+
42+echo -n "copying Nix to $dest/store..." >&2
43+
44+for i in $(cd $self/store >/dev/null && echo *); do
45+ echo -n "." >&2
46+ i_tmp="$dest/store/$i.$$"
47+ if [ -e "$i_tmp" ]; then
48+ rm -rf "$i_tmp"
49+ fi
50+ if ! [ -e "$dest/store/$i" ]; then
51+ cp -Rp "$self/store/$i" "$i_tmp"
52+ chmod -R a-w "$i_tmp"
53+ chmod +w "$i_tmp"
54+ mv "$i_tmp" "$dest/store/$i"
55+ chmod -w "$dest/store/$i"
56+ fi
57+done
58+echo "" >&2
59+
60+echo "initialising Nix database..." >&2
61+if ! $nix/bin/nix-store --init; then
62+ echo "$0: failed to initialize the Nix database" >&2
63+ exit 1
64+fi
65+
66+if ! $nix/bin/nix-store --load-db < $self/.reginfo; then
67+ echo "$0: unable to register valid paths" >&2
68+ exit 1
69+fi
70+
71+. $nix/etc/profile.d/nix.sh
72+
73+if ! $nix/bin/nix-env -i "$nix"; then
74+ echo "$0: unable to install Nix into your default profile" >&2
75+ exit 1
76+fi
77+
78+# Install an SSL certificate bundle.
79+if [ -z "$SSL_CERT_FILE" -o ! -f "$SSL_CERT_FILE" ]; then
80+ $nix/bin/nix-env -i "$cacert"
81+ export SSL_CERT_FILE="$HOME/.nix-profile/etc/ssl/certs/ca-bundle.crt"
82+fi
83+
84+# Subscribe the user to the Nixpkgs channel and fetch it.
85+if ! $nix/bin/nix-channel --list | grep -q "^nixpkgs "; then
86+ $nix/bin/nix-channel --add https://nixos.org/channels/nixpkgs-unstable
87+fi
88+if [ -z "$_NIX_INSTALLER_TEST" ]; then
89+ $nix/bin/nix-channel --update nixpkgs
90+fi
91+
92+# Make the shell source nix.sh during login.
93+p=$HOME/.nix-profile/etc/profile.d/nix.sh
94+
95+added=
96+for i in .bash_profile .bash_login .profile; do
97+ fn="$HOME/$i"
98+ if [ -w "$fn" ]; then
99+ if ! grep -q "$p" "$fn"; then
100+ echo "modifying $fn..." >&2
101+ echo "if [ -e $p ]; then . $p; fi # added by Nix installer" >> $fn
102+ fi
103+ added=1
104+ break
105+ fi
106+done
107+
108+if [ -z "$added" ]; then
109+ cat >&2 <<EOF
110+
111+Installation finished! To ensure that the necessary environment
112+variables are set, please add the line
113+
114+ . $p
115+
116+to your shell profile (e.g. ~/.profile).
117+EOF
118+else
119+ cat >&2 <<EOF
120+
121+Installation finished! To ensure that the necessary environment
122+variables are set, either log in again, or type
123+
124+ . $p
125+
126+in your shell.
127+EOF
128+fi