Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at domenkozar-patch-1 726 lines 28 kB view raw
1# NOTE: Make sure to (re-)format this file on changes with `nixpkgs-fmt`! 2 3{ stdenv 4, lib 5, nixosTests 6, fetchFromGitHub 7, fetchpatch 8, fetchzip 9, applyPatches 10, buildPackages 11, makeBinaryWrapper 12, ninja 13, meson 14, m4 15, pkg-config 16, coreutils 17, gperf 18, getent 19, glibcLocales 20 21 # glib is only used during tests (test-bus-gvariant, test-bus-marshal) 22, glib 23, substituteAll 24, gettext 25, python3Packages 26 27 # Mandatory dependencies 28, libcap 29, util-linux 30, kbd 31, kmod 32, libxcrypt 33 34 # Optional dependencies 35, pam 36, cryptsetup 37, audit 38, acl 39, lz4 40, libgcrypt 41, libgpg-error 42, libidn2 43, curl 44, gnutar 45, gnupg 46, zlib 47, xz 48, zstd 49, tpm2-tss 50, libuuid 51, libapparmor 52, intltool 53, bzip2 54, pcre2 55, e2fsprogs 56, elfutils 57, linuxHeaders ? stdenv.cc.libc.linuxHeaders 58, gnu-efi 59, iptables 60, withSelinux ? false 61, libselinux 62, withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp 63, libseccomp 64, withKexectools ? lib.meta.availableOn stdenv.hostPlatform kexec-tools 65, kexec-tools 66, bashInteractive 67, libmicrohttpd 68, libfido2 69, p11-kit 70 71 # the (optional) BPF feature requires bpftool, libbpf, clang and llvm-strip to be available during build time. 72 # Only libbpf should be a runtime dependency. 73, bpftools 74, libbpf 75, llvmPackages 76 77, withAnalyze ? true 78, withApparmor ? true 79, withCompression ? true # adds bzip2, lz4, xz and zstd 80, withCoredump ? true 81, withCryptsetup ? true 82, withDocumentation ? true 83, withEfi ? stdenv.hostPlatform.isEfi && !stdenv.hostPlatform.isMusl 84, withFido2 ? true 85, withHomed ? false 86, withHostnamed ? true 87, withHwdb ? true 88, withImportd ? !stdenv.hostPlatform.isMusl 89, withLibBPF ? lib.versionAtLeast llvmPackages.clang.version "10.0" 90, withLocaled ? true 91, withLogind ? true 92, withMachined ? true 93, withNetworkd ? true 94, withNss ? !stdenv.hostPlatform.isMusl 95, withOomd ? true 96, withPCRE2 ? true 97, withPolkit ? true 98, withPortabled ? !stdenv.hostPlatform.isMusl 99, withRemote ? !stdenv.hostPlatform.isMusl 100, withResolved ? true 101, withShellCompletions ? true 102, withTimedated ? true 103, withTimesyncd ? true 104, withTpm2Tss ? true 105, withUserDb ? true 106, withUtmp ? !stdenv.hostPlatform.isMusl 107 # tests assume too much system access for them to be feasible for us right now 108, withTests ? false 109 110 # name argument 111, pname ? "systemd" 112 113, libxslt 114, docbook_xsl 115, docbook_xml_dtd_42 116, docbook_xml_dtd_45 117}: 118 119assert withImportd -> withCompression; 120assert withCoredump -> withCompression; 121assert withHomed -> withCryptsetup; 122 123let 124 wantCurl = withRemote || withImportd; 125 wantGcrypt = withResolved || withImportd; 126 version = "252.1"; 127 128 # Bump this variable on every (major) version change. See below (in the meson options list) for why. 129 # command: 130 # $ curl -s https://api.github.com/repos/systemd/systemd/releases/latest | \ 131 # jq '.created_at|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime' 132 releaseTimestamp = "1667246393"; 133in 134stdenv.mkDerivation { 135 inherit pname version; 136 137 # We use systemd/systemd-stable for src, and ship NixOS-specific patches inside nixpkgs directly 138 # This has proven to be less error-prone than the previous systemd fork. 139 src = fetchFromGitHub { 140 owner = "systemd"; 141 repo = "systemd-stable"; 142 rev = "v${version}"; 143 hash = "sha256-G43qbNF7znTITSM78sOL0qi8nqaA7qIhmiqP/rZKjXY="; 144 }; 145 146 # On major changes, or when otherwise required, you *must* reformat the patches, 147 # `git am path/to/00*.patch` them into a systemd worktree, rebase to the more recent 148 # systemd version, and export the patches again via 149 # `git -c format.signoff=false format-patch v${version} --no-numbered --zero-commit --no-signature`. 150 # Use `find . -name "*.patch" | sort` to get an up-to-date listing of all patches 151 patches = [ 152 ./0001-Start-device-units-for-uninitialised-encrypted-devic.patch 153 ./0002-Don-t-try-to-unmount-nix-or-nix-store.patch 154 ./0003-Fix-NixOS-containers.patch 155 ./0004-Look-for-fsck-in-the-right-place.patch 156 ./0005-Add-some-NixOS-specific-unit-directories.patch 157 ./0006-Get-rid-of-a-useless-message-in-user-sessions.patch 158 ./0007-hostnamed-localed-timedated-disable-methods-that-cha.patch 159 ./0008-Fix-hwdb-paths.patch 160 ./0009-Change-usr-share-zoneinfo-to-etc-zoneinfo.patch 161 ./0010-localectl-use-etc-X11-xkb-for-list-x11.patch 162 ./0011-build-don-t-create-statedir-and-don-t-touch-prefixdi.patch 163 ./0012-add-rootprefix-to-lookup-dir-paths.patch 164 ./0013-systemd-shutdown-execute-scripts-in-etc-systemd-syst.patch 165 ./0014-systemd-sleep-execute-scripts-in-etc-systemd-system-.patch 166 ./0015-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch 167 ./0016-pkg-config-derive-prefix-from-prefix.patch 168 ./0017-inherit-systemd-environment-when-calling-generators.patch 169 ./0018-core-don-t-taint-on-unmerged-usr.patch 170 ] ++ lib.optional stdenv.hostPlatform.isMusl ( 171 let 172 oe-core = fetchzip { 173 url = "https://git.openembedded.org/openembedded-core/snapshot/openembedded-core-d43ec090ceb2bf0016a065103a4c34d0c43cb906.tar.gz"; 174 sha256 = "sha256-e5rHmz0uyNgJwrAj96VGWWu9YHhZtJXoDpCtj17eC5w="; 175 }; 176 oe-core-patched = applyPatches { 177 src = oe-core; 178 patches = [ 179 (fetchpatch { 180 url = "https://lore.kernel.org/all/20221109002306.853567-1-raj.khem@gmail.com/raw"; 181 includes = [ "meta/recipes-core/systemd/systemd/*" ]; 182 sha256 = "sha256-aPJjN4vesZwFzgY4Nb6uaIuHz/quH1HccSVEof32IOU="; 183 }) 184 ]; 185 }; 186 musl-patches = oe-core-patched + "/meta/recipes-core/systemd/systemd"; 187 in 188 [ 189 (musl-patches + "/0003-missing_type.h-add-comparison_fn_t.patch") 190 (musl-patches + "/0004-add-fallback-parse_printf_format-implementation.patch") 191 (musl-patches + "/0005-src-basic-missing.h-check-for-missing-strndupa.patch") 192 (musl-patches + "/0007-don-t-fail-if-GLOB_BRACE-and-GLOB_ALTDIRFUNC-is-not-.patch") 193 (musl-patches + "/0008-add-missing-FTW_-macros-for-musl.patch") 194 (musl-patches + "/0010-Use-uintmax_t-for-handling-rlim_t.patch") 195 (musl-patches + "/0011-test-sizeof.c-Disable-tests-for-missing-typedefs-in-.patch") 196 (musl-patches + "/0012-don-t-pass-AT_SYMLINK_NOFOLLOW-flag-to-faccessat.patch") 197 (musl-patches + "/0013-Define-glibc-compatible-basename-for-non-glibc-syste.patch") 198 (musl-patches + "/0014-Do-not-disable-buffering-when-writing-to-oom_score_a.patch") 199 (musl-patches + "/0015-distinguish-XSI-compliant-strerror_r-from-GNU-specif.patch") 200 (musl-patches + "/0018-avoid-redefinition-of-prctl_mm_map-structure.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 (musl-patches + "/0001-pass-correct-parameters-to-getdents64.patch") 206 (musl-patches + "/0002-Add-sys-stat.h-for-S_IFDIR.patch") 207 (musl-patches + "/0001-Adjust-for-musl-headers.patch") 208 (musl-patches + "/0001-networkd-ipv4acd.c-Use-net-if.h-for-getting-IFF_LOOP.patch") 209 (musl-patches + "/0001-test-compile-test-utmp.c-only-if-UTMP-is-enabled.patch") 210 ] 211 ); 212 213 postPatch = '' 214 substituteInPlace src/basic/path-util.h --replace "@defaultPathNormal@" "${placeholder "out"}/bin/" 215 substituteInPlace src/boot/efi/meson.build \ 216 --replace \ 217 "run_command(cc.cmd_array(), '-print-prog-name=objcopy', check: true).stdout().strip()" \ 218 "'${stdenv.cc.bintools.targetPrefix}objcopy'" 219 '' + lib.optionalString withLibBPF '' 220 substituteInPlace meson.build \ 221 --replace "find_program('clang'" "find_program('${stdenv.cc.targetPrefix}clang'" 222 # BPF does not work with stack protector 223 substituteInPlace src/core/bpf/meson.build \ 224 --replace "clang_flags = [" "clang_flags = [ '-fno-stack-protector'," 225 '' + ( 226 let 227 # The following patches references to dynamic libraries to ensure that 228 # all the features that are implemented via dlopen(3) are available (or 229 # explicitly deactivated) by pointing dlopen to the absolute store path 230 # instead of relying on the linkers runtime lookup code. 231 # 232 # All of the shared library references have to be handled. When new ones 233 # are introduced by upstream (or one of our patches) they must be 234 # explicitly declared, otherwise the build will fail. 235 # 236 # As of systemd version 247 we've seen a few errors like `libpcre2.… not 237 # found` when using e.g. --grep with journalctl. Those errors should 238 # become less unexpected now. 239 # 240 # There are generally two classes of dlopen(3) calls. Those that we want to 241 # support and those that should be deactivated / unsupported. This change 242 # enforces that we handle all dlopen calls explicitly. Meaning: There is 243 # not a single dlopen call in the source code tree that we did not 244 # explicitly handle. 245 # 246 # In order to do this we introduced a list of attributes that maps from 247 # shared object name to the package that contains them. The package can be 248 # null meaning the reference should be nuked and the shared object will 249 # never be loadable during runtime (because it points at an invalid store 250 # path location). 251 # 252 # To get a list of dynamically loaded libraries issue something like 253 # `grep -ri '"lib[a-zA-Z0-9-]*\.so[\.0-9a-zA-z]*"'' $src` and update the below list. 254 dlopenLibs = 255 let 256 opt = condition: pkg: if condition then pkg else null; 257 in 258 [ 259 # bpf compilation support. We use libbpf 1 now. 260 { name = "libbpf.so.1"; pkg = opt withLibBPF libbpf; } 261 { name = "libbpf.so.0"; pkg = null; } 262 263 # We did never provide support for libxkbcommon & qrencode 264 { name = "libxkbcommon.so.0"; pkg = null; } 265 { name = "libqrencode.so.4"; pkg = null; } 266 { name = "libqrencode.so.3"; pkg = null; } 267 268 # We did not provide libpwquality before so it is safe to disable it for 269 # now. 270 { name = "libpwquality.so.1"; pkg = null; } 271 272 # Only include cryptsetup if it is enabled. We might not be able to 273 # provide it during "bootstrap" in e.g. the minimal systemd build as 274 # cryptsetup has udev (aka systemd) in it's dependencies. 275 { name = "libcryptsetup.so.12"; pkg = opt withCryptsetup cryptsetup; } 276 277 # We are using libidn2 so we only provide that and ignore the others. 278 # Systemd does this decision during configure time and uses ifdef's to 279 # enable specific branches. We can safely ignore (nuke) the libidn "v1" 280 # libraries. 281 { name = "libidn2.so.0"; pkg = libidn2; } 282 { name = "libidn.so.12"; pkg = null; } 283 { name = "libidn.so.11"; pkg = null; } 284 285 # journalctl --grep requires libpcre so let's provide it 286 { name = "libpcre2-8.so.0"; pkg = pcre2; } 287 288 # Support for TPM2 in systemd-cryptsetup, systemd-repart and systemd-cryptenroll 289 { name = "libtss2-esys.so.0"; pkg = opt withTpm2Tss tpm2-tss; } 290 { name = "libtss2-rc.so.0"; pkg = opt withTpm2Tss tpm2-tss; } 291 { name = "libtss2-mu.so.0"; pkg = opt withTpm2Tss tpm2-tss; } 292 { name = "libtss2-tcti-"; pkg = opt withTpm2Tss tpm2-tss; } 293 { name = "libfido2.so.1"; pkg = opt withFido2 libfido2; } 294 295 # inspect-elf support 296 { name = "libelf.so.1"; pkg = opt withCoredump elfutils; } 297 { name = "libdw.so.1"; pkg = opt withCoredump elfutils; } 298 ]; 299 300 patchDlOpen = dl: 301 let 302 library = "${lib.makeLibraryPath [ dl.pkg ]}/${dl.name}"; 303 in 304 if dl.pkg == null then '' 305 # remove the dependency on the library by replacing it with an invalid path 306 for file in $(grep -lr '"${dl.name}"' src); do 307 echo "patching dlopen(\"${dl.name}\", ) in $file to an invalid store path ("/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-not-implemented/${dl.name}")" 308 substituteInPlace "$file" --replace '"${dl.name}"' '"/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-not-implemented/${dl.name}"' 309 done 310 '' else '' 311 # ensure that the library we provide actually exists 312 if ! [ -e ${library} ]; then 313 # exceptional case, details: 314 # https://github.com/systemd/systemd-stable/blob/v249-stable/src/shared/tpm2-util.c#L157 315 if ! [[ "${library}" =~ .*libtss2-tcti-$ ]]; then 316 echo 'The shared library `${library}` does not exist but was given as substitute for `${dl.name}`' 317 exit 1 318 fi 319 fi 320 # make the path to the dependency explicit 321 for file in $(grep -lr '"${dl.name}"' src); do 322 echo "patching dlopen(\"${dl.name}\", ) in $file to ${library}" 323 substituteInPlace "$file" --replace '"${dl.name}"' '"${library}"' 324 done 325 326 ''; 327 in 328 # patch all the dlopen calls to contain absolute paths to the libraries 329 lib.concatMapStringsSep "\n" patchDlOpen dlopenLibs 330 ) 331 # finally ensure that there are no left-over dlopen calls (or rather strings pointing to shared libraries) that we didn't handle 332 + '' 333 if grep -qr '"lib[a-zA-Z0-9-]*\.so[\.0-9a-zA-z]*"' src; then 334 echo "Found unhandled dynamic library calls: " 335 grep -r '"lib[a-zA-Z0-9-]*\.so[\.0-9a-zA-z]*"' src 336 exit 1 337 fi 338 '' 339 # Finally, patch shebangs in scripts used at build time. This must not patch 340 # scripts that will end up in the output, to avoid build platform references 341 # when cross-compiling. 342 + '' 343 shopt -s extglob 344 patchShebangs tools test src/!(rpm) 345 ''; 346 347 outputs = [ "out" "man" "dev" ]; 348 349 nativeBuildInputs = 350 [ 351 pkg-config 352 makeBinaryWrapper 353 gperf 354 ninja 355 meson 356 glibcLocales 357 getent 358 m4 359 360 intltool 361 gettext 362 363 libxslt 364 docbook_xsl 365 docbook_xml_dtd_42 366 docbook_xml_dtd_45 367 (buildPackages.python3Packages.python.withPackages (ps: with ps; [ lxml jinja2 ])) 368 ] 369 ++ lib.optionals withLibBPF [ 370 bpftools 371 llvmPackages.clang 372 llvmPackages.libllvm 373 ] 374 ; 375 376 buildInputs = 377 [ 378 acl 379 audit 380 kmod 381 libxcrypt 382 libcap 383 libidn2 384 libuuid 385 linuxHeaders 386 pam 387 ] 388 389 ++ lib.optional wantGcrypt libgcrypt 390 ++ lib.optional withTests glib 391 ++ lib.optional withApparmor libapparmor 392 ++ lib.optional wantCurl (lib.getDev curl) 393 ++ lib.optionals withCompression [ bzip2 lz4 xz zstd ] 394 ++ lib.optional withCoredump elfutils 395 ++ lib.optional withCryptsetup (lib.getDev cryptsetup.dev) 396 ++ lib.optional withEfi gnu-efi 397 ++ lib.optional withKexectools kexec-tools 398 ++ lib.optional withLibseccomp libseccomp 399 ++ lib.optional withNetworkd iptables 400 ++ lib.optional withPCRE2 pcre2 401 ++ lib.optional withResolved libgpg-error 402 ++ lib.optional withSelinux libselinux 403 ++ lib.optional withRemote libmicrohttpd 404 ++ lib.optionals withHomed [ p11-kit ] 405 ++ lib.optionals (withHomed || withCryptsetup) [ libfido2 ] 406 ++ lib.optionals withLibBPF [ libbpf ] 407 ++ lib.optional withTpm2Tss tpm2-tss 408 ; 409 410 #dontAddPrefix = true; 411 412 mesonFlags = [ 413 "-Dversion-tag=${version}" 414 # We bump this variable on every (major) version change to ensure 415 # that we have known-good value for a timestamp that is in the (not so distant) past. 416 # This serves as a lower bound for valid system timestamps during startup. Systemd will 417 # reset the system timestamp if this date is +- 15 years from the system time. 418 # See the systemd v250 release notes for further details: 419 # https://github.com/systemd/systemd/blob/60e930fc3e6eb8a36fbc184773119eb8d2f30364/NEWS#L258-L266 420 "-Dtime-epoch=${releaseTimestamp}" 421 422 "-Dmode=release" 423 "-Ddbuspolicydir=${placeholder "out"}/share/dbus-1/system.d" 424 "-Ddbussessionservicedir=${placeholder "out"}/share/dbus-1/services" 425 "-Ddbussystemservicedir=${placeholder "out"}/share/dbus-1/system-services" 426 "-Dpamconfdir=${placeholder "out"}/etc/pam.d" 427 "-Drootprefix=${placeholder "out"}" 428 "-Dpkgconfiglibdir=${placeholder "dev"}/lib/pkgconfig" 429 "-Dpkgconfigdatadir=${placeholder "dev"}/share/pkgconfig" 430 "-Dloadkeys-path=${kbd}/bin/loadkeys" 431 "-Dsetfont-path=${kbd}/bin/setfont" 432 "-Dtty-gid=3" # tty in NixOS has gid 3 433 "-Ddebug-shell=${bashInteractive}/bin/bash" 434 "-Dglib=${lib.boolToString withTests}" 435 # while we do not run tests we should also not build them. Removes about 600 targets 436 "-Dtests=false" 437 "-Danalyze=${lib.boolToString withAnalyze}" 438 "-Dgcrypt=${lib.boolToString wantGcrypt}" 439 "-Dimportd=${lib.boolToString withImportd}" 440 "-Dlz4=${lib.boolToString withCompression}" 441 "-Dhomed=${lib.boolToString withHomed}" 442 "-Dlogind=${lib.boolToString withLogind}" 443 "-Dlocaled=${lib.boolToString withLocaled}" 444 "-Dhostnamed=${lib.boolToString withHostnamed}" 445 "-Dmachined=${lib.boolToString withMachined}" 446 "-Dnetworkd=${lib.boolToString withNetworkd}" 447 "-Doomd=${lib.boolToString withOomd}" 448 "-Dpolkit=${lib.boolToString withPolkit}" 449 "-Dlibcryptsetup=${lib.boolToString withCryptsetup}" 450 "-Dportabled=${lib.boolToString withPortabled}" 451 "-Dhwdb=${lib.boolToString withHwdb}" 452 "-Dremote=${lib.boolToString withRemote}" 453 "-Dsysusers=false" 454 "-Dtimedated=${lib.boolToString withTimedated}" 455 "-Dtimesyncd=${lib.boolToString withTimesyncd}" 456 "-Duserdb=${lib.boolToString withUserDb}" 457 "-Dcoredump=${lib.boolToString withCoredump}" 458 "-Dfirstboot=false" 459 "-Dresolve=${lib.boolToString withResolved}" 460 "-Dsplit-usr=false" 461 "-Dlibcurl=${lib.boolToString wantCurl}" 462 "-Dlibidn=false" 463 "-Dlibidn2=true" 464 "-Dquotacheck=false" 465 "-Dldconfig=false" 466 "-Dsmack=true" 467 "-Db_pie=true" 468 "-Dinstall-sysconfdir=false" 469 "-Dsbat-distro=nixos" 470 "-Dsbat-distro-summary=NixOS" 471 "-Dsbat-distro-url=https://nixos.org/" 472 "-Dsbat-distro-pkgname=${pname}" 473 "-Dsbat-distro-version=${version}" 474 /* 475 As of now, systemd doesn't allow runtime configuration of these values. So 476 the settings in /etc/login.defs have no effect on it. Many people think this 477 should be supported however, see 478 - https://github.com/systemd/systemd/issues/3855 479 - https://github.com/systemd/systemd/issues/4850 480 - https://github.com/systemd/systemd/issues/9769 481 - https://github.com/systemd/systemd/issues/9843 482 - https://github.com/systemd/systemd/issues/10184 483 */ 484 "-Dsystem-uid-max=999" 485 "-Dsystem-gid-max=999" 486 487 "-Dsysvinit-path=" 488 "-Dsysvrcnd-path=" 489 490 "-Dkmod-path=${kmod}/bin/kmod" 491 "-Dsulogin-path=${util-linux}/bin/sulogin" 492 "-Dmount-path=${util-linux}/bin/mount" 493 "-Dumount-path=${util-linux}/bin/umount" 494 "-Dcreate-log-dirs=false" 495 496 # Use cgroupsv2. This is already the upstream default, but better be explicit. 497 "-Ddefault-hierarchy=unified" 498 # Upstream defaulted to disable manpages since they optimize for the much 499 # more frequent development builds 500 "-Dman=true" 501 502 "-Defi=${lib.boolToString withEfi}" 503 "-Dgnu-efi=${lib.boolToString withEfi}" 504 ] ++ lib.optionals withEfi [ 505 "-Defi-libdir=${toString gnu-efi}/lib" 506 "-Defi-includedir=${toString gnu-efi}/include/efi" 507 ] ++ lib.optionals (withShellCompletions == false) [ 508 "-Dbashcompletiondir=no" 509 "-Dzshcompletiondir=no" 510 ] ++ lib.optionals (!withNss) [ 511 "-Dnss-myhostname=false" 512 "-Dnss-mymachines=false" 513 "-Dnss-resolve=false" 514 "-Dnss-systemd=false" 515 ] ++ lib.optionals withLibBPF [ 516 "-Dbpf-framework=true" 517 ] ++ lib.optionals withTpm2Tss [ 518 "-Dtpm2=true" 519 ] ++ lib.optionals (!withUtmp) [ 520 "-Dutmp=false" 521 ] ++ lib.optionals stdenv.hostPlatform.isMusl [ 522 "-Dgshadow=false" 523 "-Didn=false" 524 ]; 525 preConfigure = 526 let 527 # A list of all the runtime binaries that the systemd executables, tests and libraries are referencing in their source code, scripts and unit files. 528 # As soon as a dependency isn't required anymore we should remove it from the list. The `where` attribute for each of the replacement patterns must be exhaustive. If another (unhandled) case is found in the source code the build fails with an error message. 529 binaryReplacements = [ 530 { search = "/usr/bin/getent"; replacement = "${getent}/bin/getent"; where = [ "src/nspawn/nspawn-setuid.c" ]; } 531 532 { 533 search = "/sbin/mkswap"; 534 replacement = "${lib.getBin util-linux}/sbin/mkswap"; 535 where = [ 536 "man/systemd-makefs@.service.xml" 537 ]; 538 } 539 { search = "/sbin/swapon"; replacement = "${lib.getBin util-linux}/sbin/swapon"; where = [ "src/core/swap.c" "src/basic/unit-def.h" ]; } 540 { search = "/sbin/swapoff"; replacement = "${lib.getBin util-linux}/sbin/swapoff"; where = [ "src/core/swap.c" ]; } 541 { 542 search = "/bin/echo"; 543 replacement = "${coreutils}/bin/echo"; 544 where = [ 545 "man/systemd-analyze.xml" 546 "man/systemd.service.xml" 547 "src/analyze/test-verify.c" 548 "src/test/test-env-file.c" 549 "src/test/test-fileio.c" 550 "src/test/test-load-fragment.c" 551 ]; 552 } 553 { 554 search = "/bin/cat"; 555 replacement = "${coreutils}/bin/cat"; 556 where = [ "test/create-busybox-container" "test/test-execute/exec-noexecpaths-simple.service" "src/journal/cat.c" ]; 557 } 558 { search = "/sbin/modprobe"; replacement = "${lib.getBin kmod}/sbin/modprobe"; where = [ "units/modprobe@.service" ]; } 559 { 560 search = "/usr/lib/systemd/systemd-fsck"; 561 replacement = "$out/lib/systemd/systemd-fsck"; 562 where = [ 563 "man/systemd-fsck@.service.xml" 564 ]; 565 } 566 ] ++ lib.optionals withImportd [ 567 { 568 search = "\"gpg\""; 569 replacement = "\\\"${gnupg}/bin/gpg\\\""; 570 where = [ "src/import/pull-common.c" ]; 571 } 572 { 573 search = "\"tar\""; 574 replacement = "\\\"${gnutar}/bin/tar\\\""; 575 where = [ 576 "src/import/export-tar.c" 577 "src/import/import-common.c" 578 "src/import/import-tar.c" 579 ]; 580 ignore = [ 581 # occurrences here refer to the tar sub command 582 "src/sysupdate/sysupdate-resource.c" 583 "src/sysupdate/sysupdate-transfer.c" 584 "src/import/pull.c" 585 "src/import/export.c" 586 "src/import/import.c" 587 "src/import/importd.c" 588 # runs `tar` but also also creates a temporary directory with the string 589 "src/import/pull-tar.c" 590 ]; 591 } 592 ]; 593 594 # { replacement, search, where } -> List[str] 595 mkSubstitute = { replacement, search, where, ignore ? [ ] }: 596 map (path: "substituteInPlace ${path} --replace '${search}' \"${replacement}\"") where; 597 mkEnsureSubstituted = { replacement, search, where, ignore ? [ ] }: 598 let 599 ignore' = lib.concatStringsSep "|" (ignore ++ [ "^test" "NEWS" ]); 600 in 601 '' 602 set +e 603 search=$(grep '${search}' -r | grep -v "${replacement}" | grep -Ev "${ignore'}") 604 set -e 605 if [[ -n "$search" ]]; then 606 echo "Not all references to '${search}' have been replaced. Found the following matches:" 607 echo "$search" 608 exit 1 609 fi 610 ''; 611 in 612 '' 613 mesonFlagsArray+=(-Dntp-servers="0.nixos.pool.ntp.org 1.nixos.pool.ntp.org 2.nixos.pool.ntp.org 3.nixos.pool.ntp.org") 614 export LC_ALL="en_US.UTF-8"; 615 616 ${lib.concatStringsSep "\n" (lib.flatten (map mkSubstitute binaryReplacements))} 617 ${lib.concatMapStringsSep "\n" mkEnsureSubstituted binaryReplacements} 618 619 substituteInPlace src/libsystemd/sd-journal/catalog.c \ 620 --replace /usr/lib/systemd/catalog/ $out/lib/systemd/catalog/ 621 622 substituteInPlace src/import/pull-tar.c \ 623 --replace 'wait_for_terminate_and_check("tar"' 'wait_for_terminate_and_check("${gnutar}/bin/tar"' 624 ''; 625 626 # These defines are overridden by CFLAGS and would trigger annoying 627 # warning messages 628 postConfigure = '' 629 substituteInPlace config.h \ 630 --replace "POLKIT_AGENT_BINARY_PATH" "_POLKIT_AGENT_BINARY_PATH" \ 631 --replace "SYSTEMD_BINARY_PATH" "_SYSTEMD_BINARY_PATH" \ 632 --replace "SYSTEMD_CGROUP_AGENTS_PATH" "_SYSTEMD_CGROUP_AGENT_PATH" 633 ''; 634 635 NIX_CFLAGS_COMPILE = toString ([ 636 # Can't say ${polkit.bin}/bin/pkttyagent here because that would 637 # lead to a cyclic dependency. 638 "-UPOLKIT_AGENT_BINARY_PATH" 639 "-DPOLKIT_AGENT_BINARY_PATH=\"/run/current-system/sw/bin/pkttyagent\"" 640 641 # Set the release_agent on /sys/fs/cgroup/systemd to the 642 # currently running systemd (/run/current-system/systemd) so 643 # that we don't use an obsolete/garbage-collected release agent. 644 "-USYSTEMD_CGROUP_AGENTS_PATH" 645 "-DSYSTEMD_CGROUP_AGENTS_PATH=\"/run/current-system/systemd/lib/systemd/systemd-cgroups-agent\"" 646 647 "-USYSTEMD_BINARY_PATH" 648 "-DSYSTEMD_BINARY_PATH=\"/run/current-system/systemd/lib/systemd/systemd\"" 649 650 ] ++ lib.optionals stdenv.hostPlatform.isMusl [ 651 "-D__UAPI_DEF_ETHHDR=0" 652 ]); 653 654 doCheck = false; # fails a bunch of tests 655 656 # trigger the test -n "$DESTDIR" || mutate in upstreams build system 657 preInstall = '' 658 export DESTDIR=/ 659 ''; 660 661 postInstall = '' 662 mkdir -p $out/example/systemd 663 mv $out/lib/{modules-load.d,binfmt.d,sysctl.d,tmpfiles.d} $out/example 664 mv $out/lib/systemd/{system,user} $out/example/systemd 665 666 rm -rf $out/etc/systemd/system 667 668 # Fix reference to /bin/false in the D-Bus services. 669 for i in $out/share/dbus-1/system-services/*.service; do 670 substituteInPlace $i --replace /bin/false ${coreutils}/bin/false 671 done 672 673 rm -rf $out/etc/rpm 674 675 # "kernel-install" shouldn't be used on NixOS. 676 find $out -name "*kernel-install*" -exec rm {} \; 677 '' + lib.optionalString (!withDocumentation) '' 678 rm -rf $out/share/doc 679 ''; 680 681 # Avoid *.EFI binary stripping. At least on aarch64-linux strip 682 # removes too much from PE32+ files: 683 # https://github.com/NixOS/nixpkgs/issues/169693 684 # The hack is to move EFI file out of lib/ before doStrip 685 # run and return it after doStrip run. 686 preFixup = lib.optionalString withEfi '' 687 mv $out/lib/systemd/boot/efi $out/dont-strip-me 688 ''; 689 690 # Wrap in the correct path for LUKS2 tokens. 691 postFixup = lib.optionalString withCryptsetup '' 692 for f in lib/systemd/systemd-cryptsetup bin/systemd-cryptenroll; do 693 # This needs to be in LD_LIBRARY_PATH because rpath on a binary is not propagated to libraries using dlopen, in this case `libcryptsetup.so` 694 wrapProgram $out/$f --prefix LD_LIBRARY_PATH : ${placeholder "out"}/lib/cryptsetup 695 done 696 '' + lib.optionalString withEfi '' 697 mv $out/dont-strip-me $out/lib/systemd/boot/efi 698 ''; 699 700 passthru = { 701 # The interface version prevents NixOS from switching to an 702 # incompatible systemd at runtime. (Switching across reboots is 703 # fine, of course.) It should be increased whenever systemd changes 704 # in a backwards-incompatible way. If the interface version of two 705 # systemd builds is the same, then we can switch between them at 706 # runtime; otherwise we can't and we need to reboot. 707 interfaceVersion = 2; 708 709 inherit withCryptsetup withHostnamed withImportd withLocaled withMachined withPortabled withTimedated withUtmp util-linux kmod kbd; 710 711 tests = { 712 inherit (nixosTests) switchTest; 713 }; 714 }; 715 716 meta = with lib; { 717 homepage = "https://www.freedesktop.org/wiki/Software/systemd/"; 718 description = "A system and service manager for Linux"; 719 license = licenses.lgpl21Plus; 720 platforms = platforms.linux; 721 # https://github.com/systemd/systemd/issues/20600#issuecomment-912338965 722 broken = stdenv.hostPlatform.isStatic; 723 priority = 10; 724 maintainers = with maintainers; [ flokli kloenk mic92 ]; 725 }; 726}