2447ac6006c5419d6bdb679771c9c7e9cf9e586d
[gentoo.git] / sys-apps / systemd / systemd-243-r2.ebuild
1 # Copyright 2011-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 if [[ ${PV} == 9999 ]]; then
7         EGIT_REPO_URI="https://github.com/systemd/systemd.git"
8         inherit git-r3
9 else
10         MY_PV=${PV/_/-}
11         MY_P=${PN}-${MY_PV}
12         S=${WORKDIR}/${MY_P}
13         SRC_URI="https://github.com/systemd/systemd/archive/v${MY_PV}/${MY_P}.tar.gz"
14         KEYWORDS="alpha amd64 arm arm64 ~hppa ia64 ~mips ppc ppc64 sparc x86"
15 fi
16
17 PYTHON_COMPAT=( python{3_6,3_7} )
18
19 inherit bash-completion-r1 linux-info meson multilib-minimal ninja-utils pam python-any-r1 systemd toolchain-funcs udev usr-ldscript
20
21 DESCRIPTION="System and service manager for Linux"
22 HOMEPAGE="https://www.freedesktop.org/wiki/Software/systemd"
23
24 LICENSE="GPL-2 LGPL-2.1 MIT public-domain"
25 SLOT="0/2"
26 IUSE="acl apparmor audit build cgroup-hybrid cryptsetup curl dns-over-tls elfutils +gcrypt gnuefi http idn importd +kmod +lz4 lzma nat pam pcre policykit qrcode +resolvconf +seccomp selinux split-usr static-libs +sysv-utils test vanilla xkb"
27
28 REQUIRED_USE="importd? ( curl gcrypt lzma )"
29 RESTRICT="!test? ( test )"
30
31 MINKV="3.11"
32
33 COMMON_DEPEND=">=sys-apps/util-linux-2.30:0=[${MULTILIB_USEDEP}]
34         sys-libs/libcap:0=[${MULTILIB_USEDEP}]
35         !<sys-libs/glibc-2.16
36         acl? ( sys-apps/acl:0= )
37         apparmor? ( sys-libs/libapparmor:0= )
38         audit? ( >=sys-process/audit-2:0= )
39         cryptsetup? ( >=sys-fs/cryptsetup-1.6:0= )
40         curl? ( net-misc/curl:0= )
41         dns-over-tls? ( >=net-libs/gnutls-3.5.3:0= )
42         elfutils? ( >=dev-libs/elfutils-0.158:0= )
43         gcrypt? ( >=dev-libs/libgcrypt-1.4.5:0=[${MULTILIB_USEDEP}] )
44         http? (
45                 >=net-libs/libmicrohttpd-0.9.33:0=[epoll(+)]
46                 >=net-libs/gnutls-3.1.4:0=
47         )
48         idn? ( net-dns/libidn2:= )
49         importd? (
50                 app-arch/bzip2:0=
51                 sys-libs/zlib:0=
52         )
53         kmod? ( >=sys-apps/kmod-15:0= )
54         lz4? ( >=app-arch/lz4-0_p131:0=[${MULTILIB_USEDEP}] )
55         lzma? ( >=app-arch/xz-utils-5.0.5-r1:0=[${MULTILIB_USEDEP}] )
56         nat? ( net-firewall/iptables:0= )
57         pam? ( sys-libs/pam:=[${MULTILIB_USEDEP}] )
58         pcre? ( dev-libs/libpcre2 )
59         qrcode? ( media-gfx/qrencode:0= )
60         seccomp? ( >=sys-libs/libseccomp-2.3.3:0= )
61         selinux? ( sys-libs/libselinux:0= )
62         xkb? ( >=x11-libs/libxkbcommon-0.4.1:0= )"
63
64 # Newer linux-headers needed by ia64, bug #480218
65 DEPEND="${COMMON_DEPEND}
66         >=sys-kernel/linux-headers-${MINKV}
67         gnuefi? ( >=sys-boot/gnu-efi-3.0.2 )
68 "
69
70 # baselayout-2.2 has /run
71 RDEPEND="${COMMON_DEPEND}
72         acct-group/adm
73         acct-group/wheel
74         acct-group/kmem
75         acct-group/tty
76         acct-group/utmp
77         acct-group/audio
78         acct-group/cdrom
79         acct-group/dialout
80         acct-group/disk
81         acct-group/input
82         acct-group/kvm
83         acct-group/render
84         acct-group/tape
85         acct-group/video
86         acct-group/systemd-journal
87         acct-user/systemd-journal-remote
88         acct-user/systemd-coredump
89         acct-user/systemd-network
90         acct-user/systemd-resolve
91         acct-user/systemd-timesync
92         >=sys-apps/baselayout-2.2
93         selinux? ( sec-policy/selinux-base-policy[systemd] )
94         sysv-utils? ( !sys-apps/sysvinit )
95         !sysv-utils? ( sys-apps/sysvinit )
96         resolvconf? ( !net-dns/openresolv )
97         !build? ( || (
98                 sys-apps/util-linux[kill(-)]
99                 sys-process/procps[kill(+)]
100                 sys-apps/coreutils[kill(-)]
101         ) )
102         !sys-auth/nss-myhostname
103         !<sys-kernel/dracut-044
104         !sys-fs/eudev
105         !sys-fs/udev
106 "
107
108 # sys-apps/dbus: the daemon only (+ build-time lib dep for tests)
109 PDEPEND=">=sys-apps/dbus-1.9.8[systemd]
110         >=sys-apps/hwids-20150417[udev]
111         >=sys-fs/udev-init-scripts-25
112         policykit? ( sys-auth/polkit )
113         !vanilla? ( sys-apps/gentoo-systemd-integration )"
114
115 BDEPEND="
116         app-arch/xz-utils:0
117         dev-util/gperf
118         >=dev-util/meson-0.46
119         >=dev-util/intltool-0.50
120         >=sys-apps/coreutils-8.16
121         sys-devel/m4
122         virtual/pkgconfig[${MULTILIB_USEDEP}]
123         test? ( sys-apps/dbus )
124         app-text/docbook-xml-dtd:4.2
125         app-text/docbook-xml-dtd:4.5
126         app-text/docbook-xsl-stylesheets
127         dev-libs/libxslt:0
128         $(python_gen_any_dep 'dev-python/lxml[${PYTHON_USEDEP}]')
129 "
130
131 pkg_pretend() {
132         if [[ ${MERGE_TYPE} != buildonly ]]; then
133                 if use test && has pid-sandbox ${FEATURES}; then
134                         ewarn "Tests are known to fail with PID sandboxing enabled."
135                         ewarn "See https://bugs.gentoo.org/674458."
136                 fi
137
138                 local CONFIG_CHECK="~AUTOFS4_FS ~BLK_DEV_BSG ~CGROUPS
139                         ~CHECKPOINT_RESTORE ~DEVTMPFS ~EPOLL ~FANOTIFY ~FHANDLE
140                         ~INOTIFY_USER ~IPV6 ~NET ~NET_NS ~PROC_FS ~SIGNALFD ~SYSFS
141                         ~TIMERFD ~TMPFS_XATTR ~UNIX
142                         ~CRYPTO_HMAC ~CRYPTO_SHA256 ~CRYPTO_USER_API_HASH
143                         ~!FW_LOADER_USER_HELPER_FALLBACK ~!GRKERNSEC_PROC ~!IDE ~!SYSFS_DEPRECATED
144                         ~!SYSFS_DEPRECATED_V2"
145
146                 use acl && CONFIG_CHECK+=" ~TMPFS_POSIX_ACL"
147                 use seccomp && CONFIG_CHECK+=" ~SECCOMP ~SECCOMP_FILTER"
148                 kernel_is -lt 3 7 && CONFIG_CHECK+=" ~HOTPLUG"
149                 kernel_is -lt 4 7 && CONFIG_CHECK+=" ~DEVPTS_MULTIPLE_INSTANCES"
150                 kernel_is -ge 4 10 && CONFIG_CHECK+=" ~CGROUP_BPF"
151
152                 if linux_config_exists; then
153                         local uevent_helper_path=$(linux_chkconfig_string UEVENT_HELPER_PATH)
154                         if [[ -n ${uevent_helper_path} ]] && [[ ${uevent_helper_path} != '""' ]]; then
155                                 ewarn "It's recommended to set an empty value to the following kernel config option:"
156                                 ewarn "CONFIG_UEVENT_HELPER_PATH=${uevent_helper_path}"
157                         fi
158                         if linux_chkconfig_present X86; then
159                                 CONFIG_CHECK+=" ~DMIID"
160                         fi
161                 fi
162
163                 if kernel_is -lt ${MINKV//./ }; then
164                         ewarn "Kernel version at least ${MINKV} required"
165                 fi
166
167                 check_extra_config
168         fi
169 }
170
171 pkg_setup() {
172         :
173 }
174
175 src_unpack() {
176         default
177         [[ ${PV} != 9999 ]] || git-r3_src_unpack
178 }
179
180 src_prepare() {
181         # Do NOT add patches here
182         local PATCHES=()
183
184         [[ -d "${WORKDIR}"/patches ]] && PATCHES+=( "${WORKDIR}"/patches )
185
186         # Add local patches here
187         PATCHES+=(
188                 "${FILESDIR}/243-seccomp.patch"
189         )
190
191         if ! use vanilla; then
192                 PATCHES+=(
193                         "${FILESDIR}/gentoo-Dont-enable-audit-by-default.patch"
194                         "${FILESDIR}/gentoo-systemd-user-pam.patch"
195                         "${FILESDIR}/gentoo-generator-path-r1.patch"
196                 )
197         fi
198
199         default
200 }
201
202 src_configure() {
203         # Prevent conflicts with i686 cross toolchain, bug 559726
204         tc-export AR CC NM OBJCOPY RANLIB
205
206         python_setup
207
208         multilib-minimal_src_configure
209 }
210
211 meson_use() {
212         usex "$1" true false
213 }
214
215 meson_multilib() {
216         if multilib_is_native_abi; then
217                 echo true
218         else
219                 echo false
220         fi
221 }
222
223 meson_multilib_native_use() {
224         if multilib_is_native_abi && use "$1"; then
225                 echo true
226         else
227                 echo false
228         fi
229 }
230
231 multilib_src_configure() {
232         local myconf=(
233                 --localstatedir="${EPREFIX}/var"
234                 -Dsupport-url="https://gentoo.org/support/"
235                 -Dpamlibdir="$(getpam_mod_dir)"
236                 # avoid bash-completion dep
237                 -Dbashcompletiondir="$(get_bashcompdir)"
238                 # make sure we get /bin:/sbin in PATH
239                 -Dsplit-usr=$(usex split-usr true false)
240                 -Drootprefix="$(usex split-usr "${EPREFIX:-/}" "${EPREFIX}/usr")"
241                 -Drootlibdir="${EPREFIX}/usr/$(get_libdir)"
242                 -Dsysvinit-path=
243                 -Dsysvrcnd-path=
244                 # Avoid infinite exec recursion, bug 642724
245                 -Dtelinit-path="${EPREFIX}/lib/sysvinit/telinit"
246                 # no deps
247                 -Defi=$(meson_multilib)
248                 -Dima=true
249                 -Ddefault-hierarchy=$(usex cgroup-hybrid hybrid unified)
250                 # Optional components/dependencies
251                 -Dacl=$(meson_multilib_native_use acl)
252                 -Dapparmor=$(meson_multilib_native_use apparmor)
253                 -Daudit=$(meson_multilib_native_use audit)
254                 -Dlibcryptsetup=$(meson_multilib_native_use cryptsetup)
255                 -Dlibcurl=$(meson_multilib_native_use curl)
256                 -Ddns-over-tls=$(meson_multilib_native_use dns-over-tls)
257                 -Delfutils=$(meson_multilib_native_use elfutils)
258                 -Dgcrypt=$(meson_use gcrypt)
259                 -Dgnu-efi=$(meson_multilib_native_use gnuefi)
260                 -Defi-libdir="${ESYSROOT}/usr/$(get_libdir)"
261                 -Dmicrohttpd=$(meson_multilib_native_use http)
262                 -Didn=$(meson_multilib_native_use idn)
263                 -Dimportd=$(meson_multilib_native_use importd)
264                 -Dbzip2=$(meson_multilib_native_use importd)
265                 -Dzlib=$(meson_multilib_native_use importd)
266                 -Dkmod=$(meson_multilib_native_use kmod)
267                 -Dlz4=$(meson_use lz4)
268                 -Dxz=$(meson_use lzma)
269                 -Dlibiptc=$(meson_multilib_native_use nat)
270                 -Dpam=$(meson_use pam)
271                 -Dpcre2=$(meson_multilib_native_use pcre)
272                 -Dpolkit=$(meson_multilib_native_use policykit)
273                 -Dqrencode=$(meson_multilib_native_use qrcode)
274                 -Dseccomp=$(meson_multilib_native_use seccomp)
275                 -Dselinux=$(meson_multilib_native_use selinux)
276                 -Ddbus=$(meson_multilib_native_use test)
277                 -Dxkbcommon=$(meson_multilib_native_use xkb)
278                 -Dntp-servers="0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org 2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org"
279                 # Breaks screen, tmux, etc.
280                 -Ddefault-kill-user-processes=false
281                 -Dcreate-log-dirs=false
282
283                 # multilib options
284                 -Dbacklight=$(meson_multilib)
285                 -Dbinfmt=$(meson_multilib)
286                 -Dcoredump=$(meson_multilib)
287                 -Denvironment-d=$(meson_multilib)
288                 -Dfirstboot=$(meson_multilib)
289                 -Dhibernate=$(meson_multilib)
290                 -Dhostnamed=$(meson_multilib)
291                 -Dhwdb=$(meson_multilib)
292                 -Dldconfig=$(meson_multilib)
293                 -Dlocaled=$(meson_multilib)
294                 -Dman=$(meson_multilib)
295                 -Dnetworkd=$(meson_multilib)
296                 -Dquotacheck=$(meson_multilib)
297                 -Drandomseed=$(meson_multilib)
298                 -Drfkill=$(meson_multilib)
299                 -Dsysusers=$(meson_multilib)
300                 -Dtimedated=$(meson_multilib)
301                 -Dtimesyncd=$(meson_multilib)
302                 -Dtmpfiles=$(meson_multilib)
303                 -Dvconsole=$(meson_multilib)
304
305                 # static-libs
306                 -Dstatic-libsystemd=$(usex static-libs true false)
307                 -Dstatic-libudev=$(usex static-libs true false)
308         )
309
310         meson_src_configure "${myconf[@]}"
311 }
312
313 multilib_src_compile() {
314         eninja
315 }
316
317 multilib_src_test() {
318         unset DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR
319         meson_src_test
320 }
321
322 multilib_src_install() {
323         DESTDIR="${D}" eninja install
324 }
325
326 multilib_src_install_all() {
327         local rootprefix=$(usex split-usr '' /usr)
328
329         # meson doesn't know about docdir
330         mv "${ED}"/usr/share/doc/{systemd,${PF}} || die
331
332         einstalldocs
333         dodoc "${FILESDIR}"/nsswitch.conf
334
335         if ! use resolvconf; then
336                 rm -f "${ED}${rootprefix}"/sbin/resolvconf || die
337         fi
338
339         if ! use sysv-utils; then
340                 rm "${ED}${rootprefix}"/sbin/{halt,init,poweroff,reboot,runlevel,shutdown,telinit} || die
341                 rm "${ED}"/usr/share/man/man1/init.1 || die
342                 rm "${ED}"/usr/share/man/man8/{halt,poweroff,reboot,runlevel,shutdown,telinit}.8 || die
343         fi
344
345         if ! use resolvconf && ! use sysv-utils; then
346                 rmdir "${ED}${rootprefix}"/sbin || die
347         fi
348
349         # Preserve empty dirs in /etc & /var, bug #437008
350         keepdir /etc/{binfmt.d,modules-load.d,tmpfiles.d}
351         keepdir /etc/kernel/install.d
352         keepdir /etc/systemd/{network,system,user}
353         keepdir /etc/udev/{hwdb.d,rules.d}
354         keepdir "${rootprefix}"/lib/systemd/{system-sleep,system-shutdown}
355         keepdir /usr/lib/{binfmt.d,modules-load.d}
356         keepdir /usr/lib/systemd/user-generators
357         keepdir /var/lib/systemd
358         keepdir /var/log/journal
359
360         # Symlink /etc/sysctl.conf for easy migration.
361         dosym ../sysctl.conf /etc/sysctl.d/99-sysctl.conf
362
363         rm -r "${ED}${rootprefix}"/lib/udev/hwdb.d || die
364
365         if use split-usr; then
366                 # Avoid breaking boot/reboot
367                 dosym ../../../lib/systemd/systemd /usr/lib/systemd/systemd
368                 dosym ../../../lib/systemd/systemd-shutdown /usr/lib/systemd/systemd-shutdown
369         fi
370
371         gen_usr_ldscript -a systemd udev
372 }
373
374 migrate_locale() {
375         local envd_locale_def="${EROOT}/etc/env.d/02locale"
376         local envd_locale=( "${EROOT}"/etc/env.d/??locale )
377         local locale_conf="${EROOT}/etc/locale.conf"
378
379         if [[ ! -L ${locale_conf} && ! -e ${locale_conf} ]]; then
380                 # If locale.conf does not exist...
381                 if [[ -e ${envd_locale} ]]; then
382                         # ...either copy env.d/??locale if there's one
383                         ebegin "Moving ${envd_locale} to ${locale_conf}"
384                         mv "${envd_locale}" "${locale_conf}"
385                         eend ${?} || FAIL=1
386                 else
387                         # ...or create a dummy default
388                         ebegin "Creating ${locale_conf}"
389                         cat > "${locale_conf}" <<-EOF
390                                 # This file has been created by the sys-apps/systemd ebuild.
391                                 # See locale.conf(5) and localectl(1).
392
393                                 # LANG=${LANG}
394                         EOF
395                         eend ${?} || FAIL=1
396                 fi
397         fi
398
399         if [[ ! -L ${envd_locale} ]]; then
400                 # now, if env.d/??locale is not a symlink (to locale.conf)...
401                 if [[ -e ${envd_locale} ]]; then
402                         # ...warn the user that he has duplicate locale settings
403                         ewarn
404                         ewarn "To ensure consistent behavior, you should replace ${envd_locale}"
405                         ewarn "with a symlink to ${locale_conf}. Please migrate your settings"
406                         ewarn "and create the symlink with the following command:"
407                         ewarn "ln -s -n -f ../locale.conf ${envd_locale}"
408                         ewarn
409                 else
410                         # ...or just create the symlink if there's nothing here
411                         ebegin "Creating ${envd_locale_def} -> ../locale.conf symlink"
412                         ln -n -s ../locale.conf "${envd_locale_def}"
413                         eend ${?} || FAIL=1
414                 fi
415         fi
416 }
417
418 save_enabled_units() {
419         ENABLED_UNITS=()
420         type systemctl &>/dev/null || return
421         for x; do
422                 if systemctl --quiet --root="${ROOT:-/}" is-enabled "${x}"; then
423                         ENABLED_UNITS+=( "${x}" )
424                 fi
425         done
426 }
427
428 pkg_preinst() {
429         save_enabled_units {machines,remote-{cryptsetup,fs}}.target getty@tty1.service
430
431         if ! use split-usr; then
432                 local dir
433                 for dir in bin sbin lib; do
434                         if [[ ! ${EROOT}/${dir} -ef ${EROOT}/usr/${dir} ]]; then
435                                 eerror "\"${EROOT}/${dir}\" and \"${EROOT}/usr/${dir}\" are not merged."
436                                 eerror "One of them should be a symbolic link to the other one."
437                                 FAIL=1
438                         fi
439                 done
440                 if [[ ${FAIL} ]]; then
441                         eerror "Migration to system layout with merged directories must be performed before"
442                         eerror "rebuilding ${CATEGORY}/${PN} with USE=\"-split-usr\" to avoid run-time breakage."
443                         die "System layout with split directories still used"
444                 fi
445         fi
446 }
447
448 pkg_postinst() {
449         systemd_update_catalog
450
451         # Keep this here in case the database format changes so it gets updated
452         # when required. Despite that this file is owned by sys-apps/hwids.
453         if has_version "sys-apps/hwids[udev]"; then
454                 udevadm hwdb --update --root="${EROOT}"
455         fi
456
457         udev_reload || FAIL=1
458
459         # Bug 465468, make sure locales are respect, and ensure consistency
460         # between OpenRC & systemd
461         migrate_locale
462
463         systemd_reenable systemd-networkd.service systemd-resolved.service
464
465         if [[ ${ENABLED_UNITS[@]} ]]; then
466                 systemctl --root="${ROOT:-/}" enable "${ENABLED_UNITS[@]}"
467         fi
468
469         if [[ -z ${REPLACING_VERSIONS} ]]; then
470                 if type systemctl &>/dev/null; then
471                         systemctl --root="${ROOT:-/}" enable getty@.service remote-fs.target || FAIL=1
472                 fi
473                 elog "To enable a useful set of services, run the following:"
474                 elog "  systemctl preset-all --preset-mode=enable-only"
475         fi
476
477         if [[ -L ${EROOT}/var/lib/systemd/timesync ]]; then
478                 rm "${EROOT}/var/lib/systemd/timesync"
479         fi
480
481         if [[ -z ${ROOT} && -d /run/systemd/system ]]; then
482                 ebegin "Reexecuting system manager"
483                 systemctl daemon-reexec
484                 eend $?
485         fi
486
487         if [[ ${FAIL} ]]; then
488                 eerror "One of the postinst commands failed. Please check the postinst output"
489                 eerror "for errors. You may need to clean up your system and/or try installing"
490                 eerror "systemd again."
491                 eerror
492         fi
493 }
494
495 pkg_prerm() {
496         # If removing systemd completely, remove the catalog database.
497         if [[ ! ${REPLACED_BY_VERSION} ]]; then
498                 rm -f -v "${EROOT}"/var/lib/systemd/catalog/database
499         fi
500 }