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