1{ stdenv, fetchFromGitHub, pkgconfig, intltool, gperf, libcap, kmod
2, zlib, xz, pam, acl, cryptsetup, libuuid, m4, utillinux, libffi
3, glib, kbd, libxslt, coreutils, libgcrypt, libgpgerror, libapparmor, audit, lz4
4, kexectools, libmicrohttpd, linuxHeaders ? stdenv.cc.libc.linuxHeaders, libseccomp
5, iptables, gnu-efi
6, autoreconfHook, gettext, docbook_xsl, docbook_xml_dtd_42, docbook_xml_dtd_45
7, enableKDbus ? false
8}:
9
10assert stdenv.isLinux;
11
12stdenv.mkDerivation rec {
13 version = "231";
14 name = "systemd-${version}";
15
16 src = fetchFromGitHub {
17 owner = "NixOS";
18 repo = "systemd";
19 rev = "124564dd451349ec12673a7d4836b4a7a2f8fb4e";
20 sha256 = "021b7filp1dlhic1iv54b821w7mj5595njvzns939pmn636ry4m5";
21 };
22
23 /* gave up for now!
24 outputs = [ "out" "libudev" "doc" ]; # maybe: "dev"
25 # note: there are many references to ${systemd}/...
26 outputDev = "out";
27 propagatedBuildOutputs = "libudev";
28 */
29 outputs = [ "out" "man" ];
30
31 buildInputs =
32 [ linuxHeaders pkgconfig intltool gperf libcap kmod xz pam acl
33 /* cryptsetup */ libuuid m4 glib libxslt libgcrypt libgpgerror
34 libmicrohttpd kexectools libseccomp libffi audit lz4 libapparmor
35 iptables gnu-efi
36 /* FIXME: we may be able to prevent the following dependencies
37 by generating an autoconf'd tarball, but that's probably not
38 worth it. */
39 autoreconfHook gettext docbook_xsl docbook_xml_dtd_42 docbook_xml_dtd_45
40 ];
41
42
43 configureFlags =
44 [ "--localstatedir=/var"
45 "--sysconfdir=/etc"
46 "--with-rootprefix=$(out)"
47 "--with-kbd-loadkeys=${kbd}/bin/loadkeys"
48 "--with-kbd-setfont=${kbd}/bin/setfont"
49 "--with-rootprefix=$(out)"
50 "--with-dbuspolicydir=$(out)/etc/dbus-1/system.d"
51 "--with-dbussystemservicedir=$(out)/share/dbus-1/system-services"
52 "--with-dbussessionservicedir=$(out)/share/dbus-1/services"
53 "--with-tty-gid=3" # tty in NixOS has gid 3
54 "--enable-compat-libs" # get rid of this eventually
55 "--disable-tests"
56
57 "--enable-lz4"
58 "--enable-hostnamed"
59 "--enable-networkd"
60 "--disable-sysusers"
61 "--enable-timedated"
62 "--enable-timesyncd"
63 "--disable-firstboot"
64 "--enable-localed"
65 "--enable-resolved"
66 "--disable-split-usr"
67 "--disable-libcurl"
68 "--disable-libidn"
69 "--disable-quotacheck"
70 "--disable-ldconfig"
71 "--disable-smack"
72
73 (if stdenv.isArm then "--disable-gnuefi" else "--enable-gnuefi")
74 "--with-efi-libdir=${gnu-efi}/lib"
75 "--with-efi-includedir=${gnu-efi}/include"
76 "--with-efi-ldsdir=${gnu-efi}/lib"
77
78 "--with-sysvinit-path="
79 "--with-sysvrcnd-path="
80 "--with-rc-local-script-path-stop=/etc/halt.local"
81 ] ++ (if enableKDbus then [ "--enable-kdbus" ] else [ "--disable-kdbus" ]);
82
83 hardeningDisable = [ "stackprotector" ];
84
85 preConfigure =
86 ''
87 ./autogen.sh
88
89 # FIXME: patch this in systemd properly (and send upstream).
90 for i in src/remount-fs/remount-fs.c src/core/mount.c src/core/swap.c src/fsck/fsck.c units/emergency.service.in units/rescue.service.in src/journal/cat.c src/core/shutdown.c src/nspawn/nspawn.c src/shared/generator.c; do
91 test -e $i
92 substituteInPlace $i \
93 --replace /usr/bin/getent ${stdenv.glibc.bin}/bin/getent \
94 --replace /bin/mount ${utillinux.bin}/bin/mount \
95 --replace /bin/umount ${utillinux.bin}/bin/umount \
96 --replace /sbin/swapon ${utillinux.bin}/sbin/swapon \
97 --replace /sbin/swapoff ${utillinux.bin}/sbin/swapoff \
98 --replace /sbin/fsck ${utillinux.bin}/sbin/fsck \
99 --replace /bin/echo ${coreutils}/bin/echo \
100 --replace /bin/cat ${coreutils}/bin/cat \
101 --replace /sbin/sulogin ${utillinux.bin}/sbin/sulogin \
102 --replace /usr/lib/systemd/systemd-fsck $out/lib/systemd/systemd-fsck \
103 --replace /bin/plymouth /run/current-system/sw/bin/plymouth # To avoid dependency
104 done
105
106 substituteInPlace src/journal/catalog.c \
107 --replace /usr/lib/systemd/catalog/ $out/lib/systemd/catalog/
108
109 configureFlagsArray+=("--with-ntp-servers=0.nixos.pool.ntp.org 1.nixos.pool.ntp.org 2.nixos.pool.ntp.org 3.nixos.pool.ntp.org")
110
111 #export NIX_CFLAGS_LINK+=" -Wl,-rpath,$libudev/lib"
112 '';
113
114 /*
115 makeFlags = [
116 "udevlibexecdir=$(libudev)/lib/udev"
117 # udev rules refer to $out, and anything but libs should probably go to $out
118 "udevrulesdir=$(out)/lib/udev/rules.d"
119 "udevhwdbdir=$(out)/lib/udev/hwdb.d"
120 ];
121 */
122
123
124 PYTHON_BINARY = "${coreutils}/bin/env python"; # don't want a build time dependency on Python
125
126 NIX_CFLAGS_COMPILE =
127 [ # Can't say ${polkit.bin}/bin/pkttyagent here because that would
128 # lead to a cyclic dependency.
129 "-UPOLKIT_AGENT_BINARY_PATH" "-DPOLKIT_AGENT_BINARY_PATH=\"/run/current-system/sw/bin/pkttyagent\""
130 "-fno-stack-protector"
131
132 # Set the release_agent on /sys/fs/cgroup/systemd to the
133 # currently running systemd (/run/current-system/systemd) so
134 # that we don't use an obsolete/garbage-collected release agent.
135 "-USYSTEMD_CGROUP_AGENT_PATH" "-DSYSTEMD_CGROUP_AGENT_PATH=\"/run/current-system/systemd/lib/systemd/systemd-cgroups-agent\""
136
137 "-USYSTEMD_BINARY_PATH" "-DSYSTEMD_BINARY_PATH=\"/run/current-system/systemd/lib/systemd/systemd\""
138 ];
139
140 installFlags =
141 [ "localstatedir=$(TMPDIR)/var"
142 "sysconfdir=$(out)/etc"
143 "sysvinitdir=$(TMPDIR)/etc/init.d"
144 "pamconfdir=$(out)/etc/pam.d"
145 ];
146
147 postInstall =
148 ''
149 # sysinit.target: Don't depend on
150 # systemd-tmpfiles-setup.service. This interferes with NixOps's
151 # send-keys feature (since sshd.service depends indirectly on
152 # sysinit.target).
153 mv $out/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup-dev.service $out/lib/systemd/system/multi-user.target.wants/
154
155 mkdir -p $out/example/systemd
156 mv $out/lib/{modules-load.d,binfmt.d,sysctl.d,tmpfiles.d} $out/example
157 mv $out/lib/systemd/{system,user} $out/example/systemd
158
159 rm -rf $out/etc/systemd/system
160
161 # Install SysV compatibility commands.
162 mkdir -p $out/sbin
163 ln -s $out/lib/systemd/systemd $out/sbin/telinit
164 for i in init halt poweroff runlevel reboot shutdown; do
165 ln -s $out/bin/systemctl $out/sbin/$i
166 done
167
168 # Fix reference to /bin/false in the D-Bus services.
169 for i in $out/share/dbus-1/system-services/*.service; do
170 substituteInPlace $i --replace /bin/false ${coreutils}/bin/false
171 done
172
173 rm -rf $out/etc/rpm
174
175 rm $out/lib/*.la
176
177 # "kernel-install" shouldn't be used on NixOS.
178 find $out -name "*kernel-install*" -exec rm {} \;
179 ''; # */
180 /*
181 # Move lib(g)udev to a separate output. TODO: maybe split them up
182 # to avoid libudev pulling glib
183 mkdir -p "$libudev/lib"
184 mv "$out"/lib/lib{,g}udev* "$libudev/lib/"
185
186 for i in "$libudev"/lib/*.la; do
187 substituteInPlace $i --replace "$out" "$libudev"
188 done
189 for i in "$out"/lib/pkgconfig/{libudev,gudev-1.0}.pc; do
190 substituteInPlace $i --replace "libdir=$out" "libdir=$libudev"
191 done
192 */
193
194 enableParallelBuilding = true;
195 /*
196 # some libs fail to link to liblzma and/or libffi
197 postFixup = let extraLibs = stdenv.lib.makeLibraryPath [ xz.out libffi.out zlib.out ];
198 in ''
199 for f in "$out"/lib/*.so.0.*; do
200 patchelf --set-rpath `patchelf --print-rpath "$f"`':${extraLibs}' "$f"
201 done
202 '';
203 */
204
205 # The interface version prevents NixOS from switching to an
206 # incompatible systemd at runtime. (Switching across reboots is
207 # fine, of course.) It should be increased whenever systemd changes
208 # in a backwards-incompatible way. If the interface version of two
209 # systemd builds is the same, then we can switch between them at
210 # runtime; otherwise we can't and we need to reboot.
211 passthru.interfaceVersion = 2;
212
213 meta = {
214 homepage = "http://www.freedesktop.org/wiki/Software/systemd";
215 description = "A system and service manager for Linux";
216 platforms = stdenv.lib.platforms.linux;
217 maintainers = [ stdenv.lib.maintainers.eelco ];
218 };
219}