From 9fd5d70968ef031f9c95b80ef56a19cd8fe391cf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 30 Jan 2008 01:28:56 +0000 Subject: [PATCH] * The CD is now a true live CD: you can run Nix operations in it thanks to unionfs. For instance, nix-env and nixos-rebuild work. The tricky part was to build a Nix database (in the tmpfs/unionfs) which is now necessary to prevent store paths on the CD from being deleted right away because they otherwise wouldn't be valid. * nixos-install: use the /etc/nixos/configuration.nix from the target file system (don't copy it anymore). Since the user is supposed to mount the target file system on /mnt anyway, we may as well require that configuration.nix is placed in /mnt/etc/nixos. This also makes upgrading / reinstalling much easier, since it will automatically use the right configuration.nix. svn path=/nixos/trunk/; revision=10399 --- configuration/rescue-cd.nix | 13 +++++++++---- etc/profile.sh | 2 +- helpers/make-iso9660-image.sh | 4 ++-- helpers/paths-from-graph.pl | 14 ++++++++++++++ installer/nixos-checkout.sh | 5 ++--- installer/nixos-install.sh | 21 ++++----------------- system/activate-configuration.sh | 5 ++++- 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/configuration/rescue-cd.nix b/configuration/rescue-cd.nix index 2edfe78d9e9..2d9fa54b318 100644 --- a/configuration/rescue-cd.nix +++ b/configuration/rescue-cd.nix @@ -36,14 +36,18 @@ rec { extraJobs = [ # Unpack the NixOS/Nixpkgs sources to /etc/nixos. + # !!! run this synchronously { name = "unpack-sources"; job = " start on startup script export PATH=${pkgs.gnutar}/bin:${pkgs.bzip2}/bin:$PATH + + ${system.nix}/bin/nix-store --load-db < /nix-path-registration + mkdir -p /etc/nixos/nixos - tar xjf /nixos.tar.bz2 -C /etc/nixos/nixos - tar xjf /nixpkgs.tar.bz2 -C /etc/nixos + tar xjf /install/nixos.tar.bz2 -C /etc/nixos/nixos + tar xjf /install/nixpkgs.tar.bz2 -C /etc/nixos mv /etc/nixos/nixpkgs-* /etc/nixos/nixpkgs ln -sfn ../nixpkgs/pkgs /etc/nixos/nixos/pkgs chown -R root.root /etc/nixos @@ -66,6 +70,7 @@ rec { { name = "rogue"; job = " env HOME=/root + chdir /root start on udev stop on shutdown respawn ${pkgs.rogue}/bin/rogue < /dev/tty8 > /dev/tty8 2>&1 @@ -214,10 +219,10 @@ rec { target = "boot/background.xpm.gz"; } { source = nixosTarball + "/" + nixosTarball.tarName; - target = "/" + nixosTarball.tarName; + target = "/install/" + nixosTarball.tarName; } { source = nixpkgsTarball; - target = "/nixpkgs.tar.bz2"; + target = "/install/nixpkgs.tar.bz2"; } { source = pkgs.writeText "label" ""; target = "/${configuration.boot.rootLabel}"; diff --git a/etc/profile.sh b/etc/profile.sh index 27d265f74ac..99f7d7c1e8b 100644 --- a/etc/profile.sh +++ b/etc/profile.sh @@ -73,7 +73,7 @@ if test ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr; then echo "creating $HOME/.nix-defexpr" >&2 rm -f $HOME/.nix-defexpr mkdir $HOME/.nix-defexpr - ln -s /etc/nixos/install-source.nix $HOME/.nix-defexpr/nixpkgs_sys + ln -s /etc/nixos/nixpkgs $HOME/.nix-defexpr/nixpkgs_sys ln -s /etc/nixos/nixos $HOME/.nix-defexpr/nixos if test "$USER" != root; then ln -s /nix/var/nix/gcroots/per-user/root/channels $HOME/.nix-defexpr/channels_root diff --git a/helpers/make-iso9660-image.sh b/helpers/make-iso9660-image.sh index 6f18f0e3e5b..586cfb8deb4 100644 --- a/helpers/make-iso9660-image.sh +++ b/helpers/make-iso9660-image.sh @@ -39,8 +39,8 @@ done # Also put a nix-pull manifest of the closures on the CD. -printManifest=1 perl $pathsFromGraph closure-* > MANIFEST -echo "MANIFEST=MANIFEST" >> pathlist +printRegistration=1 perl $pathsFromGraph closure-* > nix-path-registration +echo "nix-path-registration=nix-path-registration" >> pathlist # Add symlinks to the top-level store objects. diff --git a/helpers/paths-from-graph.pl b/helpers/paths-from-graph.pl index bede974cb76..43ce4e68db4 100644 --- a/helpers/paths-from-graph.pl +++ b/helpers/paths-from-graph.pl @@ -47,6 +47,20 @@ if ($ENV{"printManifest"} eq "1") { } } +elsif ($ENV{"printRegistration"} eq "1") { + # This is the format used by `nix-store --register-validity + # --hash-given' / `nix-store --load-db'. + foreach my $storePath (sort (keys %storePaths)) { + print "$storePath\n"; + print "0000000000000000000000000000000000000000000000000000000000000000\n"; # !!! fix + print "\n"; # don't care about preserving the deriver + print scalar(@{$refs{$storePath}}), "\n"; + foreach my $ref (@{$refs{$storePath}}) { + print "$ref\n"; + } + } +} + else { foreach my $storePath (sort (keys %storePaths)) { print "$storePath\n"; diff --git a/installer/nixos-checkout.sh b/installer/nixos-checkout.sh index d6c3d535d83..339beeecacd 100644 --- a/installer/nixos-checkout.sh +++ b/installer/nixos-checkout.sh @@ -29,8 +29,7 @@ fi svn co https://svn.cs.uu.nl:12443/repos/trace/nixos/trunk nixos svn co https://svn.cs.uu.nl:12443/repos/trace/nixpkgs/trunk nixpkgs svn co https://svn.cs.uu.nl:12443/repos/trace/services/trunk services -ln -sfn ../services nixos/services -# A few symlink. +# Add a few required symlink. +ln -sfn ../services nixos/services ln -sfn ../nixpkgs/pkgs nixos/pkgs -ln -sfn nixpkgs/pkgs/top-level/all-packages.nix install-source.nix diff --git a/installer/nixos-install.sh b/installer/nixos-install.sh index 07e7360ce92..e7794f720a3 100644 --- a/installer/nixos-install.sh +++ b/installer/nixos-install.sh @@ -19,6 +19,7 @@ if test -z "$NIXOS"; then NIXOS=/etc/nixos/nixos fi +# NIXOS_CONFIG is interpreted relative to $mountPoint. if test -z "$NIXOS_CONFIG"; then NIXOS_CONFIG=/etc/nixos/configuration.nix fi @@ -38,14 +39,13 @@ if ! test -e "$NIXOS"; then exit 1 fi -if ! test -e "$NIXOS_CONFIG"; then - echo "configuration file $NIXOS_CONFIG doesn't exist" +if ! test -e "$mountPoint/$NIXOS_CONFIG"; then + echo "configuration file $mountPoint/$NIXOS_CONFIG doesn't exist" exit 1 fi NIXOS=$(readlink -f "$NIXOS") -NIXOS_CONFIG=$(readlink -f "$NIXOS_CONFIG") # Mount some stuff in the target root directory. @@ -142,22 +142,10 @@ echo "building the system configuration..." chroot $mountPoint @nix@/bin/nix-env \ -p /nix/var/nix/profiles/system \ -f "/mnt$NIXOS/system/system.nix" \ - --arg configuration "import /mnt$NIXOS_CONFIG" \ + --arg configuration "import $NIXOS_CONFIG" \ --set -A system -# Copy the configuration to /etc/nixos. -backupTimestamp=$(date "+%Y%m%d%H%M%S") -targetConfig=$mountPoint/etc/nixos/configuration.nix -mkdir -p $(dirname $targetConfig) -if test -e $targetConfig -o -L $targetConfig; then - cp -f $targetConfig $targetConfig.backup-$backupTimestamp -fi -if test "$NIXOS_CONFIG" != "$targetConfig"; then - cp -f $NIXOS_CONFIG $targetConfig -fi - - # Make a backup of the old NixOS/Nixpkgs sources. echo "copying NixOS/Nixpkgs sources to /etc/nixos...." @@ -177,7 +165,6 @@ cp -prd $NIXOS $targetNixos if test -e /etc/nixos/nixpkgs; then cp -prd /etc/nixos/nixpkgs $targetNixpkgs fi -ln -sfn nixpkgs/pkgs/top-level/all-packages.nix $mountPoint/etc/nixos/install-source.nix # Grub needs a mtab. diff --git a/system/activate-configuration.sh b/system/activate-configuration.sh index 4e35785f981..e07e8d295af 100644 --- a/system/activate-configuration.sh +++ b/system/activate-configuration.sh @@ -155,7 +155,10 @@ fi # Make this configuration the current configuration. -ln -sfn "$systemConfig" /var/run/current-system +# The readlink is there to ensure that when $systemConfig = /system +# (which is a symlink to the store), /var/run/current-system is still +# used as a garbage collection root. +ln -sfn "$(readlink -f "$systemConfig")" /var/run/current-system # Prevent the current configuration from being garbage-collected.