···
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
2
+
{ stdenv, cmake, pkgconfig, which
5
+
, bison, bzip2, checkpolicy, dev86, figlet, flex, gettext, glib
6
+
, iasl, libaio, libiconv, libuuid, ncurses, openssl, perl
8
+
# python2Packages.python
, 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
20
+
# python2Packages.markdown
21
+
, transfig, ghostscript, texinfo, pandoc
28
+
#TODO: fix paths instead
29
+
scriptEnvPath = concatMapStringsSep ":" (x: "${x}/bin") [
31
+
coreutils gawk gnused gnugrep diffutils utillinux multipath-tools
32
+
iproute inetutils iptables bridge-utils openvswitch nbd drbd
16
-
libDir = if stdenv.is64bit then "lib64" else "lib";
35
+
withXenfiles = f: concatStringsSep "\n" (mapAttrsToList f config.xenfiles);
18
-
# Sources needed to build the tools
19
-
# These sources are already rather old and probably do not change frequently
21
-
{ url = http://xenbits.xensource.com/xen-extfiles/ipxe-git-9a93db3f0947484e30e753bbd61a10b17336e20e.tar.gz;
22
-
sha256 = "0p206zaxlhda60ci33h9gipi5gm46fvvsm6k5c0w7b6cjg0yhb33";
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 ]));
37
+
withTools = a: f: withXenfiles (name: x: optionalString (hasAttr a x) ''
38
+
echo "processing ${name}"
47
+
stdenv.mkDerivation (rec {
48
+
inherit (config) version;
33
-
stdenv.mkDerivation {
34
-
inherit (xenConfig) name version src;
50
+
name = "xen-${version}";
dontUseCmakeConfigure = true;
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
hardeningDisable = [ "stackprotector" "fortify" "pic" ];
51
-
patches = stdenv.lib.optionals ((xenserverPatched == false) && (builtins.hasAttr "xenPatches" xenConfig)) xenConfig.xenPatches;
57
+
cmake pkgconfig which
54
-
${stdenv.lib.optionalString ((xenserverPatched == true) && (builtins.hasAttr "xenserverPatches" xenConfig)) xenConfig.xenserverPatches}
60
+
bison bzip2 checkpolicy dev86 figlet flex gettext glib iasl libaio
61
+
libiconv libuuid ncurses openssl perl python2Packages.python xz yajl zlib
64
+
ocamlPackages.findlib ocamlPackages.ocaml
67
+
python2Packages.wrapPython
70
+
python2Packages.markdown transfig ghostscript texinfo pandoc
73
+
] ++ (concatMap (x: x.buildInputs or []) (attrValues config.xenfiles))
74
+
++ (config.buildInputs or []);
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.
86
+
# Fake git: just print what it wants and die
87
+
cat > fake-bin/wget << EOF
89
+
echo ===== FAKE WGET: Not fetching \$*
93
+
# Fake git: just print what it wants and die
94
+
cat > fake-bin/git << EOF
96
+
echo ===== FAKE GIT: Not cloning \$*
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)} )
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)} )
100
+
chmod +x fake-bin/*
101
+
export PATH=$PATH:$PWD/fake-bin
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.
74
-
${flip concatMapStrings xenExtfiles (x: let src = fetchurl x; in ''
75
-
cp ${src} xen_ext_files/${src.name}
103
+
# Remove in-tree qemu stuff in case we build from a tar-ball
104
+
rm -rf tools/qemu-xen tools/qemu-xen-traditional
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'
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
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}
85
-
# Fake wget: copy prefetched downloads instead
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
91
-
export PATH=$PATH:$PWD/wget
92
-
export EXTRA_QEMUU_CONFIGURE_ARGS="--enable-spice --enable-usb-redir --enable-linux-aio"
120
+
patches = [ ./0000-fix-ipxe-src.patch
121
+
./0000-fix-install-python.patch ]
122
+
++ (config.patches or []);
95
-
# https://github.com/NixOS/nixpkgs/issues/13590
96
-
configureFlags = ["--disable-stubdom"];
100
-
substituteInPlace tools/libfsimage/common/fsimage_plugin.c \
101
-
--replace /usr $out
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'
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
107
-
substituteInPlace tools/xenmon/xenmon.py \
108
-
--replace /usr/bin/pkill ${procps}/bin/pkill
136
+
### Fixing everything else
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
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
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
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
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
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
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
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}"
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
169
+
${withTools "postPatch" (name: x: x.postPatch)}
146
-
# Fix build on Glibc 2.24.
147
-
NIX_CFLAGS_COMPILE = "-Wno-error=deprecated-declarations";
171
+
${config.postPatch or ""}
# TODO: Flask needs more testing before enabling it by default.
#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 []);
buildFlags = "xen tools";
157
-
make -C docs man-pages
182
+
make -C docs man-pages
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)
184
+
${withTools "buildPhase" (name: x: x.buildPhase)}
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/
171
-
substituteInPlace $out/etc/xen/scripts/hotplugpath.sh --replace SBINDIR=\"$out/sbin\" SBINDIR=\"$out/bin\"
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/
174
-
for i in $out/etc/xen/scripts/!(*.sh); do
175
-
sed -i "2s@^@export PATH=$out/bin:${scriptEnvPath}\n@" $i
194
+
${withTools "installPhase" (name: x: x.installPhase)}
178
-
(cd tools/xen-libhvm-dir-remote; make install)
179
-
cp tools/xen-libhvm-dir-remote/biospt/biospt $out/bin/.
197
+
substituteInPlace $out/etc/xen/scripts/hotplugpath.sh \
198
+
--replace SBINDIR=\"$out/sbin\" SBINDIR=\"$out/bin\"
203
+
for i in $out/etc/xen/scripts/!(*.sh); do
204
+
sed -i "2s@^@export PATH=$out/bin:${scriptEnvPath}\n@" $i
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 "")
215
+
+ withXenfiles (name: x: ''* ${name}: ${x.meta.description or "(No description)"}.'');
platforms = [ "x86_64-linux" ];
186
-
maintainers = with stdenv.lib.maintainers; [ eelco tstrobel ];
217
+
maintainers = with stdenv.lib.maintainers; [ eelco tstrobel oxij ];
219
+
} // removeAttrs config [ "xenfiles" "buildInputs" "patches" "postPatch" "meta" ])