* The installer now takes a user-specified Nix expression that will be

built in the target Nix store and installed in the "system" user
  environment.  Not quite sure what should go in there, but probably
  the kernel, initrd, the boot scripts and eventually the system
  services.  Maybe grub as well.

svn path=/nixu/trunk/; revision=6993
This commit is contained in:
Eelco Dolstra 2006-11-11 22:31:26 +00:00
parent b7e8c174a1
commit afc05314c4

View File

@ -13,33 +13,48 @@
# * run hook scripts provided by packages in the configuration? # * run hook scripts provided by packages in the configuration?
# - install/update grub # - install/update grub
targetDevice="$1" set -e
if test -z "$targetDevice"; then targetDevice="$1"
echo "syntax: installer.sh <targetDevice>" nixExpr="$2"
if test -z "$targetDevice" -o -z "$nixExpr"; then
echo "syntax: installer.sh <targetDevice> <nixExpr>"
exit 1 exit 1
fi fi
nixExpr=$(readlink -f "$nixExpr")
# Make sure that the target device isn't mounted. # Make sure that the target device isn't mounted.
umount "$targetDevice" 2> /dev/null umount "$targetDevice" 2> /dev/null || true
# Check it. # Check it.
fsck "$targetDevice" || exit 1 fsck "$targetDevice"
# Mount the target device. # Mount the target device.
mountPoint=/tmp/inst-mnt mountPoint=/tmp/inst-mnt
mkdir -p $mountPoint mkdir -p $mountPoint
mount "$targetDevice" $mountPoint || exit 1 mount "$targetDevice" $mountPoint
mkdir -p $mountPoint/dev $mountPoint/proc $mountPoint/sys || exit 1 mkdir -p $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/mnt
mount --bind /dev $mountPoint/dev || exit 1 mount --rbind / $mountPoint/mnt
mount --bind /proc $mountPoint/proc || exit 1 mount --bind /dev $mountPoint/dev
mount --bind /sys $mountPoint/sys || exit 1 mount --bind /proc $mountPoint/proc
mount --bind /sys $mountPoint/sys
trap "umount $mountPoint/dev; umount $mountPoint/proc; umount $mountPoint/sys; umount $mountPoint" EXIT cleanup() {
for i in $(grep -F "$mountPoint" /proc/mounts \
| perl -e 'while (<>) { /^\S+\s+(\S+)\s+/; print "$1\n"; }' \
| sort -r);
do
umount $i
done
}
trap "cleanup" EXIT
mkdir -p $mountPoint/tmp mkdir -p $mountPoint/tmp
mkdir -p $mountPoint/var mkdir -p $mountPoint/var
@ -62,7 +77,7 @@ mkdir -p \
echo "copying Nix to $targetDevice...." echo "copying Nix to $targetDevice...."
for i in $(cat @nixClosure@); do for i in $(cat @nixClosure@); do
echo " $i" echo " $i"
rsync -a $i $mountPoint/nix/store/ || exit 1 rsync -a $i $mountPoint/nix/store/
done done
@ -76,7 +91,7 @@ for i in $(cat @nixClosure@); do
echo # deriver echo # deriver
echo 0 # nr of references echo 0 # nr of references
done \ done \
| chroot $mountPoint @nix@/bin/nix-store --register-validity || exit 1 | chroot $mountPoint @nix@/bin/nix-store --register-validity
# Create the required /bin/sh symlink; otherwise lots of things # Create the required /bin/sh symlink; otherwise lots of things
@ -90,16 +105,19 @@ mkdir -p $mountPoint/etc
cp /etc/resolv.conf $mountPoint/etc/ cp /etc/resolv.conf $mountPoint/etc/
# Do a nix-pull. # Do a nix-pull to speed up building.
nixpkgsURL=http://nix.cs.uu.nl/dist/nix/nixpkgs-0.11pre6984 nixpkgsURL=http://nix.cs.uu.nl/dist/nix/nixpkgs-0.11pre6984
chroot $mountPoint @nix@/bin/nix-pull $nixpkgsURL/MANIFEST chroot $mountPoint @nix@/bin/nix-pull $nixpkgsURL/MANIFEST
# Install some packages. # Build the specified Nix expression in the target store and install
rm -rf $mountPoint/scratch # it into the system configuration profile.
mkdir $mountPoint/scratch
curl $nixpkgsURL/nixexprs.tar.bz2 | tar xj -C $mountPoint/scratch
nixpkgsName=$(cd $mountPoint/scratch && ls) #rm -rf $mountPoint/scratch
#mkdir $mountPoint/scratch
#curl $nixpkgsURL/nixexprs.tar.bz2 | tar xj -C $mountPoint/scratch
#nixpkgsName=$(cd $mountPoint/scratch && ls)
chroot $mountPoint @nix@/bin/nix-env -f /scratch/$nixpkgsName -i aterm chroot $mountPoint @nix@/bin/nix-env \
-p /nix/var/nix/profiles/system \
-f "/mnt/$nixExpr" -i '*'