Author: eelco
Date: Mon Apr 23 00:41:37 2012
New Revision: 33887
URL: https://nixos.org/websvn/nix/?rev=33887&sc=1

Log:
* In the installation CD, make the NixOS/Nixpkgs available as if they
  were obtained from the NixOS channel.  "nixos-install" copies this
  to the installed system as well.
* In the installation CD, set GC_INITIAL_HEAP_SIZE to a low value for
  the benefit of memory-constrained environments.

Added:
   nixos/trunk/lib/channel-expr.nix
Modified:
   nixos/trunk/modules/installer/cd-dvd/installation-cd-base.nix
   nixos/trunk/modules/installer/tools/nixos-install.sh
   nixos/trunk/modules/profiles/installation-device.nix
   nixos/trunk/modules/services/misc/nix-daemon.nix
   nixos/trunk/release.nix
   nixos/trunk/tests/installer.nix

Added: nixos/trunk/lib/channel-expr.nix
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ nixos/trunk/lib/channel-expr.nix    Mon Apr 23 00:41:37 2012        (r33887)
@@ -0,0 +1,6 @@
+{ system ? builtins.currentSystem }:
+
+{ pkgs =
+    (import nixpkgs/default.nix { inherit system; })
+    // { recurseForDerivations = true; };
+}

Modified: nixos/trunk/modules/installer/cd-dvd/installation-cd-base.nix
==============================================================================
--- nixos/trunk/modules/installer/cd-dvd/installation-cd-base.nix       Mon Apr 
23 00:30:48 2012        (r33886)
+++ nixos/trunk/modules/installer/cd-dvd/installation-cd-base.nix       Mon Apr 
23 00:41:37 2012        (r33887)
@@ -8,22 +8,20 @@
 let
 
   # We need a copy of the Nix expressions for Nixpkgs and NixOS on the
-  # CD.  We put them in a tarball because accessing that many small
-  # files from a slow device like a CD-ROM takes too long.  !!! Once
-  # we use squashfs, maybe we won't need this anymore.
-  makeTarball = tarName: input: pkgs.runCommand "tarball" {inherit tarName;}
+  # CD.  These are installed into the "nixos" channel of the root
+  # user, as expected by nixos-rebuild/nixos-install.
+  channelSources = pkgs.runCommand "nixos-${config.system.nixosVersion}"
+    { expr = builtins.readFile ../../../lib/channel-expr.nix; }
     ''
-      ensureDir $out
-      (cd ${input} && tar cvfj $out/${tarName} . \
-        --exclude '*~' --exclude 'result')
+      mkdir -p $out/nixos
+      cp -prd ${cleanSource ../../..} $out/nixos/nixos
+      cp -prd ${cleanSource <nixpkgs>} $out/nixos/nixpkgs
+      chmod -R u+w $out/nixos/nixos
+      echo -n ${config.system.nixosVersion} > $out/nixos/nixos/.version
+      echo -n "" > $out/nixos/nixos/.version-suffix
+      echo "$expr" > $out/nixos/default.nix
     '';
 
-  # Put the current directory in a tarball.
-  nixosTarball = makeTarball "nixos.tar.bz2" (cleanSource ../../..);
-
-  # Put Nixpkgs in a tarball.
-  nixpkgsTarball = makeTarball "nixpkgs.tar.bz2" (cleanSource <nixpkgs>);
-
   includeSources = true;
 
 in
@@ -48,19 +46,14 @@
 
   boot.postBootCommands =
     ''
-      export PATH=${pkgs.gnutar}/bin:${pkgs.bzip2}/bin:$PATH
-
       # Provide the NixOS/Nixpkgs sources in /etc/nixos.  This is required
       # for nixos-install.
       ${optionalString includeSources ''
         echo "unpacking the NixOS/Nixpkgs sources..."
-        mkdir -p /etc/nixos/nixos
-        tar xjf ${nixosTarball}/nixos.tar.bz2 -C /etc/nixos/nixos
-        mkdir -p /etc/nixos/nixpkgs
-        tar xjf ${nixpkgsTarball}/nixpkgs.tar.bz2 -C /etc/nixos/nixpkgs
-        chown -R root.root /etc/nixos
-        echo -n ${config.system.nixosVersion} > /etc/nixos/nixos/.version
-        echo -n "" > /etc/nixos/nixos/.version-suffix
+        mkdir -p /nix/var/nix/profiles/per-user/root
+        ${config.environment.nix}/bin/nix-env -p 
/nix/var/nix/profiles/per-user/root/channels -i ${channelSources} --quiet
+        mkdir -m 0700 -p /root/.nix-defexpr
+        ln -s /nix/var/nix/profiles/per-user/root/channels 
/root/.nix-defexpr/channels
      ''}
 
      # Make the installer more likely to succeed in low memory

