From 29b05fb62a7594266a3bf20a46b22f46d3044c7c Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Mon, 14 May 2012 04:12:43 +0000
Subject: [PATCH] * nixos-checkout: add an argument to specify the directory
 where the   sources should be stored.  E.g. "nixos-checkout /home/eelco/srcs"
   will check out to /home/eelco/srcs/{nixos,nixpkgs}.  Probably the  
 /etc/nixos default should be removed eventually because /etc is a   pretty
 weird place to keep large source trees.

svn path=/nixos/trunk/; revision=34086
---
 doc/manual/development.xml                 | 13 +++++++------
 modules/installer/tools/nixos-checkout.nix |  7 ++++++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/doc/manual/development.xml b/doc/manual/development.xml
index 918bbe08a1a..017a0f007fa 100644
--- a/doc/manual/development.xml
+++ b/doc/manual/development.xml
@@ -21,18 +21,19 @@ To modify NixOS, however, you should check out the latest sources from
 Subversion.  This is done using the following command:
 
 <screen>
-$ nixos-checkout
+$ nixos-checkout <replaceable>/my/sources</replaceable>
 </screen>
 
 This will check out the latest NixOS sources to
-<filename>/etc/nixos/nixos</filename> and the Nixpkgs sources to
-<filename>/etc/nixos/nixpkgs</filename>.  If you want to rebuild your
-system using your (modified) sources, you need to tell
-<command>nixos-rebuild</command> about them using the
+<filename><replaceable>/my/sources</replaceable>/nixos</filename> and
+the Nixpkgs sources to
+<filename><replaceable>/my/sources</replaceable>/nixpkgs</filename>.
+If you want to rebuild your system using your (modified) sources, you
+need to tell <command>nixos-rebuild</command> about them using the
 <option>-I</option> flag:
 
 <screen>
-$ nixos-rebuild -I /etc/nixos
+$ nixos-rebuild switch -I <replaceable>/my/sources</replaceable>
 </screen>
 
 </para>
diff --git a/modules/installer/tools/nixos-checkout.nix b/modules/installer/tools/nixos-checkout.nix
index f90d24b0864..d591c01df19 100644
--- a/modules/installer/tools/nixos-checkout.nix
+++ b/modules/installer/tools/nixos-checkout.nix
@@ -14,7 +14,12 @@ let
     isExecutable = true;
     src = pkgs.writeScript "nixos-checkout"
       ''
-        cd /etc/nixos
+        #! ${pkgs.stdenv.shell} -e
+        
+        prefix="$1"
+        if [ -z "$prefix" ]; then prefix=/etc/nixos; fi
+        mkdir -p "$prefix"
+        cd "$prefix"
 
         # Move any old nixos or nixpkgs directories out of the way.
         backupTimestamp=$(date "+%Y%m%d%H%M%S")