@@ -1,188 +1,219 @@
1−{ stdenv, fetchurl, which, zlib, pkgconfig, SDL, openssl
2−, libuuid, gettext, ncurses, dev86, iasl, pciutils, bzip2
3−, lvm2, utillinux, procps, texinfo, perl, python2Packages
4−, glib, bridge-utils, xorg, pixman, iproute, udev, bison
5−, flex, cmake, ocamlPackages, figlet, libaio, yajl
6−, checkpolicy, transfig, glusterfs, acl, fetchgit, xz, spice
7−, spice_protocol, usbredir, alsaLib, quilt
1+config:
2+{ stdenv, cmake, pkgconfig, which
3+
4+# Xen
5+, bison, bzip2, checkpolicy, dev86, figlet, flex, gettext, glib
6+, iasl, libaio, libiconv, libuuid, ncurses, openssl, perl
7+, python2Packages
8+# python2Packages.python
9+, xz, yajl, zlib
10+
11+# Xen Optional
12+, ocamlPackages
13+
14+# Scripts
815, coreutils, gawk, gnused, gnugrep, diffutils, multipath-tools
9−, inetutils, iptables, openvswitch, nbd, drbd, xenConfig
10−, xenserverPatched ? false, ... }:
16+, iproute, inetutils, iptables, bridge-utils, openvswitch, nbd, drbd
17+, lvm2, utillinux, procps
18+
19+# Documentation
20+# python2Packages.markdown
21+, transfig, ghostscript, texinfo, pandoc
22+
23+, ...} @ args:
1124
1225with stdenv.lib;
1326
1427let
28+ #TODO: fix paths instead
29+ scriptEnvPath = concatMapStringsSep ":" (x: "${x}/bin") [
30+ which perl
31+ coreutils gawk gnused gnugrep diffutils utillinux multipath-tools
32+ iproute inetutils iptables bridge-utils openvswitch nbd drbd
33+ ];
34+
35+ withXenfiles = f: concatStringsSep "\n" (mapAttrsToList f config.xenfiles);
36+
37+ withTools = a: f: withXenfiles (name: x: optionalString (hasAttr a x) ''
38+ echo "processing ${name}"
39+ __do() {
40+ cd "tools/${name}"
41+ ${f name x}
42+ }
43+ ( __do )
44+ '');
45+in
1546
16− libDir = if stdenv.is64bit then "lib64" else "lib";
47+stdenv.mkDerivation (rec {
48+ inherit (config) version;
1749
18− # Sources needed to build the tools
19− # These sources are already rather old and probably do not change frequently
20− xenExtfiles = [
21− { url = http://xenbits.xensource.com/xen-extfiles/ipxe-git-9a93db3f0947484e30e753bbd61a10b17336e20e.tar.gz;
22− sha256 = "0p206zaxlhda60ci33h9gipi5gm46fvvsm6k5c0w7b6cjg0yhb33";
23− }
24− ];
50+ name = "xen-${version}";
2551
26− scriptEnvPath = stdenv.lib.concatStrings (stdenv.lib.intersperse ":" (map (x: "${x}/bin")
27− [ coreutils gawk gnused gnugrep which perl diffutils utillinux multipath-tools
28− iproute inetutils iptables bridge-utils openvswitch nbd drbd ]));
29−in
52+ dontUseCmakeConfigure = true;
3053
54+ hardeningDisable = [ "stackprotector" "fortify" "pic" ];
3155
56+ buildInputs = [
57+ cmake pkgconfig which
3258
33−stdenv.mkDerivation {
34− inherit (xenConfig) name version src;
59+ # Xen
60+ bison bzip2 checkpolicy dev86 figlet flex gettext glib iasl libaio
61+ libiconv libuuid ncurses openssl perl python2Packages.python xz yajl zlib
3562
36− dontUseCmakeConfigure = true;
63+ # oxenstored
64+ ocamlPackages.findlib ocamlPackages.ocaml
3765
38− buildInputs =
39− [ which zlib pkgconfig SDL openssl libuuid gettext ncurses
40− dev86 iasl pciutils bzip2 xz texinfo perl yajl
41− python2Packages.python python2Packages.wrapPython
42− glib bridge-utils pixman iproute udev bison xorg.libX11
43− flex ocamlPackages.ocaml ocamlPackages.findlib figlet libaio
44− checkpolicy python2Packages.markdown transfig
45− glusterfs acl cmake spice spice_protocol usbredir
46− alsaLib quilt
47− ];
66+ # Python fixes
67+ python2Packages.wrapPython
4868
49− hardeningDisable = [ "stackprotector" "fortify" "pic" ];
69+ # Documentation
70+ python2Packages.markdown transfig ghostscript texinfo pandoc
5071
51− patches = stdenv.lib.optionals ((xenserverPatched == false) && (builtins.hasAttr "xenPatches" xenConfig)) xenConfig.xenPatches;
72+ # Others
73+ ] ++ (concatMap (x: x.buildInputs or []) (attrValues config.xenfiles))
74+ ++ (config.buildInputs or []);
5275
53− postPatch = ''
54− ${stdenv.lib.optionalString ((xenserverPatched == true) && (builtins.hasAttr "xenserverPatches" xenConfig)) xenConfig.xenserverPatches}
55−
56− # Xen's tools and firmares need various git repositories that it
57− # usually checks out at time using git. We can't have that.
58− ${flip concatMapStrings xenConfig.toolsGits (x: let src = fetchgit x.git; in ''
59− cp -r ${src} tools/${src.name}-dir-remote
60− chmod -R +w tools/${src.name}-dir-remote
61− '' + stdenv.lib.optionalString (builtins.hasAttr "patches" x) ''
62− ( cd tools/${src.name}-dir-remote; ${concatStringsSep "; " (map (p: "patch -p1 < ${p}") x.patches)} )
63− '')}
64− ${flip concatMapStrings xenConfig.firmwareGits (x: let src = fetchgit x.git; in ''
65− cp -r ${src} tools/firmware/${src.name}-dir-remote
66− chmod -R +w tools/firmware/${src.name}-dir-remote
67− '' + stdenv.lib.optionalString (builtins.hasAttr "patches" x) ''
68− ( cd tools/firmware/${src.name}-dir-remote; ${concatStringsSep "; " (map (p: "patch -p1 < ${p}") x.patches)} )
69− '')}
70−
71− # Xen's stubdoms and firmwares need various sources that are usually fetched
72− # at build time using wget. We can't have that, so we prefetch Xen's ext_files.
73− mkdir xen_ext_files
74− ${flip concatMapStrings xenExtfiles (x: let src = fetchurl x; in ''
75− cp ${src} xen_ext_files/${src.name}
76− '')}
77−
78− # Avoid a glibc >= 2.25 deprecation warnings that get fatal via -Werror.
79− sed 1i'#include <sys/sysmacros.h>' \
80− -i tools/blktap2/control/tap-ctl-allocate.c \
81− -i tools/libxl/libxl_device.c
82− '';
76+ prePatch = ''
77+ ### Generic fixes
78+
79+ # Xen's stubdoms, tools and firmwares need various sources that
80+ # are usually fetched at build time using wget and git. We can't
81+ # have that, so we prefetch them in nix-expression and setup
82+ # fake wget and git for debugging purposes.
83+
84+ mkdir fake-bin
85+
86+ # Fake git: just print what it wants and die
87+ cat > fake-bin/wget << EOF
88+ #!/bin/sh -e
89+ echo ===== FAKE WGET: Not fetching \$*
90+ [ -e \$3 ]
91+ EOF
8392
84− preConfigure = ''
85− # Fake wget: copy prefetched downloads instead
86− mkdir wget
87− echo "#!/bin/sh" > wget/wget
88− echo "echo ===== Not fetching \$*, copy pre-fetched file instead" >> wget/wget
89− echo "cp \$4 \$3" >> wget/wget
90− chmod +x wget/wget
91− export PATH=$PATH:$PWD/wget
92− export EXTRA_QEMUU_CONFIGURE_ARGS="--enable-spice --enable-usb-redir --enable-linux-aio"
93+ # Fake git: just print what it wants and die
94+ cat > fake-bin/git << EOF
95+ #!/bin/sh
96+ echo ===== FAKE GIT: Not cloning \$*
97+ [ -e \$3 ]
98+ EOF
99+
100+ chmod +x fake-bin/*
101+ export PATH=$PATH:$PWD/fake-bin
102+
103+ # Remove in-tree qemu stuff in case we build from a tar-ball
104+ rm -rf tools/qemu-xen tools/qemu-xen-traditional
105+
106+ # Fix shebangs, mainly for build-scipts
107+ # We want to do this before getting prefetched stuff to speed things up
108+ # (prefetched stuff has lots of files)
109+ find . -type f | xargs sed -i 's@/usr/bin/\(python\|perl\)@/usr/bin/env \1@g'
110+ find . -type f | xargs sed -i 's@/bin/bash@/bin/sh@g'
111+
112+ # Get prefetched stuff
113+ ${withXenfiles (name: x: ''
114+ echo "${x.src} -> tools/${name}"
115+ cp -r ${x.src} tools/${name}
116+ chmod -R +w tools/${name}
117+ '')}
93118 '';
94119
95− # https://github.com/NixOS/nixpkgs/issues/13590
96− configureFlags = ["--disable-stubdom"];
120+ patches = [ ./0000-fix-ipxe-src.patch
121+ ./0000-fix-install-python.patch ]
122+ ++ (config.patches or []);
97123
98− postConfigure =
99− ''
100− substituteInPlace tools/libfsimage/common/fsimage_plugin.c \
101− --replace /usr $out
124+ postPatch = ''
125+ ### Hacks
126+
127+ # Work around a bug in our GCC wrapper: `gcc -MF foo -v' doesn't
128+ # print the GCC version number properly.
129+ substituteInPlace xen/Makefile \
130+ --replace '$(CC) $(CFLAGS) -v' '$(CC) -v'
102131
103− substituteInPlace tools/blktap2/lvm/lvm-util.c \
104− --replace /usr/sbin/vgs ${lvm2}/sbin/vgs \
105− --replace /usr/sbin/lvs ${lvm2}/sbin/lvs
132+ # Hack to get `gcc -m32' to work without having 32-bit Glibc headers.
133+ mkdir -p tools/include/gnu
134+ touch tools/include/gnu/stubs-32.h
106135
107− substituteInPlace tools/xenmon/xenmon.py \
108− --replace /usr/bin/pkill ${procps}/bin/pkill
136+ ### Fixing everything else
109137
110− substituteInPlace tools/xenstat/Makefile \
111− --replace /usr/include/curses.h ${ncurses.dev}/include/curses.h
138+ substituteInPlace tools/libfsimage/common/fsimage_plugin.c \
139+ --replace /usr $out
112140
113− substituteInPlace tools/qemu-xen-traditional/xen-hooks.mak \
114− --replace /usr/include/pci ${pciutils}/include/pci
141+ substituteInPlace tools/blktap2/lvm/lvm-util.c \
142+ --replace /usr/sbin/vgs ${lvm2}/bin/vgs \
143+ --replace /usr/sbin/lvs ${lvm2}/bin/lvs
115144
116− substituteInPlace tools/qemu-xen-traditional-dir-remote/xen-hooks.mak \
117− --replace /usr/include/pci ${pciutils}/include/pci
145+ substituteInPlace tools/misc/xenpvnetboot \
146+ --replace /usr/sbin/mount ${utillinux}/bin/mount \
147+ --replace /usr/sbin/umount ${utillinux}/bin/umount
118148
119− substituteInPlace tools/hotplug/Linux/xen-backend.rules \
120− --replace /etc/xen/scripts $out/etc/xen/scripts
149+ substituteInPlace tools/xenmon/xenmon.py \
150+ --replace /usr/bin/pkill ${procps}/bin/pkill
121151
122− # blktap is not provided by xen, but by xapi
123− sed -i '/blktap/d' tools/hotplug/Linux/xen-backend.rules
152+ substituteInPlace tools/xenstat/Makefile \
153+ --replace /usr/include/curses.h ${ncurses.dev}/include/curses.h
124154
125− # Work around a bug in our GCC wrapper: `gcc -MF foo -v' doesn't
126− # print the GCC version number properly.
127− substituteInPlace xen/Makefile \
128− --replace '$(CC) $(CFLAGS) -v' '$(CC) -v'
155+ # TODO: use this as a template and support our own if-up scripts instead?
156+ substituteInPlace tools/hotplug/Linux/xen-backend.rules.in \
157+ --replace "@XEN_SCRIPT_DIR@" $out/etc/xen/scripts
129158
130− # Allow the location of the xendomains config file to be
131− # overriden at runtime.
132− substituteInPlace tools/hotplug/Linux/init.d/xendomains \
133− --replace 'XENDOM_CONFIG=/etc/sysconfig/xendomains' "" \
134− --replace 'XENDOM_CONFIG=/etc/default/xendomains' "" \
135− --replace /etc/xen/scripts/hotplugpath.sh $out/etc/xen/scripts/hotplugpath.sh \
136− --replace /bin/ls ls
159+ # blktap is not provided by xen, but by xapi
160+ sed -i '/blktap/d' tools/hotplug/Linux/xen-backend.rules.in
137161
138− substituteInPlace tools/hotplug/Linux/xendomains \
139− --replace /bin/ls ls
162+ ${withTools "patches" (name: x: ''
163+ ${concatMapStringsSep "\n" (p: ''
164+ echo "# Patching with ${p}"
165+ patch -p1 < ${p}
166+ '') x.patches}
167+ '')}
140168
141− # Hack to get `gcc -m32' to work without having 32-bit Glibc headers.
142− mkdir -p tools/include/gnu
143− touch tools/include/gnu/stubs-32.h
144− '';
169+ ${withTools "postPatch" (name: x: x.postPatch)}
145170
146− # Fix build on Glibc 2.24.
147− NIX_CFLAGS_COMPILE = "-Wno-error=deprecated-declarations";
171+ ${config.postPatch or ""}
172+ '';
148173
149174 # TODO: Flask needs more testing before enabling it by default.
150175 #makeFlags = "XSM_ENABLE=y FLASK_ENABLE=y PREFIX=$(out) CONFIG_DIR=/etc XEN_EXTFILES_URL=\\$(XEN_ROOT)/xen_ext_files ";
151− makeFlags = "PREFIX=$(out) CONFIG_DIR=/etc XEN_EXTFILES_URL=\\$(XEN_ROOT)/xen_ext_files ";
176+ makeFlags = [ "PREFIX=$(out) CONFIG_DIR=/etc" "XEN_SCRIPT_DIR=/etc/xen/scripts" ]
177+ ++ (config.makeFlags or []);
152178
153179 buildFlags = "xen tools";
154180
155− postBuild =
156− ''
157− make -C docs man-pages
158−
159− (cd tools/xen-libhvm-dir-remote; make)
160− (cd tools/xen-libhvm-dir-remote/biospt; cc -Wall -g -D_LINUX -Wstrict-prototypes biospt.c -o biospt -I../libhvm -L../libhvm -lxenhvm)
161− '';
162−
163− installPhase =
164− ''
165− mkdir -p $out $out/share
166− cp -prvd dist/install/nix/store/*/* $out/
167− cp -prvd dist/install/boot $out/boot
168− cp -prvd dist/install/etc $out
169− cp -dR docs/man1 docs/man5 $out/share/man/
170− wrapPythonPrograms
171− substituteInPlace $out/etc/xen/scripts/hotplugpath.sh --replace SBINDIR=\"$out/sbin\" SBINDIR=\"$out/bin\"
172−
173− shopt -s extglob
174− for i in $out/etc/xen/scripts/!(*.sh); do
175− sed -i "2s@^@export PATH=$out/bin:${scriptEnvPath}\n@" $i
176− done
177−
178− (cd tools/xen-libhvm-dir-remote; make install)
179− cp tools/xen-libhvm-dir-remote/biospt/biospt $out/bin/.
180− '';
181+ postBuild = ''
182+ make -C docs man-pages
183+
184+ ${withTools "buildPhase" (name: x: x.buildPhase)}
185+ '';
186+
187+ installPhase = ''
188+ mkdir -p $out $out/share
189+ cp -prvd dist/install/nix/store/*/* $out/
190+ cp -prvd dist/install/boot $out/boot
191+ cp -prvd dist/install/etc $out
192+ cp -dR docs/man1 docs/man5 $out/share/man/
193+
194+ ${withTools "installPhase" (name: x: x.installPhase)}
195+
196+ # Hack
197+ substituteInPlace $out/etc/xen/scripts/hotplugpath.sh \
198+ --replace SBINDIR=\"$out/sbin\" SBINDIR=\"$out/bin\"
199+
200+ wrapPythonPrograms
201+
202+ shopt -s extglob
203+ for i in $out/etc/xen/scripts/!(*.sh); do
204+ sed -i "2s@^@export PATH=$out/bin:${scriptEnvPath}\n@" $i
205+ done
206+ '';
181207
182208 meta = {
183209 homepage = http://www.xen.org/;
184− description = "Xen hypervisor and management tools for Dom0";
210+ description = "Xen hypervisor and related components"
211+ + optionalString (args ? meta && args.meta ? description)
212+ " (${args.meta.description})";
213+ longDescription = (args.meta.longDescription or "")
214+ + "\nIncludes:\n"
215+ + withXenfiles (name: x: ''* ${name}: ${x.meta.description or "(No description)"}.'');
185216 platforms = [ "x86_64-linux" ];
186− maintainers = with stdenv.lib.maintainers; [ eelco tstrobel ];
217+ maintainers = with stdenv.lib.maintainers; [ eelco tstrobel oxij ];
187218 };
188−}
219+} // removeAttrs config [ "xenfiles" "buildInputs" "patches" "postPatch" "meta" ])