Modified: nixos/trunk/modules/installer/tools/nixos-install.sh
==============================================================================
--- nixos/trunk/modules/installer/tools/nixos-install.sh        Mon Apr 23 
00:30:48 2012        (r33886)
+++ nixos/trunk/modules/installer/tools/nixos-install.sh        Mon Apr 23 
00:41:37 2012        (r33887)
@@ -103,7 +103,7 @@
 
 # Create a temporary Nix config file that causes the nixbld users to
 # be used.
-echo "build-users-group = nixbld" > /mnt/tmp/nix.conf
+echo "build-users-group = nixbld" > $mountPoint/tmp/nix.conf
 export NIX_CONF_DIR=/tmp
 
 
@@ -141,45 +141,32 @@
 done
 
 
+# Get the absolute path to the NixOS/Nixpkgs sources.
+srcs=$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos 
--no-name --out-path)
+
+
 # Build the specified Nix expression in the target store and install
 # it into the system configuration profile.
 echo "building the system configuration..."
-NIX_PATH=nixpkgs=/mnt/etc/nixos/nixpkgs:nixos=/mnt/etc/nixos/nixos:nixos-config="/mnt$NIXOS_CONFIG"
 NIXOS_CONFIG= \
+NIX_PATH="/mnt$srcs/nixos:nixos-config=/mnt$NIXOS_CONFIG" NIXOS_CONFIG= \
     chroot $mountPoint @nix@/bin/nix-env \
     -p /nix/var/nix/profiles/system -f '<nixos>' --set -A system --show-trace
 
 
