* The installer now installs a configuration on the target device that
boots into stage 1 (kernel+initrd) succesfully. `system-configuration.nix' contains the definition of the configuration to be installed. The attribute systemConfiguration is installed into the profile /nix/var/nix/profiles/system. Then the program /nix/var/nix/profiles/system/bin/switch-to-configuration is called to finalise the installation. This program (generated by system-configuration.sh) installs Grub on the drive with a menu that contains the entry for the desired kernel and initrd. In principle this allows us to do rollbacks to previous system configurations by doing `nix-env --rollback' and then calling switch-to-configuration to update Grub. Ideally this should be done in a single command (and we should consider the obvious risk of garbage collecting the current kernel etc. to which the current Grub menu points...). Maybe the responsibility for generating the Grub menu should be placed somewhere else. For instance, we could generate a Grub menu automatically out of all the generations in the `system' profile. svn path=/nixu/trunk/; revision=7009
This commit is contained in:
parent
0785dfb9f8
commit
0b26af2188
@ -31,7 +31,7 @@ umount "$targetDevice" 2> /dev/null || true
|
||||
|
||||
|
||||
# Check it.
|
||||
fsck "$targetDevice"
|
||||
fsck -n "$targetDevice"
|
||||
|
||||
|
||||
# Mount the target device.
|
||||
@ -107,7 +107,7 @@ cp /etc/resolv.conf $mountPoint/etc/
|
||||
|
||||
# Do a nix-pull to speed up building.
|
||||
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
|
||||
|
||||
|
||||
# Build the specified Nix expression in the target store and install
|
||||
@ -120,4 +120,15 @@ chroot $mountPoint @nix@/bin/nix-pull $nixpkgsURL/MANIFEST
|
||||
|
||||
chroot $mountPoint @nix@/bin/nix-env \
|
||||
-p /nix/var/nix/profiles/system \
|
||||
-f "/mnt/$nixExpr" -i '*'
|
||||
-f "/mnt/$nixExpr" -i system-configuration
|
||||
|
||||
|
||||
# Grub needs a mtab.
|
||||
echo "$targetDevice / somefs rw 0 0" > $mountPoint/etc/mtab
|
||||
|
||||
|
||||
# Switch to the new system configuration. This will install Grub with
|
||||
# a menu default pointing at the kernel/initrd/etc of the new
|
||||
# configuration.
|
||||
echo "finalising the installation..."
|
||||
chroot $mountPoint /nix/var/nix/profiles/system/bin/switch-to-configuration
|
||||
|
@ -10,11 +10,11 @@
|
||||
# A symlink `/init' is made to the store path passed in the `init'
|
||||
# argument.
|
||||
|
||||
{stdenv, cpio, packages, init}:
|
||||
{stdenv, cpio, packages, init, nix}:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "initrd";
|
||||
builder = ./make-initrd.sh;
|
||||
buildInputs = [cpio];
|
||||
buildInputs = [cpio nix];
|
||||
inherit packages init;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ set -o pipefail
|
||||
# way to get the closure is to call Nix, which is strictly speaking
|
||||
# forbidden. But we do it anyway. In time, we should add a feature
|
||||
# to Nix to let Nix pass closures to builders.
|
||||
packagesClosure=$(/nix/bin/nix-store -qR $packages $init)
|
||||
packagesClosure=$(nix-store -qR $packages $init)
|
||||
|
||||
# Paths in cpio archives *must* be relative, otherwise the kernel
|
||||
# won't unpack 'em.
|
||||
|
@ -14,6 +14,8 @@ in
|
||||
|
||||
rec {
|
||||
|
||||
inherit nixosInstaller; # !!! debug
|
||||
|
||||
|
||||
# Since the CD is read-only, the mount points must be on disk.
|
||||
cdMountPoints = pkgs.stdenv.mkDerivation {
|
||||
|
@ -59,7 +59,7 @@ rec {
|
||||
# The closure of the init script of boot stage 1 is what we put in
|
||||
# the initial RAM disk.
|
||||
initialRamdisk = import ./make-initrd.nix {
|
||||
inherit (pkgs) stdenv cpio;
|
||||
inherit (pkgs) stdenv cpio nix;
|
||||
packages = [];
|
||||
init = bootStage1;
|
||||
};
|
||||
|
32
test/system-configuration.nix
Normal file
32
test/system-configuration.nix
Normal file
@ -0,0 +1,32 @@
|
||||
let
|
||||
|
||||
# The root device.
|
||||
rootDevice = "/dev/hda1";
|
||||
|
||||
# The device on which GRUB should be installed (leave empty if you
|
||||
# don't want GRUB to be installed).
|
||||
grubDevice = "/dev/hda";
|
||||
|
||||
in
|
||||
|
||||
# Build boot scripts for the CD that find the CD-ROM automatically.
|
||||
with import ./rescue-system.nix {
|
||||
autoDetectRootDevice = false;
|
||||
inherit rootDevice;
|
||||
};
|
||||
|
||||
|
||||
rec {
|
||||
|
||||
|
||||
systemConfiguration = pkgs.stdenv.mkDerivation {
|
||||
name = "system-configuration";
|
||||
builder = ./system-configuration.sh;
|
||||
inherit (pkgs) grub coreutils gnused gnugrep diffutils;
|
||||
inherit grubDevice;
|
||||
kernel = pkgs.kernel + "/vmlinuz";
|
||||
initrd = initialRamdisk + "/initrd";
|
||||
};
|
||||
|
||||
|
||||
}
|
29
test/system-configuration.sh
Normal file
29
test/system-configuration.sh
Normal file
@ -0,0 +1,29 @@
|
||||
source $stdenv/setup
|
||||
|
||||
ensureDir $out
|
||||
|
||||
ln -s $kernel $out/kernel
|
||||
ln -s $grub $out/grub
|
||||
|
||||
cat > $out/menu.lst << GRUBEND
|
||||
# Automatically generated. DO NOT EDIT THIS FILE!
|
||||
default=0
|
||||
timeout=5
|
||||
title NixOS
|
||||
kernel $kernel selinux=0 apm=on acpi=on
|
||||
initrd $initrd
|
||||
GRUBEND
|
||||
|
||||
ensureDir $out/bin
|
||||
|
||||
cat > $out/bin/switch-to-configuration <<EOF
|
||||
#! $SHELL
|
||||
set -e
|
||||
export PATH=$coreutils/bin:$gnused/bin:$gnugrep/bin:$diffutils/bin
|
||||
if test -n "$grubDevice"; then
|
||||
$grub/sbin/grub-install "$grubDevice" --no-floppy --recheck
|
||||
cp -f $out/menu.lst /boot/grub/menu.lst
|
||||
fi
|
||||
EOF
|
||||
|
||||
chmod +x $out/bin/switch-to-configuration
|
Loading…
x
Reference in New Issue
Block a user