Binary tarball: Automatically create /nix

The tarball can now be unpacked anywhere.  The installation script
uses "sudo" to create /nix if it doesn't exist.  It also fetches the
nixpkgs-unstable channel.
This commit is contained in:
Eelco Dolstra 2014-02-10 16:35:59 +01:00
parent c5839752b9
commit 57386c9bae
3 changed files with 117 additions and 37 deletions

View file

@ -69,27 +69,26 @@ $ dpkg -i nix_1.0-1_amd64.deb</screen>
<para>For other platforms, including Mac OS X (Darwin), FreeBSD and <para>For other platforms, including Mac OS X (Darwin), FreeBSD and
other Linux distributions, you can download a binary tarball. It other Linux distributions, you can download a binary tarball. It
contains Nix and all its dependencies. You should unpack it in the contains Nix and all its dependencies. You should unpack it somewhere
root directory, then run <command>nix-finish-install</command>: (e.g. in <filename>/tmp</filename>), and then run the script named
<command>install</command> inside the binary tarball:
<screen> <screen>
$ cd / alice$ cd /tmp
$ tar xfj nix-1.1-x86_64-darwin.tar.bz2 alice$ tar xfj nix-1.1-x86_64-darwin.tar.bz2
$ nix-finish-install alice$ cd nix-1.1-x86_64-darwin
alice$ ./install
</screen> </screen>
After this you can delete You should run this under your usual user account,
<filename>/usr/bin/nix-finish-install</filename>.</para> <emphasis>not</emphasis> as root. The script will invoke
<command>sudo</command> to create <filename>/nix</filename> if it
<para>If you plan to use Nix from a single non-root user account, its doesnt already exist. If you dont have <command>sudo</command>, you
probably convenient to change the ownership of the entire Nix store should manually create <command>/nix</command> first as root:
and database to that user account. In that case, install as follows:
<screen> <screen>
alice$ cd / $ mkdir /nix
alice$ sudo tar xfj nix-1.1-x86_64-darwin.tar.bz2 $ chown alice /nix
alice$ sudo chown -R alice /nix
alice$ nix-finish-install
</screen> </screen>
</para> </para>

View file

@ -124,15 +124,19 @@ let
storePaths=$(perl ${pathsFromGraph} ./closure) storePaths=$(perl ${pathsFromGraph} ./closure)
printRegistration=1 perl ${pathsFromGraph} ./closure > $TMPDIR/reginfo printRegistration=1 perl ${pathsFromGraph} ./closure > $TMPDIR/reginfo
substitute ${./scripts/install-nix-from-closure.sh} $TMPDIR/install \ substitute ${./scripts/install-nix-from-closure.sh} $TMPDIR/install \
--subst-var-by nix ${toplevel} --subst-var-by regInfo /nix/store/reginfo --subst-var-by nix ${toplevel}
chmod +x $TMPDIR/install chmod +x $TMPDIR/install
fn=$out/nix-${version}-${system}.tar.bz2 dir=nix-${version}-${system}
fn=$out/$dir.tar.bz2
mkdir -p $out/nix-support mkdir -p $out/nix-support
echo "file binary-dist $fn" >> $out/nix-support/hydra-build-products echo "file binary-dist $fn" >> $out/nix-support/hydra-build-products
tar cvfj $fn \ tar cvfj $fn \
--owner=0 --group=0 --absolute-names \ --owner=0 --group=0 --mode=u+rw,uga+r \
--transform "s,$TMPDIR/install,/usr/bin/nix-finish-install," \ --absolute-names \
--transform "s,$TMPDIR/reginfo,/nix/store/reginfo," \ --hard-dereference \
--transform "s,$TMPDIR/install,$dir/install," \
--transform "s,$TMPDIR/reginfo,$dir/.reginfo," \
--transform "s,$NIX_STORE,$dir/store,S" \
$TMPDIR/install $TMPDIR/reginfo $storePaths $TMPDIR/install $TMPDIR/reginfo $storePaths
''); '');

View file

@ -1,17 +1,74 @@
#! /bin/sh -e #! /bin/sh
nix=@nix@ set -e
regInfo=@regInfo@
if ! $nix/bin/nix-store --load-db < $regInfo; then dest="/nix"
echo "$0: unable to register valid paths" self="$(dirname "$0")"
nix="@nix@"
if ! [ -e $self/.reginfo ]; then
echo "$0: incomplete installer (.reginfo is missing)" >&2
exit 1 exit 1
fi fi
. @nix@/etc/profile.d/nix.sh if [ -z "$USER" ]; then
echo "$0: \$USER is not set" >&2
exit 1
fi
if ! $nix/bin/nix-env -i @nix@; then if [ "$(id -u)" -eq 0 ]; then
echo "$0: unable to install Nix into your default profile" echo "warning: installing Nix as root is not recommended" >&2
exit 1
fi
echo "performing a single-user installation of Nix..." >&2
if ! [ -e $dest ]; then
cmd="mkdir -m 0755 $dest && chown $USER $dest"
echo "directory $dest does not exist; creating it by running \`$cmd' using sudo" >&2
if ! sudo sh -c "$cmd"; then
echo "$0: please manually run \`$cmd' as root to create $dest" >&2
exit 1
fi
fi
if ! [ -w $dest ]; then
echo "$0: directory $dest exists, but is not writable by you; please run \`chown -R $USER $dest' as root" >&2
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
cp -rp "$self/store/$i" "$i_tmp"
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
exit 1
fi
if ! $nix/bin/nix-store --load-db < $self/.reginfo; then
echo "$0: unable to register valid paths" >&2
exit 1
fi
. $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
exit 1 exit 1
fi fi
@ -21,20 +78,40 @@ if ! $nix/bin/nix-channel --list | grep -q "^nixpkgs "; then
fi fi
$nix/bin/nix-channel --update nixpkgs $nix/bin/nix-channel --update nixpkgs
# Add nix.sh to the shell's profile.d directory. # Make the shell source nix.sh during login.
p=$NIX_LINK/etc/profile.d/nix.sh p=$NIX_LINK/etc/profile.d/nix.sh
if [ -w /etc/profile.d ]; then added=
ln -s $p /etc/profile.d/ for i in .bash_profile .bash_login .profile; do
elif [ -w /usr/local/etc/profile.d ]; then fn="$HOME/$i"
ln -s $p /usr/local/etc/profile.d/ if [ -e "$fn" ]; then
else if ! grep -q "$p" "$fn"; then
cat <<EOF echo "modifying $fn..." >&2
Installation finished. To ensure that the necessary environment 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
variables are set, please add the line variables are set, please add the line
source $p . $p
to your shell profile (e.g. ~/.profile). to your shell profile (e.g. ~/.profile).
EOF EOF
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
fi fi