-# Get rid of the manifests.
-rm -f $mountPoint/nix/var/nix/manifests/*
-
-
 # We're done building/downloading, so we don't need the /etc bind
 # mount anymore.  In fact, below we want to modify the target's /etc.
 umount $mountPoint/etc/nixos
 umount $mountPoint/etc
 
 
-# Make a backup of the old NixOS/Nixpkgs sources.
-echo "copying NixOS/Nixpkgs sources to /etc/nixos...."
-
-backupTimestamp=$(date "+%Y%m%d%H%M%S")
-
-targetNixos=$mountPoint/etc/nixos/nixos
-if test -e $targetNixos; then
-    mv $targetNixos $targetNixos.backup-$backupTimestamp
-fi
-
-targetNixpkgs=$mountPoint/etc/nixos/nixpkgs
-if test -e $targetNixpkgs; then
-    mv $targetNixpkgs $targetNixpkgs.backup-$backupTimestamp
-fi
-
-
-# Copy the NixOS/Nixpkgs sources to the target.
-cp -prd /etc/nixos/nixos $targetNixos
-if [ -e /etc/nixos/nixpkgs ]; then
-    cp -prd /etc/nixos/nixpkgs $targetNixpkgs
-fi
+# Copy the NixOS/Nixpkgs sources to the target as the initial contents
+# of the NixOS channel.
+echo "copying NixOS/Nixpkgs sources..."
+mkdir -p $mountPoint/nix/var/nix/profiles/per-user/root
+chroot $mountPoint @nix@/bin/nix-env \
+    -p /nix/var/nix/profiles/per-user/root/channels -i "$srcs" --quiet
+mkdir -m 0700 -p $mountPoint/root/.nix-defexpr
+ln -s /nix/var/nix/profiles/per-user/root/channels 
$mountPoint/root/.nix-defexpr/channels
 
 
 # Grub needs an mtab.

Modified: nixos/trunk/modules/profiles/installation-device.nix
==============================================================================
--- nixos/trunk/modules/profiles/installation-device.nix        Mon Apr 23 
00:30:48 2012        (r33886)
+++ nixos/trunk/modules/profiles/installation-device.nix        Mon Apr 23 
00:41:37 2012        (r33887)
@@ -29,7 +29,7 @@
   relocatedModuleFiles =
     let
       relocateNixOS = path:
-        "/etc/nixos/nixos" + removePrefix nixosPath (toString path);
+        "<nixos" + removePrefix nixosPath (toString path) + ">";
       relocateOthers = null;
     in
       { nixos = map relocateNixOS partitionedModuleFiles.nixos;
@@ -44,16 +44,12 @@
   # evaluated.  So we'll just hope for the best.
   configClone = pkgs.writeText "configuration.nix"
     ''
-      {config, pkgs, ...}:
+      { config, pkgs, ... }:
 
       {
         require = [
           ${toString config.installer.cloneConfigIncludes}
         ];
-
-        # Add your own options below and run "nixos-rebuild switch".
-        # E.g.,
-        #   services.openssh.enable = true;
       }
     '';
 in
@@ -84,18 +80,6 @@
       '';
     };
 
-    # Ignored. Kept for Backward compatibiliy.
-    # you can retrieve the profiles which have been used by looking at the
-    # list of modules use to configure the installation device.
-    installer.configModule = mkOption {
-      example = "./nixos/modules/installer/cd-dvd/installation-cd.nix";
-      description = ''
-        Filename of the configuration module that builds the CD
-        configuration.  Must be specified to support reconfiguration
-        in live CDs.
-      '';
-    };
-    
   };
 
   config = {
@@ -148,5 +132,13 @@
     # Enable wpa_supplicant, but don't start it by default.
     networking.wireless.enable = true;
     jobs.wpa_supplicant.startOn = pkgs.lib.mkOverride 50 "";
+
+    # Tell the Nix evaluator to garbage collect more aggressively.
+    # This is desirable in memory-constrained environments that don't
+    # (yet) have swap set up.
+    environment.shellInit =
+      ''
+        export GC_INITIAL_HEAP_SIZE=100000
+      '';
   };
 }

Modified: nixos/trunk/modules/services/misc/nix-daemon.nix
==============================================================================
--- nixos/trunk/modules/services/misc/nix-daemon.nix    Mon Apr 23 00:30:48 
2012        (r33886)
+++ nixos/trunk/modules/services/misc/nix-daemon.nix    Mon Apr 23 00:41:37 
2012        (r33887)
@@ -28,11 +28,10 @@
 
     environment.nix = mkOption {
       default = pkgs.nixUnstable;
-      example = pkgs.nixCustomFun /root/nix.tar.gz;
       merge = mergeOneOption;
-      description = "
+      description = ''
         This option specifies the Nix package instance to use throughout the 
system.
-      ";
+      '';
     };
 
     nix = {

Modified: nixos/trunk/release.nix
==============================================================================
--- nixos/trunk/release.nix     Mon Apr 23 00:30:48 2012        (r33886)
+++ nixos/trunk/release.nix     Mon Apr 23 00:41:37 2012        (r33887)
@@ -114,11 +114,7 @@
 
         buildInputs = [ nixUnstable ];
 
-        expr =
-          ''
-            { system ? builtins.currentSystem }:
-            { pkgs = (import nixpkgs/default.nix { inherit system; }) // { 
recurseForDerivations = true; }; }
-          '';
+        expr = builtins.readFile lib/channel-expr.nix;
 
         distPhase = ''
           echo -n $VERSION_SUFFIX > .version-suffix
@@ -128,7 +124,6 @@
           cp -prd . ../$releaseName/nixos
           cp -prd ${nixpkgs} ../$releaseName/nixpkgs
           echo "$expr" > ../$releaseName/default.nix
-          echo nixos > ../$releaseName/channel-name
           NIX_STATE_DIR=$TMPDIR nix-env -f ../$releaseName/default.nix -qaP 
--meta --xml \* > /dev/null
           cd ..
           chmod -R u+w $releaseName

Modified: nixos/trunk/tests/installer.nix
==============================================================================
--- nixos/trunk/tests/installer.nix     Mon Apr 23 00:30:48 2012        (r33886)
+++ nixos/trunk/tests/installer.nix     Mon Apr 23 00:41:37 2012        (r33887)
@@ -131,7 +131,7 @@
 
         # Test nix-env.
         $machine->mustFail("hello");
-        $machine->mustSucceed("nix-env -f /etc/nixos/nixpkgs -i hello");
+        $machine->mustSucceed("nix-env -i hello");
         $machine->mustSucceed("hello") =~ /Hello, world/
             or die "bad `hello' output";
       ''}
@@ -175,7 +175,7 @@
       # !!! Idem.
       $machine->waitUntilSucceeds("cat /proc/swaps | grep -q /dev");
 
-      $machine->mustSucceed("nix-env -f /etc/nixos/nixpkgs -i coreutils >&2");
+      $machine->mustSucceed("nix-env -i coreutils >&2");
       $machine->mustSucceed("type -tP ls | tee /dev/stderr") =~ /.nix-profile/
           or die "nix-env failed";
 
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to