From 7fa31be4402a9ecd42b79dd860e068d614ca8f5c Mon Sep 17 00:00:00 2001
From: Michael Raskin <7c6f434c@mail.ru>
Date: Tue, 22 Jan 2008 17:55:57 +0000
Subject: [PATCH] Tried to do offline install CD, not DVD. Failure, but some
 parts could be useful.

svn path=/nixos/trunk/; revision=10248
---
 configuration/rescue-cd-configurable.nix |  9 ++++--
 configuration/rescue-cd-offline.nix      | 36 ++++++++++++++++++++++++
 system/options.nix                       | 12 ++++++++
 system/system.nix                        | 18 ++++++++++--
 4 files changed, 69 insertions(+), 6 deletions(-)
 create mode 100644 configuration/rescue-cd-offline.nix

diff --git a/configuration/rescue-cd-configurable.nix b/configuration/rescue-cd-configurable.nix
index 01e7ca86d0d6..e1b0e7088eeb 100644
--- a/configuration/rescue-cd-configurable.nix
+++ b/configuration/rescue-cd-configurable.nix
@@ -26,6 +26,8 @@ let
 	addUsers = arg "addUsers" [];
 	extraInitrdKernelModules = arg "extraInitrdKernelModules" [];
 	bootKernelModules = arg "bootKernelModules" [];
+	arbitraryOverrides = arg "arbitraryOverrides" (config:{});
+	cleanStart = arg "cleanStart" false;
 
 	/* Should return list of {configuration, suffix} attrsets.
 	{configuration=configuration; suffix=""} is always prepended.
@@ -99,7 +101,7 @@ rec {
   nixpkgsRel = "nixpkgs" + (if networkNixpkgs != "" then "-" + networkNixpkgs else "");
 
 
-  configuration = {
+  configuration = let preConfiguration ={
   
     boot = {
       autoDetectRootDevice = true;
@@ -238,19 +240,20 @@ rec {
     };
  
     environment = {
-      extraPackages = pkgs: [
+      extraPackages = if cleanStart then pkgs:[] else pkgs: [
         pkgs.vim
         pkgs.subversion # for nixos-checkout
         pkgs.w3m # needed for the manual anyway
       ] ++ (packages pkgs);
       checkConfigurationOptions = true;
+      cleanStart = cleanStart;
     };
 
     users = {
       extraUsers = map userEntry addUsers;
     };
  
-  };
+  }; in preConfiguration // (arbitraryOverrides preConfiguration);
 
   configurations = [{
     inherit configuration;
diff --git a/configuration/rescue-cd-offline.nix b/configuration/rescue-cd-offline.nix
new file mode 100644
index 000000000000..ab650f65938c
--- /dev/null
+++ b/configuration/rescue-cd-offline.nix
@@ -0,0 +1,36 @@
+{platform ? __currentSystem} : 
+let 
+  isoFun = import ./rescue-cd-configurable.nix;
+in 
+(isoFun {
+	inherit platform;
+	lib = (import ../pkgs/lib);
+
+	networkNixpkgs = "";
+	manualEnabled = false;
+	rogueEnabled = false;
+	sshdEnabled = false;
+	fontConfigEnabled = false;
+	sudoEnable = false;
+	includeMemtest = false;
+	includeStdenv = false;
+	includeBuildDeps = true;
+	cleanStart = true;
+	packages = pkgs: with pkgs; [
+		bashInteractive
+		bzip2
+		coreutils
+		curl
+		e2fsprogs
+		gnutar
+		grub
+		gzip
+		less
+		module_init_tools
+		nano
+		su
+		udev
+		upstart
+		utillinux
+	];
+}).rescueCD
diff --git a/system/options.nix b/system/options.nix
index da741b044b64..fc5c5c116dd4 100644
--- a/system/options.nix
+++ b/system/options.nix
@@ -1849,6 +1849,18 @@ root        ALL=(ALL) SETENV: ALL
       ";
     };
 
+    cleanStart = mkOption {
+      default = false;
+      example = true;
+      description = "
+        There are some times when you want really small system for specific 
+	purpose and do not want default package list. Setting 
+	<varname>cleanStart<varname> to <literal>true</literal> allows you 
+	to create a system with empty path - only extraPackages will be 
+	included..
+      ";
+    };
+
     extraPackages = mkOption {
       default = pkgs: [];
       example = pkgs: [pkgs.firefox pkgs.thunderbird];
diff --git a/system/system.nix b/system/system.nix
index 516e69a6ec71..d4c4cc505c35 100644
--- a/system/system.nix
+++ b/system/system.nix
@@ -204,7 +204,19 @@ rec {
 
 
   # The packages you want in the boot environment.
-  systemPathList = [
+  systemPathList = (if config.environment.cleanStart then 
+  [
+    # Better leave them here - they are small, needed,
+    # and hard to refer from anywhere outside.
+    modprobe 
+    nix
+    nixosInstall
+    nixosRebuild
+    nixosCheckout
+    setuidWrapper
+  ]
+  else
+  [
     modprobe # must take precedence over module_init_tools
     pkgs.bashInteractive # bash with ncurses support
     pkgs.bzip2
@@ -252,9 +264,9 @@ rec {
     nixosRebuild
     nixosCheckout
     setuidWrapper
-  ]
+  ])
   ++ pkgs.lib.optional (config.security.sudo.enable) pkgs.sudo
-  ++ pkgs.lib.optional (config.networking.defaultMailServer.directDelivery) pkgs.ssmtp
+  ++ pkgs.lib.optional (config.networking.defaultMailServer.directDelivery) pkgs.ssmtp 
   ++ pkgs.lib.concatLists (map (job: job.extraPath) upstartJobs.jobs)
   ++ (config.environment.extraPackages) pkgs
   ++ pkgs.lib.optional (config.fonts.enableFontDir) fontDir;