From 0b26af2188736e73ec6e5f7d0eeacf34370812ba Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 12 Nov 2006 23:30:03 +0000 Subject: [PATCH] * 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 --- test/installer.sh | 17 ++++++++++++++--- test/make-initrd.nix | 4 ++-- test/make-initrd.sh | 2 +- test/rescue-cd.nix | 2 ++ test/rescue-system.nix | 2 +- test/system-configuration.nix | 32 ++++++++++++++++++++++++++++++++ test/system-configuration.sh | 29 +++++++++++++++++++++++++++++ 7 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 test/system-configuration.nix create mode 100644 test/system-configuration.sh diff --git a/test/installer.sh b/test/installer.sh index 359086a5238..14b6e2a4aac 100644 --- a/test/installer.sh +++ b/test/installer.sh @@ -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 diff --git a/test/make-initrd.nix b/test/make-initrd.nix index f850e1cf657..91722b96602 100644 --- a/test/make-initrd.nix +++ b/test/make-initrd.nix @@ -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; } diff --git a/test/make-initrd.sh b/test/make-initrd.sh index 2620b90eec7..5da23533feb 100644 --- a/test/make-initrd.sh +++ b/test/make-initrd.sh @@ -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. diff --git a/test/rescue-cd.nix b/test/rescue-cd.nix index defeeb48ece..002288bea87 100644 --- a/test/rescue-cd.nix +++ b/test/rescue-cd.nix @@ -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 { diff --git a/test/rescue-system.nix b/test/rescue-system.nix index 890e3cfdf82..40ec535c6b1 100644 --- a/test/rescue-system.nix +++ b/test/rescue-system.nix @@ -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; }; diff --git a/test/system-configuration.nix b/test/system-configuration.nix new file mode 100644 index 00000000000..ef04dc1badc --- /dev/null +++ b/test/system-configuration.nix @@ -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"; + }; + + +} diff --git a/test/system-configuration.sh b/test/system-configuration.sh new file mode 100644 index 00000000000..17d58f4d0cb --- /dev/null +++ b/test/system-configuration.sh @@ -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 <