1{ stdenv, fetchurl, dpkg, gettext, gawk, perl, wget, coreutils, fakeroot }:
2
3let
4
5# USAGE like this: debootstrap sid /tmp/target-chroot-directory
6
7# There is also cdebootstrap now. Is that easier to maintain?
8
9 makedev = stdenv.mkDerivation {
10 name = "makedev-for-debootstrap";
11 src = fetchurl {
12 url = mirror://debian/pool/main/m/makedev/makedev_2.3.1.orig.tar.gz;
13 sha256 = "1yhxlj2mhn1nqkx1f0sn0bl898nf28arxxa4lgp7hdrb5cpp36c5";
14 };
15 patches = [
16 (fetchurl {
17 url = "mirror://debian/pool/main/m/makedev/makedev_2.3.1-93.diff.gz";
18 sha256 = "08328779mc0b20xkj76ilpf9c8bw6zkz5xiw5l2kwm690dxp9nvw";
19 })
20 ];
21 # TODO install man
22 installPhase = ''
23 mkdir -p $out/sbin
24 ls -l
25 t=$out/sbin/MAKEDEV
26 cp MAKEDEV $t
27 chmod +x $t
28 '';
29 };
30
31in
32
33stdenv.mkDerivation {
34
35 name = "debootstrap-1.0.67";
36
37 src = fetchurl {
38 # git clone git://git.debian.org/d-i/debootstrap.git
39 # I'd like to use the source. However it's lacking the lanny script ? (still true?)
40 url = mirror://debian/pool/main/d/debootstrap/debootstrap_1.0.67.tar.gz;
41 sha256 = "06x5zw6fskw37qh62hvqx006319l4wgnnw8sf53ms67zpfif04ha";
42 };
43
44 buildInputs = [ dpkg gettext gawk perl ];
45
46 buildPhase = ":";
47
48 # If you have to update the patch for functions a vim regex like this
49 # can help you identify which lines are used to write scripts on TARGET and
50 # which should /bin/ paths should be replaced:
51 # \<echo\>\|\/bin\/\|^\s*\<cat\>\|EOF\|END
52 installPhase = ''
53
54 sed -i \
55 -e 's@/usr/bin/id@id@' \
56 -e 's@/usr/bin/dpkg@${dpkg}/bin/dpkg@' \
57 -e 's@/usr/bin/sha@${coreutils}/bin/sha@' \
58 -e 's@/bin/sha@${coreutils}/bin/sha@' \
59 debootstrap
60
61
62 for file in functions debootstrap; do
63 substituteInPlace "$file" \
64 --subst-var-by gunzip "$(type -p gunzip)" \
65 --subst-var-by bunzip "$(type -p bunzip)" \
66 --subst-var-by gettext "$(type -p gettext)" \
67 --subst-var-by dpkg "$(type -p dpkg)" \
68 --subst-var-by udpkg "$(type -p udpkg)" \
69 --subst-var-by id "$(type -p id)" \
70 --subst-var-by perl "$(type -p perl)" \
71 --subst-var-by uname "$(type -p uname)" \
72 --subst-var-by wget "${wget}/bin/wget"
73 done
74
75
76 sed -i \
77 -e 's@\<wget\>@${wget}/bin/wget@' \
78 functions
79
80 d=$out/share/debootstrap
81 mkdir -p $out/{share/debootstrap,bin}
82
83 ${fakeroot}/bin/fakeroot -- make devices.tar.gz MAKEDEV=${makedev}/sbin/MAKEDEV
84
85 cp -r . $d
86
87 cat >> $out/bin/debootstrap << EOF
88 #!/bin/sh
89 export DEBOOTSTRAP_DIR="''${DEBOOTSTRAP_DIR:-$d}"
90 # mount and other tools must be found in chroot. So add default debain paths!
91 # TODO only add paths which are required by the scripts!
92 export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
93 exec $d/debootstrap "\$@"
94 EOF
95 chmod +x $out/bin/debootstrap
96
97 mkdir -p $out/man/man8
98 mv debootstrap.8 $out/man/man8
99 '';
100
101 passthru = {
102 inherit makedev;
103 };
104
105 meta = {
106 description = "Tool to create a Debian system in a chroot";
107 homepage = http://packages.debian.org/de/lenny/debootstrap; # http://code.erisian.com.au/Wiki/debootstrap
108 license = stdenv.lib.licenses.gpl2; # gentoo says so.. ?
109 maintainers = [ stdenv.lib.maintainers.marcweber ];
110 platforms = stdenv.lib.platforms.linux;
111 };
112}