* Compress the Nix store on the CD using squashfs. This reduces the

size of the i686-linux ISO image from 463 MiB to 147 MiB.  Hopefully
  it also speeds up installation due to reduced seek time and larger
  block sizes, but I haven't tested that yet (on real hardware).

svn path=/nixos/branches/modular-nixos/; revision=15930
This commit is contained in:
Eelco Dolstra 2009-06-10 16:29:48 +00:00
parent 31c6852403
commit 1cea6b09ef
4 changed files with 46 additions and 39 deletions

View file

@ -181,9 +181,5 @@ in
# To speed up installation a little bit, include the complete stdenv # To speed up installation a little bit, include the complete stdenv
# in the Nix store on the CD. # in the Nix store on the CD.
isoImage.storeContents = isoImage.storeContents = [pkgs.stdenv];
[ { object = pkgs.stdenv;
symlink = "none";
}
];
} }

View file

@ -45,11 +45,7 @@ let
}; };
isoImage.storeContents = pkgs.lib.mkOption { isoImage.storeContents = pkgs.lib.mkOption {
example = example = [pkgs.stdenv];
[ { object = pkgs.stdenv;
symlink = "/stdenv";
}
];
description = '' description = ''
This option lists additional derivations to be included in the This option lists additional derivations to be included in the
Nix store in the generated ISO image. Nix store in the generated ISO image.
@ -80,17 +76,37 @@ in
[ { mountPoint = "/"; [ { mountPoint = "/";
label = config.isoImage.volumeID; label = config.isoImage.volumeID;
} }
{ mountPoint = "/nix/store";
fsType = "squashfs";
device = "/nix-store.squashfs";
options = "loop";
neededForBoot = true;
}
]; ];
# We need AUFS in the initrd to make the CD appear writable. # We need squashfs in the initrd to mount the compressed Nix store,
# and aufs to make the root filesystem appear writable.
boot.extraModulePackages = [config.boot.kernelPackages.aufs]; boot.extraModulePackages = [config.boot.kernelPackages.aufs];
boot.initrd.extraKernelModules = ["aufs"]; boot.initrd.extraKernelModules = ["aufs" "squashfs"];
# Tell stage 1 of the boot to mount a tmpfs on top of the CD using # Tell stage 1 of the boot to mount a tmpfs on top of the CD using
# AUFS. !!! It would be nicer to make the stage 1 init pluggable # AUFS. !!! It would be nicer to make the stage 1 init pluggable
# and move that bit of code here. # and move that bit of code here.
boot.isLiveCD = true; boot.isLiveCD = true;
# Closures to be copied to the Nix store on the CD, namely the init
# script and the top-level system configuration directory.
isoImage.storeContents =
[ config.system.build.bootStage2
config.system.build.system
];
# Create the squashfs image that contains the Nix store.
system.build.squashfsStore = import ../../../lib/make-squashfs.nix {
inherit (pkgs) stdenv squashfsTools perl pathsFromGraph;
storeContents = config.isoImage.storeContents;
};
# Individual files to be included on the CD, outside of the Nix # Individual files to be included on the CD, outside of the Nix
# store on the CD. # store on the CD.
isoImage.contents = isoImage.contents =
@ -109,16 +125,12 @@ in
{ source = config.boot.grubSplashImage; { source = config.boot.grubSplashImage;
target = "/boot/background.xpm.gz"; target = "/boot/background.xpm.gz";
} }
]; { source = config.system.build.squashfsStore;
target = "/nix-store.squashfs";
# Closures to be copied to the Nix store on the CD, namely the init
# script and the top-level system configuration directory.
isoImage.storeContents =
[ { object = config.system.build.bootStage2;
symlink = "/init";
} }
{ object = config.system.build.system; { # Quick hack: need a mount point for the store.
symlink = "/system"; source = pkgs.runCommand "empty" {} "ensureDir $out";
target = "/nix/store";
} }
]; ];
@ -130,7 +142,7 @@ in
chainloader +1 chainloader +1
title NixOS Installer / Rescue title NixOS Installer / Rescue
kernel /boot/vmlinuz init=/init ${toString config.boot.kernelParams} kernel /boot/vmlinuz init=${config.system.build.bootStage2} systemConfig=${config.system.build.system} ${toString config.boot.kernelParams}
initrd /boot/initrd initrd /boot/initrd
''; '';
@ -138,18 +150,17 @@ in
system.build.isoImage = import ../../../lib/make-iso9660-image.nix { system.build.isoImage = import ../../../lib/make-iso9660-image.nix {
inherit (pkgs) stdenv perl cdrkit pathsFromGraph; inherit (pkgs) stdenv perl cdrkit pathsFromGraph;
inherit (config.isoImage) isoName compressImage volumeID contents storeContents; inherit (config.isoImage) isoName compressImage volumeID contents;
bootable = true; bootable = true;
bootImage = "/boot/grub/stage2_eltorito"; bootImage = "/boot/grub/stage2_eltorito";
}; };
# After booting, register the contents of the Nix store on the CD in
# the Nix database in the tmpfs.
boot.postBootCommands = boot.postBootCommands =
'' ''
${config.environment.nix}/bin/nix-store --load-db < /nix-path-registration # After booting, register the contents of the Nix store on the
rm /nix-path-registration # CD in the Nix database in the tmpfs.
${config.environment.nix}/bin/nix-store --load-db < /nix/store/nix-path-registration
# nixos-rebuild also requires a "system" profile and an # nixos-rebuild also requires a "system" profile and an
# /etc/NIXOS tag. # /etc/NIXOS tag.

View file

@ -5,11 +5,7 @@
# Build the build-time dependencies of this configuration on the DVD # Build the build-time dependencies of this configuration on the DVD
# to speed up installation. # to speed up installation.
isoImage.storeContents = isoImage.storeContents = [config.system.build.system.drvPath];
[ { object = config.system.build.system.drvPath;
symlink = "none";
}
];
# Include lots of packages. # Include lots of packages.
environment.systemPackages = environment.systemPackages =

View file

@ -1,6 +1,6 @@
#! @shell@ #! @shell@
targetRoot=/mnt/root targetRoot=/mnt-root
export LD_LIBRARY_PATH=@extraUtils@/lib export LD_LIBRARY_PATH=@extraUtils@/lib
@ -236,13 +236,17 @@ done
# If this is a live-CD/DVD, then union-mount a tmpfs on top of the # If this is a live-CD/DVD, then union-mount a tmpfs on top of the
# original root. # original root.
targetRoot=/mnt-root
if test -n "@isLiveCD@"; then if test -n "@isLiveCD@"; then
mkdir /mnt-tmpfs mkdir /mnt-root-tmpfs
mount -t tmpfs -o "mode=755" none /mnt-tmpfs mount -t tmpfs -o "mode=755" none /mnt-root-tmpfs
mkdir /mnt-union mkdir /mnt-root-union
mount -t aufs -o dirs=/mnt-tmpfs=rw:$targetRoot=ro none /mnt-union mount -t aufs -o dirs=/mnt-root-tmpfs=rw:$targetRoot=ro none /mnt-root-union
targetRoot=/mnt-union targetRoot=/mnt-root-union
mkdir /mnt-store-tmpfs
mount -t tmpfs -o "mode=755" none /mnt-store-tmpfs
mkdir -p $targetRoot/nix/store
mount -t aufs -o dirs=/mnt-store-tmpfs=rw:/mnt-root/nix/store=ro none /mnt-root-union/nix/store
fi fi