1{ stdenv, fetchFromGitHub, fetchpatch, pkgconfig, intltool, gperf, libcap, kmod
2, zlib, xz, pam, acl, cryptsetup, libuuid, m4, utillinux, libffi
3, glib, kbd, libxslt, coreutils, libgcrypt, libgpgerror, libidn2, libapparmor
4, audit, lz4, bzip2, kexectools, libmicrohttpd
5, linuxHeaders ? stdenv.cc.libc.linuxHeaders
6, libseccomp, iptables, gnu-efi
7, autoreconfHook, gettext, docbook_xsl, docbook_xml_dtd_42, docbook_xml_dtd_45
8, ninja, meson, python3Packages, glibcLocales
9, patchelf
10, getent
11, hostPlatform
12}:
13
14assert stdenv.isLinux;
15
16let
17 pythonLxmlEnv = python3Packages.python.withPackages ( ps: with ps; [ python3Packages.lxml ]);
18
19in stdenv.mkDerivation rec {
20 version = "237";
21 name = "systemd-${version}";
22
23 src = fetchFromGitHub {
24 owner = "NixOS";
25 repo = "systemd";
26 rev = "98067cc806ae0d2759cdd2334f230cd8548e5317";
27 sha256 = "077svfs2xy3g30s62q69wcv5pb9vfhzh8i7lhfri73vvhwbpzd5q";
28 };
29
30 outputs = [ "out" "lib" "man" "dev" ];
31
32 nativeBuildInputs =
33 [ pkgconfig intltool gperf libxslt gettext docbook_xsl docbook_xml_dtd_42 docbook_xml_dtd_45
34 ninja meson
35 coreutils # meson calls date, stat etc.
36 pythonLxmlEnv glibcLocales
37 patchelf getent
38 ];
39 buildInputs =
40 [ linuxHeaders libcap kmod xz pam acl
41 /* cryptsetup */ libuuid m4 glib libgcrypt libgpgerror libidn2
42 libmicrohttpd kexectools libseccomp libffi audit lz4 bzip2 libapparmor
43 iptables gnu-efi
44 ];
45
46 #dontAddPrefix = true;
47
48 mesonFlags = [
49 "-Dloadkeys-path=${kbd}/bin/loadkeys"
50 "-Dsetfont-path=${kbd}/bin/setfont"
51 "-Dtty-gid=3" # tty in NixOS has gid 3
52 # "-Dtests=" # TODO
53 "-Dlz4=true"
54 "-Dhostnamed=true"
55 "-Dnetworkd=true"
56 "-Dsysusers=false"
57 "-Dtimedated=true"
58 "-Dtimesyncd=true"
59 "-Dfirstboot=false"
60 "-Dlocaled=true"
61 "-Dresolve=true"
62 "-Dsplit-usr=false"
63 "-Dlibcurl=false"
64 "-Dlibidn=false"
65 "-Dlibidn2=true"
66 "-Dquotacheck=false"
67 "-Dldconfig=false"
68 "-Dsmack=true"
69 "-Dsystem-uid-max=499" #TODO: debug why awking around in /etc/login.defs doesn't work
70 "-Dsystem-gid-max=499"
71 # "-Dtime-epoch=1"
72
73 (if stdenv.isArm || !hostPlatform.isEfi then "-Dgnu-efi=false" else "-Dgnu-efi=true")
74 "-Defi-libdir=${toString gnu-efi}/lib"
75 "-Defi-includedir=${toString gnu-efi}/include/efi"
76 "-Defi-ldsdir=${toString gnu-efi}/lib"
77
78 "-Dsysvinit-path="
79 "-Dsysvrcnd-path="
80 ];
81
82 preConfigure = ''
83 mesonFlagsArray+=(-Dntp-servers="0.nixos.pool.ntp.org 1.nixos.pool.ntp.org 2.nixos.pool.ntp.org 3.nixos.pool.ntp.org")
84 mesonFlagsArray+=(-Ddbuspolicydir=$out/etc/dbus-1/system.d)
85 mesonFlagsArray+=(-Ddbussessionservicedir=$out/share/dbus-1/services)
86 mesonFlagsArray+=(-Ddbussystemservicedir=$out/share/dbus-1/system-services)
87 mesonFlagsArray+=(-Dpamconfdir=$out/etc/pam.d)
88 mesonFlagsArray+=(-Drootprefix=$out)
89 mesonFlagsArray+=(-Dlibdir=$lib/lib)
90 mesonFlagsArray+=(-Drootlibdir=$lib/lib)
91 mesonFlagsArray+=(-Dmandir=$man/lib)
92 mesonFlagsArray+=(-Dincludedir=$dev/include)
93 mesonFlagsArray+=(-Dpkgconfiglibdir=$dev/lib/pkgconfig)
94 mesonFlagsArray+=(-Dpkgconfigdatadir=$dev/share/pkgconfig)
95
96 # FIXME: Why aren't includedir and libdir picked up from mesonFlags while other options are?
97 substituteInPlace meson.build \
98 --replace "includedir = join_paths(prefixdir, get_option('includedir'))" \
99 "includedir = '$dev/include'" \
100 --replace "libdir = join_paths(prefixdir, get_option('libdir'))" \
101 "libdir = '$lib/lib'"
102
103 export LC_ALL="en_US.UTF-8";
104 # FIXME: patch this in systemd properly (and send upstream).
105 # already fixed in f00929ad622c978f8ad83590a15a765b4beecac9: (u)mount
106 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
107 test -e $i
108 substituteInPlace $i \
109 --replace /usr/bin/getent ${getent}/bin/getent \
110 --replace /sbin/swapon ${utillinux.bin}/sbin/swapon \
111 --replace /sbin/swapoff ${utillinux.bin}/sbin/swapoff \
112 --replace /sbin/fsck ${utillinux.bin}/sbin/fsck \
113 --replace /bin/echo ${coreutils}/bin/echo \
114 --replace /bin/cat ${coreutils}/bin/cat \
115 --replace /sbin/sulogin ${utillinux.bin}/sbin/sulogin \
116 --replace /usr/lib/systemd/systemd-fsck $out/lib/systemd/systemd-fsck \
117 --replace /bin/plymouth /run/current-system/sw/bin/plymouth # To avoid dependency
118 done
119
120 for i in tools/xml_helper.py tools/make-directive-index.py tools/make-man-index.py test/sys-script.py; do
121 substituteInPlace $i \
122 --replace "#!/usr/bin/env python" "#!${pythonLxmlEnv}/bin/python"
123 done
124
125 for i in src/basic/generate-gperfs.py src/resolve/generate-dns_type-gperf.py src/test/generate-sym-test.py ; do
126 substituteInPlace $i \
127 --replace "#!/usr/bin/env python" "#!${python3Packages.python}/bin/python"
128 done
129
130 substituteInPlace src/journal/catalog.c \
131 --replace /usr/lib/systemd/catalog/ $out/lib/systemd/catalog/
132 '';
133
134 # These defines are overridden by CFLAGS and would trigger annoying
135 # warning messages
136 postConfigure = ''
137 substituteInPlace config.h \
138 --replace "POLKIT_AGENT_BINARY_PATH" "_POLKIT_AGENT_BINARY_PATH" \
139 --replace "SYSTEMD_BINARY_PATH" "_SYSTEMD_BINARY_PATH" \
140 --replace "SYSTEMD_CGROUP_AGENT_PATH" "_SYSTEMD_CGROUP_AGENT_PATH"
141 '';
142
143 hardeningDisable = [ "stackprotector" ];
144
145 NIX_CFLAGS_COMPILE =
146 [ # Can't say ${polkit.bin}/bin/pkttyagent here because that would
147 # lead to a cyclic dependency.
148 "-UPOLKIT_AGENT_BINARY_PATH" "-DPOLKIT_AGENT_BINARY_PATH=\"/run/current-system/sw/bin/pkttyagent\""
149
150 # Set the release_agent on /sys/fs/cgroup/systemd to the
151 # currently running systemd (/run/current-system/systemd) so
152 # that we don't use an obsolete/garbage-collected release agent.
153 "-USYSTEMD_CGROUP_AGENT_PATH" "-DSYSTEMD_CGROUP_AGENT_PATH=\"/run/current-system/systemd/lib/systemd/systemd-cgroups-agent\""
154
155 "-USYSTEMD_BINARY_PATH" "-DSYSTEMD_BINARY_PATH=\"/run/current-system/systemd/lib/systemd/systemd\""
156 ];
157
158 postInstall = ''
159 # sysinit.target: Don't depend on
160 # systemd-tmpfiles-setup.service. This interferes with NixOps's
161 # send-keys feature (since sshd.service depends indirectly on
162 # sysinit.target).
163 mv $out/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup-dev.service $out/lib/systemd/system/multi-user.target.wants/
164
165 mkdir -p $out/example/systemd
166 mv $out/lib/{modules-load.d,binfmt.d,sysctl.d,tmpfiles.d} $out/example
167 mv $out/lib/systemd/{system,user} $out/example/systemd
168
169 rm -rf $out/etc/systemd/system
170
171 # Install SysV compatibility commands.
172 mkdir -p $out/sbin
173 ln -s $out/lib/systemd/systemd $out/sbin/telinit
174 for i in init halt poweroff runlevel reboot shutdown; do
175 ln -s $out/bin/systemctl $out/sbin/$i
176 done
177
178 # Fix reference to /bin/false in the D-Bus services.
179 for i in $out/share/dbus-1/system-services/*.service; do
180 substituteInPlace $i --replace /bin/false ${coreutils}/bin/false
181 done
182
183 rm -rf $out/etc/rpm
184
185 # "kernel-install" shouldn't be used on NixOS.
186 find $out -name "*kernel-install*" -exec rm {} \;
187
188 # Keep only libudev and libsystemd in the lib output.
189 mkdir -p $out/lib
190 mv $lib/lib/security $lib/lib/libnss* $out/lib/
191 ''; # */
192
193 enableParallelBuilding = true;
194
195 # The rpath to the shared systemd library is not added by meson. The
196 # functionality was removed by a nixpkgs patch because it would overwrite
197 # the existing rpath.
198 postFixup = ''
199 sharedLib=libsystemd-shared-${version}.so
200 for prog in `find $out -type f -executable`; do
201 (patchelf --print-needed $prog | grep $sharedLib > /dev/null) && (
202 patchelf --set-rpath `patchelf --print-rpath $prog`:"$out/lib/systemd" $prog
203 ) || true
204 done
205 '';
206
207 # The interface version prevents NixOS from switching to an
208 # incompatible systemd at runtime. (Switching across reboots is
209 # fine, of course.) It should be increased whenever systemd changes
210 # in a backwards-incompatible way. If the interface version of two
211 # systemd builds is the same, then we can switch between them at
212 # runtime; otherwise we can't and we need to reboot.
213 passthru.interfaceVersion = 2;
214
215 meta = {
216 homepage = http://www.freedesktop.org/wiki/Software/systemd;
217 description = "A system and service manager for Linux";
218 platforms = stdenv.lib.platforms.linux;
219 maintainers = [ stdenv.lib.maintainers.eelco ];
220 };
221}