From 57386c9baee78e50eb0c4a901ca9e1c147dc9777 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Feb 2014 16:35:59 +0100 Subject: 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. --- scripts/install-nix-from-closure.sh | 111 ++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 17 deletions(-) (limited to 'scripts/install-nix-from-closure.sh') diff --git a/scripts/install-nix-from-closure.sh b/scripts/install-nix-from-closure.sh index 00f23e0f4c7f..454cb432fbc7 100644 --- a/scripts/install-nix-from-closure.sh +++ b/scripts/install-nix-from-closure.sh @@ -1,17 +1,74 @@ -#! /bin/sh -e +#! /bin/sh -nix=@nix@ -regInfo=@regInfo@ +set -e -if ! $nix/bin/nix-store --load-db < $regInfo; then - echo "$0: unable to register valid paths" +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 + 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 -. @nix@/etc/profile.d/nix.sh +if ! $nix/bin/nix-store --load-db < $self/.reginfo; then + echo "$0: unable to register valid paths" >&2 + exit 1 +fi -if ! $nix/bin/nix-env -i @nix@; then - echo "$0: unable to install Nix into your default profile" +. $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 fi @@ -21,20 +78,40 @@ if ! $nix/bin/nix-channel --list | grep -q "^nixpkgs "; then fi $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 -if [ -w /etc/profile.d ]; then - ln -s $p /etc/profile.d/ -elif [ -w /usr/local/etc/profile.d ]; then - ln -s $p /usr/local/etc/profile.d/ -else - cat <&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 <&2 <