1# NOTE: Make sure to (re-)format this file on changes with `nixpkgs-fmt`!
2
3{ stdenv
4, lib
5, fetchFromGitHub
6, fetchpatch
7, fetchzip
8, buildPackages
9, ninja
10, meson
11, m4
12, pkg-config
13, coreutils
14, gperf
15, getent
16, glibcLocales
17, glib
18, substituteAll
19, gettext
20, python3Packages
21
22 # Mandatory dependencies
23, libcap
24, util-linux
25, kbd
26, kmod
27
28 # Optional dependencies
29, pam
30, cryptsetup
31, lvm2
32, audit
33, acl
34, lz4
35, libgcrypt
36, libgpg-error
37, libidn2
38, curl
39, gnutar
40, gnupg
41, zlib
42, xz
43, tpm2-tss
44, libuuid
45, libapparmor
46, intltool
47, bzip2
48, pcre2
49, e2fsprogs
50, linuxHeaders ? stdenv.cc.libc.linuxHeaders
51, gnu-efi
52, iptables
53, withSelinux ? false
54, libselinux
55, withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp
56, libseccomp
57, withKexectools ? lib.meta.availableOn stdenv.hostPlatform kexec-tools
58, kexec-tools
59, bashInteractive
60, libmicrohttpd
61
62 # the (optional) BPF feature requires bpftool, libbpf, clang and llmv-strip to be avilable during build time.
63 # Only libbpf should be a runtime dependency.
64, bpftools
65, libbpf
66, llvmPackages
67
68, withAnalyze ? true
69, withApparmor ? true
70, withCompression ? true # adds bzip2, lz4 and xz
71, withCoredump ? true
72, withCryptsetup ? true
73, withDocumentation ? true
74, withEfi ? stdenv.hostPlatform.isEfi
75, withFido2 ? true
76, withHomed ? false
77, withHostnamed ? true
78, withHwdb ? true
79, withImportd ? !stdenv.hostPlatform.isMusl
80, withLibBPF ? false # currently fails while generating BPF objects
81, withLocaled ? true
82, withLogind ? true
83, withMachined ? true
84, withNetworkd ? true
85, withNss ? !stdenv.hostPlatform.isMusl
86, withOomd ? false
87, withPCRE2 ? true
88, withPolkit ? true
89, withPortabled ? false
90, withRemote ? !stdenv.hostPlatform.isMusl
91, withResolved ? true
92, withShellCompletions ? true
93, withTimedated ? true
94, withTimesyncd ? true
95, withTpm2Tss ? !stdenv.hostPlatform.isMusl
96, withUserDb ? !stdenv.hostPlatform.isMusl
97, libfido2
98, p11-kit
99
100 # name argument
101, pname ? "systemd"
102
103, libxslt
104, docbook_xsl
105, docbook_xml_dtd_42
106, docbook_xml_dtd_45
107}:
108
109assert withResolved -> (libgcrypt != null && libgpg-error != null);
110assert withImportd ->
111(curl.dev != null && zlib != null && xz != null && libgcrypt != null
112 && gnutar != null && gnupg != null && withCompression);
113
114assert withEfi -> (gnu-efi != null);
115assert withRemote -> lib.getDev curl != null;
116assert withCoredump -> withCompression;
117
118assert withHomed -> withCryptsetup;
119
120assert withCryptsetup -> (cryptsetup != null);
121let
122 wantCurl = withRemote || withImportd;
123 version = "249.5";
124in
125stdenv.mkDerivation {
126 inherit pname version;
127
128 # We use systemd/systemd-stable for src, and ship NixOS-specific patches inside nixpkgs directly
129 # This has proven to be less error-prone than the previous systemd fork.
130 src = fetchFromGitHub {
131 owner = "systemd";
132 repo = "systemd-stable";
133 rev = "v${version}";
134 sha256 = "0bir2syy20rdi59sv8xp8nw1c92zl9z0wmv7ggsll8dca7niqwbp";
135 };
136
137 # If these need to be regenerated, `git am path/to/00*.patch` them into a
138 # systemd worktree, rebase to the more recent systemd version, and export the
139 # patches again via `git -c format.signoff=false format-patch v${version}`.
140 # Use `find . -name "*.patch" | sort` to get an up-to-date listing of all patches
141 patches = [
142 ./0001-Start-device-units-for-uninitialised-encrypted-devic.patch
143 ./0002-Don-t-try-to-unmount-nix-or-nix-store.patch
144 ./0003-Fix-NixOS-containers.patch
145 ./0004-Look-for-fsck-in-the-right-place.patch
146 ./0005-Add-some-NixOS-specific-unit-directories.patch
147 ./0006-Get-rid-of-a-useless-message-in-user-sessions.patch
148 ./0007-hostnamed-localed-timedated-disable-methods-that-cha.patch
149 ./0008-Fix-hwdb-paths.patch
150 ./0009-Change-usr-share-zoneinfo-to-etc-zoneinfo.patch
151 ./0010-localectl-use-etc-X11-xkb-for-list-x11.patch
152 ./0011-build-don-t-create-statedir-and-don-t-touch-prefixdi.patch
153 ./0012-inherit-systemd-environment-when-calling-generators.patch
154 ./0013-add-rootprefix-to-lookup-dir-paths.patch
155 ./0014-systemd-shutdown-execute-scripts-in-etc-systemd-syst.patch
156 ./0015-systemd-sleep-execute-scripts-in-etc-systemd-system-.patch
157 ./0016-kmod-static-nodes.service-Update-ConditionFileNotEmp.patch
158 ./0017-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch
159 ./0018-pkg-config-derive-prefix-from-prefix.patch
160
161 # In v248 or v249 we started to get in trouble due to our
162 # /etc/systemd/system being a symlink and thus being treated differently by
163 # systemd. With the below patch we mitigate that effect by special casing
164 # all our root unit dirs if they are symlinks. This does exactly what we
165 # need (AFAICT).
166 ./0019-core-handle-lookup-paths-being-symlinks.patch
167
168 # In v248 compiler weirdness and refactoring lead to the bootloader
169 # erroring out handling keyboard input on some systems. See
170 # https://github.com/systemd/systemd/issues/19191
171 # This should be redundant in v249.6 when it offically gets tagged in
172 # systemd-stable
173 ./0020-sd-boot-Unify-error-handling.patch
174 ./0021-sd-boot-Rework-console-input-handling.patch
175 ] ++ lib.optional stdenv.hostPlatform.isMusl (let
176 oe-core = fetchzip {
177 url = "https://git.openembedded.org/openembedded-core/snapshot/openembedded-core-14c6e5a4b72d0e4665279158a0740dd1dc21f72f.tar.bz2";
178 sha256 = "1jixya4czkr5p5rdcw3d6ips8zzr82dvnanvzvgjh67730scflya";
179 };
180 musl-patches = oe-core + "/meta/recipes-core/systemd/systemd";
181 in [
182 (musl-patches + "/0002-don-t-use-glibc-specific-qsort_r.patch")
183 (musl-patches + "/0003-missing_type.h-add-__compare_fn_t-and-comparison_fn_.patch")
184 (musl-patches + "/0004-add-fallback-parse_printf_format-implementation.patch")
185 (musl-patches + "/0005-src-basic-missing.h-check-for-missing-strndupa.patch")
186 (musl-patches + "/0006-Include-netinet-if_ether.h.patch")
187 (musl-patches + "/0007-don-t-fail-if-GLOB_BRACE-and-GLOB_ALTDIRFUNC-is-not-.patch")
188 (musl-patches + "/0008-add-missing-FTW_-macros-for-musl.patch")
189 (musl-patches + "/0009-fix-missing-of-__register_atfork-for-non-glibc-build.patch")
190 (musl-patches + "/0010-Use-uintmax_t-for-handling-rlim_t.patch")
191 (musl-patches + "/0011-test-sizeof.c-Disable-tests-for-missing-typedefs-in-.patch")
192 (musl-patches + "/0012-don-t-pass-AT_SYMLINK_NOFOLLOW-flag-to-faccessat.patch")
193 (musl-patches + "/0013-Define-glibc-compatible-basename-for-non-glibc-syste.patch")
194 (musl-patches + "/0014-Do-not-disable-buffering-when-writing-to-oom_score_a.patch")
195 (musl-patches + "/0015-distinguish-XSI-compliant-strerror_r-from-GNU-specif.patch")
196 (musl-patches + "/0016-Hide-__start_BUS_ERROR_MAP-and-__stop_BUS_ERROR_MAP.patch")
197 (musl-patches + "/0017-missing_type.h-add-__compar_d_fn_t-definition.patch")
198 (musl-patches + "/0018-avoid-redefinition-of-prctl_mm_map-structure.patch")
199 (musl-patches + "/0019-Handle-missing-LOCK_EX.patch")
200 (musl-patches + "/0021-test-json.c-define-M_PIl.patch")
201 (musl-patches + "/0022-do-not-disable-buffer-in-writing-files.patch")
202 (musl-patches + "/0025-Handle-__cpu_mask-usage.patch")
203 (musl-patches + "/0026-Handle-missing-gshadow.patch")
204 (musl-patches + "/0028-missing_syscall.h-Define-MIPS-ABI-defines-for-musl.patch")
205
206 # Being discussed upstream: https://lists.openembedded.org/g/openembedded-core/topic/86411771#157056
207 ./musl.diff
208 ]);
209
210 postPatch = ''
211 substituteInPlace src/basic/path-util.h --replace "@defaultPathNormal@" "${placeholder "out"}/bin/"
212 substituteInPlace src/boot/efi/meson.build \
213 --replace \
214 "find_program('objcopy'" \
215 "find_program('${stdenv.cc.bintools.targetPrefix}objcopy'"
216 '' + (
217 let
218 # The folllowing patches references to dynamic libraries to ensure that
219 # all the features that are implemented via dlopen(3) are available (or
220 # explicitly deactivated) by pointing dlopen to the absolute store path
221 # instead of relying on the linkers runtime lookup code.
222 #
223 # All of the shared library references have to be handled. When new ones
224 # are introduced by upstream (or one of our patches) they must be
225 # explicitly declared, otherwise the build will fail.
226 #
227 # As of systemd version 247 we've seen a few errors like `libpcre2.… not
228 # found` when using e.g. --grep with journalctl. Those errors should
229 # become less unexpected now.
230 #
231 # There are generally two classes of dlopen(3) calls. Those that we want to
232 # support and those that should be deactivated / unsupported. This change
233 # enforces that we handle all dlopen calls explicitly. Meaning: There is
234 # not a single dlopen call in the source code tree that we did not
235 # explicitly handle.
236 #
237 # In order to do this we introduced a list of attributes that maps from
238 # shared object name to the package that contains them. The package can be
239 # null meaning the reference should be nuked and the shared object will
240 # never be loadable during runtime (because it points at an invalid store
241 # path location).
242 #
243 # To get a list of dynamically loaded libraries issue something like
244 # `grep -ri '"lib[a-zA-Z0-9-]*\.so[\.0-9a-zA-z]*"'' $src` and update the below list.
245 dlopenLibs =
246 let
247 opt = condition: pkg: if condition then pkg else null;
248 in
249 [
250 # bpf compilation support
251 { name = "libbpf.so.0"; pkg = opt withLibBPF libbpf; }
252
253 # We did never provide support for libxkbcommon & qrencode
254 { name = "libxkbcommon.so.0"; pkg = null; }
255 { name = "libqrencode.so.4"; pkg = null; }
256
257 # We did not provide libpwquality before so it is safe to disable it for
258 # now.
259 { name = "libpwquality.so.1"; pkg = null; }
260
261 # Only include cryptsetup if it is enabled. We might not be able to
262 # provide it during "bootstrap" in e.g. the minimal systemd build as
263 # cryptsetup has udev (aka systemd) in it's dependencies.
264 { name = "libcryptsetup.so.12"; pkg = opt withCryptsetup cryptsetup; }
265
266 # We are using libidn2 so we only provide that and ignore the others.
267 # Systemd does this decision during configure time and uses ifdef's to
268 # enable specific branches. We can safely ignore (nuke) the libidn "v1"
269 # libraries.
270 { name = "libidn2.so.0"; pkg = libidn2; }
271 { name = "libidn.so.12"; pkg = null; }
272 { name = "libidn.so.11"; pkg = null; }
273
274 # journalctl --grep requires libpcre so lets provide it
275 { name = "libpcre2-8.so.0"; pkg = pcre2; }
276
277 # Support for TPM2 in systemd-cryptsetup, systemd-repart and systemd-cryptenroll
278 { name = "libtss2-esys.so.0"; pkg = opt withTpm2Tss tpm2-tss; }
279 { name = "libtss2-rc.so.0"; pkg = opt withTpm2Tss tpm2-tss; }
280 { name = "libtss2-mu.so.0"; pkg = opt withTpm2Tss tpm2-tss; }
281 { name = "libtss2-tcti-"; pkg = opt withTpm2Tss tpm2-tss; }
282 { name = "libfido2.so.1"; pkg = opt withFido2 libfido2; }
283 ];
284
285 patchDlOpen = dl:
286 let
287 library = "${lib.makeLibraryPath [ dl.pkg ]}/${dl.name}";
288 in
289 if dl.pkg == null then ''
290 # remove the dependency on the library by replacing it with an invalid path
291 for file in $(grep -lr '"${dl.name}"' src); do
292 echo "patching dlopen(\"${dl.name}\", …) in $file to an invalid store path ("/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-not-implemented/${dl.name}")…"
293 substituteInPlace "$file" --replace '"${dl.name}"' '"/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-not-implemented/${dl.name}"'
294 done
295 '' else ''
296 # ensure that the library we provide actually exists
297 if ! [ -e ${library} ]; then
298 # exceptional case, details:
299 # https://github.com/systemd/systemd-stable/blob/v249-stable/src/shared/tpm2-util.c#L157
300 if ! [[ "${library}" =~ .*libtss2-tcti-$ ]]; then
301 echo 'The shared library `${library}` does not exist but was given as subtitute for `${dl.name}`'
302 exit 1
303 fi
304 fi
305 # make the path to the dependency explicit
306 for file in $(grep -lr '"${dl.name}"' src); do
307 echo "patching dlopen(\"${dl.name}\", …) in $file to ${library}…"
308 substituteInPlace "$file" --replace '"${dl.name}"' '"${library}"'
309 done
310
311 '';
312 in
313 # patch all the dlopen calls to contain absolute paths to the libraries
314 lib.concatMapStringsSep "\n" patchDlOpen dlopenLibs
315 )
316 # finally ensure that there are no left-over dlopen calls (or rather strings pointing to shared libraries) that we didn't handle
317 + ''
318 if grep -qr '"lib[a-zA-Z0-9-]*\.so[\.0-9a-zA-z]*"' src; then
319 echo "Found unhandled dynamic library calls: "
320 grep -r '"lib[a-zA-Z0-9-]*\.so[\.0-9a-zA-z]*"' src
321 exit 1
322 fi
323 ''
324 # Finally patch shebangs that might need patching.
325 # Should no longer be necessary with v250.
326 # https://github.com/systemd/systemd/pull/19638
327 + ''
328 patchShebangs .
329 '';
330
331 outputs = [ "out" "man" "dev" ];
332
333 nativeBuildInputs =
334 [
335 pkg-config
336 gperf
337 ninja
338 meson
339 glibcLocales
340 getent
341 m4
342
343 intltool
344 gettext
345
346 libxslt
347 docbook_xsl
348 docbook_xml_dtd_42
349 docbook_xml_dtd_45
350 (buildPackages.python3Packages.python.withPackages (ps: with ps; [ lxml jinja2 ]))
351 ]
352 ++ lib.optional withLibBPF [
353 bpftools
354 llvmPackages.clang
355 llvmPackages.libllvm
356 ]
357 ;
358
359 buildInputs =
360 [
361 acl
362 audit
363 glib
364 kmod
365 libcap
366 libgcrypt
367 libidn2
368 libuuid
369 linuxHeaders
370 pam
371 ]
372
373 ++ lib.optional withApparmor libapparmor
374 ++ lib.optional wantCurl (lib.getDev curl)
375 ++ lib.optionals withCompression [ bzip2 lz4 xz ]
376 ++ lib.optional withCryptsetup (lib.getDev cryptsetup.dev)
377 ++ lib.optional withEfi gnu-efi
378 ++ lib.optional withKexectools kexec-tools
379 ++ lib.optional withLibseccomp libseccomp
380 ++ lib.optional withNetworkd iptables
381 ++ lib.optional withPCRE2 pcre2
382 ++ lib.optional withResolved libgpg-error
383 ++ lib.optional withSelinux libselinux
384 ++ lib.optional withRemote libmicrohttpd
385 ++ lib.optionals withHomed [ p11-kit ]
386 ++ lib.optionals (withHomed || withCryptsetup) [ libfido2 ]
387 ++ lib.optionals withLibBPF [ libbpf ]
388 ++ lib.optional withTpm2Tss tpm2-tss
389 ;
390
391 #dontAddPrefix = true;
392
393 mesonFlags = [
394 "-Dversion-tag=${version}"
395 "-Ddbuspolicydir=${placeholder "out"}/share/dbus-1/system.d"
396 "-Ddbussessionservicedir=${placeholder "out"}/share/dbus-1/services"
397 "-Ddbussystemservicedir=${placeholder "out"}/share/dbus-1/system-services"
398 "-Dpamconfdir=${placeholder "out"}/etc/pam.d"
399 "-Drootprefix=${placeholder "out"}"
400 "-Dpkgconfiglibdir=${placeholder "dev"}/lib/pkgconfig"
401 "-Dpkgconfigdatadir=${placeholder "dev"}/share/pkgconfig"
402 "-Dloadkeys-path=${kbd}/bin/loadkeys"
403 "-Dsetfont-path=${kbd}/bin/setfont"
404 "-Dtty-gid=3" # tty in NixOS has gid 3
405 "-Ddebug-shell=${bashInteractive}/bin/bash"
406 "-Dglib=${lib.boolToString (glib != null)}"
407 # while we do not run tests we should also not build them. Removes about 600 targets
408 "-Dtests=false"
409 "-Danalyze=${lib.boolToString withAnalyze}"
410 "-Dgcrypt=${lib.boolToString (libgcrypt != null)}"
411 "-Dimportd=${lib.boolToString withImportd}"
412 "-Dlz4=${lib.boolToString withCompression}"
413 "-Dhomed=${lib.boolToString withHomed}"
414 "-Dlogind=${lib.boolToString withLogind}"
415 "-Dlocaled=${lib.boolToString withLocaled}"
416 "-Dhostnamed=${lib.boolToString withHostnamed}"
417 "-Dmachined=${lib.boolToString withMachined}"
418 "-Dnetworkd=${lib.boolToString withNetworkd}"
419 "-Doomd=${lib.boolToString withOomd}"
420 "-Dpolkit=${lib.boolToString withPolkit}"
421 "-Dcryptsetup=${lib.boolToString withCryptsetup}"
422 "-Dportabled=${lib.boolToString withPortabled}"
423 "-Dhwdb=${lib.boolToString withHwdb}"
424 "-Dremote=${lib.boolToString withRemote}"
425 "-Dsysusers=false"
426 "-Dtimedated=${lib.boolToString withTimedated}"
427 "-Dtimesyncd=${lib.boolToString withTimesyncd}"
428 "-Duserdb=${lib.boolToString withUserDb}"
429 "-Dcoredump=${lib.boolToString withCoredump}"
430 "-Dfirstboot=false"
431 "-Dresolve=${lib.boolToString withResolved}"
432 "-Dsplit-usr=false"
433 "-Dlibcurl=${lib.boolToString wantCurl}"
434 "-Dlibidn=false"
435 "-Dlibidn2=true"
436 "-Dquotacheck=false"
437 "-Dldconfig=false"
438 "-Dsmack=true"
439 "-Db_pie=true"
440 "-Dinstall-sysconfdir=false"
441 "-Defi-ld=${stdenv.cc.bintools.targetPrefix}ld"
442 /*
443 As of now, systemd doesn't allow runtime configuration of these values. So
444 the settings in /etc/login.defs have no effect on it. Many people think this
445 should be supported however, see
446 - https://github.com/systemd/systemd/issues/3855
447 - https://github.com/systemd/systemd/issues/4850
448 - https://github.com/systemd/systemd/issues/9769
449 - https://github.com/systemd/systemd/issues/9843
450 - https://github.com/systemd/systemd/issues/10184
451 */
452 "-Dsystem-uid-max=999"
453 "-Dsystem-gid-max=999"
454 # "-Dtime-epoch=1"
455
456 "-Dsysvinit-path="
457 "-Dsysvrcnd-path="
458
459 "-Dkill-path=${coreutils}/bin/kill"
460 "-Dkmod-path=${kmod}/bin/kmod"
461 "-Dsulogin-path=${util-linux}/bin/sulogin"
462 "-Dmount-path=${util-linux}/bin/mount"
463 "-Dumount-path=${util-linux}/bin/umount"
464 "-Dcreate-log-dirs=false"
465
466 # Use cgroupsv2. This is already the upstream default, but better be explicit.
467 "-Ddefault-hierarchy=unified"
468 # Upstream defaulted to disable manpages since they optimize for the much
469 # more frequent development builds
470 "-Dman=true"
471
472 "-Defi=${lib.boolToString withEfi}"
473 "-Dgnu-efi=${lib.boolToString withEfi}"
474 ] ++ lib.optionals withEfi [
475 "-Defi-libdir=${toString gnu-efi}/lib"
476 "-Defi-includedir=${toString gnu-efi}/include/efi"
477 "-Defi-ldsdir=${toString gnu-efi}/lib"
478 ] ++ lib.optionals (withShellCompletions == false) [
479 "-Dbashcompletiondir=no"
480 "-Dzshcompletiondir=no"
481 ] ++ lib.optionals (!withNss) [
482 "-Dnss-myhostname=false"
483 "-Dnss-mymachines=false"
484 "-Dnss-resolve=false"
485 "-Dnss-systemd=false"
486 ] ++ lib.optionals withLibBPF [
487 "-Dbpf-framework=true"
488 ] ++ lib.optionals withTpm2Tss [
489 "-Dtpm2=true"
490 ] ++ lib.optionals stdenv.hostPlatform.isMusl [
491 "-Dgshadow=false"
492 "-Dutmp=false"
493 "-Didn=false"
494 ];
495
496 preConfigure = ''
497 mesonFlagsArray+=(-Dntp-servers="0.nixos.pool.ntp.org 1.nixos.pool.ntp.org 2.nixos.pool.ntp.org 3.nixos.pool.ntp.org")
498 export LC_ALL="en_US.UTF-8";
499 # FIXME: patch this in systemd properly (and send upstream).
500 # already fixed in f00929ad622c978f8ad83590a15a765b4beecac9: (u)mount
501 for i in \
502 src/core/mount.c \
503 src/core/swap.c \
504 src/cryptsetup/cryptsetup-generator.c \
505 src/journal/cat.c \
506 src/nspawn/nspawn.c \
507 src/remount-fs/remount-fs.c \
508 src/shared/generator.c \
509 src/shutdown/shutdown.c \
510 units/emergency.service.in \
511 units/modprobe@.service \
512 units/rescue.service.in \
513 units/systemd-logind.service.in \
514 units/systemd-nspawn@.service.in; \
515 do
516 test -e $i
517 substituteInPlace $i \
518 --replace /usr/bin/getent ${getent}/bin/getent \
519 --replace /sbin/mkswap ${lib.getBin util-linux}/sbin/mkswap \
520 --replace /sbin/swapon ${lib.getBin util-linux}/sbin/swapon \
521 --replace /sbin/swapoff ${lib.getBin util-linux}/sbin/swapoff \
522 --replace /bin/echo ${coreutils}/bin/echo \
523 --replace /bin/cat ${coreutils}/bin/cat \
524 --replace /sbin/sulogin ${lib.getBin util-linux}/sbin/sulogin \
525 --replace /sbin/modprobe ${lib.getBin kmod}/sbin/modprobe \
526 --replace /usr/lib/systemd/systemd-fsck $out/lib/systemd/systemd-fsck \
527 --replace /bin/plymouth /run/current-system/sw/bin/plymouth # To avoid dependency
528 done
529
530 for dir in tools src/resolve test src/test src/shared; do
531 patchShebangs $dir
532 done
533
534 # absolute paths to gpg & tar
535 substituteInPlace src/import/pull-common.c \
536 --replace '"gpg"' '"${gnupg}/bin/gpg"'
537 for file in src/import/{{export,import,pull}-tar,import-common}.c; do
538 substituteInPlace $file \
539 --replace '"tar"' '"${gnutar}/bin/tar"'
540 done
541
542
543 substituteInPlace src/libsystemd/sd-journal/catalog.c \
544 --replace /usr/lib/systemd/catalog/ $out/lib/systemd/catalog/
545 '';
546
547 # These defines are overridden by CFLAGS and would trigger annoying
548 # warning messages
549 postConfigure = ''
550 substituteInPlace config.h \
551 --replace "POLKIT_AGENT_BINARY_PATH" "_POLKIT_AGENT_BINARY_PATH" \
552 --replace "SYSTEMD_BINARY_PATH" "_SYSTEMD_BINARY_PATH" \
553 --replace "SYSTEMD_CGROUP_AGENT_PATH" "_SYSTEMD_CGROUP_AGENT_PATH"
554 '';
555
556 NIX_CFLAGS_COMPILE = toString ([
557 # Can't say ${polkit.bin}/bin/pkttyagent here because that would
558 # lead to a cyclic dependency.
559 "-UPOLKIT_AGENT_BINARY_PATH"
560 "-DPOLKIT_AGENT_BINARY_PATH=\"/run/current-system/sw/bin/pkttyagent\""
561
562 # Set the release_agent on /sys/fs/cgroup/systemd to the
563 # currently running systemd (/run/current-system/systemd) so
564 # that we don't use an obsolete/garbage-collected release agent.
565 "-USYSTEMD_CGROUP_AGENT_PATH"
566 "-DSYSTEMD_CGROUP_AGENT_PATH=\"/run/current-system/systemd/lib/systemd/systemd-cgroups-agent\""
567
568 "-USYSTEMD_BINARY_PATH"
569 "-DSYSTEMD_BINARY_PATH=\"/run/current-system/systemd/lib/systemd/systemd\""
570
571 ] ++ lib.optionals stdenv.hostPlatform.isMusl [
572 "-D__UAPI_DEF_ETHHDR=0"
573 ]);
574
575 doCheck = false; # fails a bunch of tests
576
577 # trigger the test -n "$DESTDIR" || mutate in upstreams build system
578 preInstall = ''
579 export DESTDIR=/
580 '';
581
582 postInstall = ''
583 # sysinit.target: Don't depend on
584 # systemd-tmpfiles-setup.service. This interferes with NixOps's
585 # send-keys feature (since sshd.service depends indirectly on
586 # sysinit.target).
587 mv $out/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup-dev.service $out/lib/systemd/system/multi-user.target.wants/
588
589 mkdir -p $out/example/systemd
590 mv $out/lib/{modules-load.d,binfmt.d,sysctl.d,tmpfiles.d} $out/example
591 mv $out/lib/systemd/{system,user} $out/example/systemd
592
593 rm -rf $out/etc/systemd/system
594
595 # Fix reference to /bin/false in the D-Bus services.
596 for i in $out/share/dbus-1/system-services/*.service; do
597 substituteInPlace $i --replace /bin/false ${coreutils}/bin/false
598 done
599
600 rm -rf $out/etc/rpm
601
602 # "kernel-install" shouldn't be used on NixOS.
603 find $out -name "*kernel-install*" -exec rm {} \;
604 '' + lib.optionalString (!withDocumentation) ''
605 rm -rf $out/share/doc
606 '';
607
608 # The interface version prevents NixOS from switching to an
609 # incompatible systemd at runtime. (Switching across reboots is
610 # fine, of course.) It should be increased whenever systemd changes
611 # in a backwards-incompatible way. If the interface version of two
612 # systemd builds is the same, then we can switch between them at
613 # runtime; otherwise we can't and we need to reboot.
614 passthru.interfaceVersion = 2;
615
616 meta = with lib; {
617 homepage = "https://www.freedesktop.org/wiki/Software/systemd/";
618 description = "A system and service manager for Linux";
619 license = licenses.lgpl21Plus;
620 platforms = platforms.linux;
621 priority = 10;
622 maintainers = with maintainers; [ andir eelco flokli kloenk ];
623 };
624}