From 6495361c7d5e8bf640841d1292ef6cfe1ea244cf Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 21 Aug 2023 12:37:00 +0200 Subject: [PATCH] meson: add build option for install path of main config files This allows distros to install configuration file templates in /usr/lib/systemd for example. Currently we install "empty" config files in /etc/systemd/. They serve two purposes: - The file contains commented-out values that show the default settings. - It is easier to edit the right file if it is already there, the user doesn't have to type in the path correctly, and the basic file structure is already in place so it's easier to edit. Things that have happened since this approach was put in place: - We started supporting drop-ins for config files, and drop-ins are the recommended way to create local configuration overrides. - We have systemd-analyze cat-config which takes care of iterating over all possible locations (/etc, /run, /usr, /usr/local) and figuring out the right file. - Because of the first two points, systemd-analyze cat-config is much better, because it takes care of finding all the drop-ins and figuring out the precedence. Looking at files manually is still possible of course, but not very convenient. The disadvantages of the current approach with "empty" files in /etc: - We clutter up /etc so it's harder to see what the local configuration actually is. - If a user edits the file, package updates will not override the file (e.g. systemd.rpm uses %config(noreplace). This means that the "documented defaults" will become stale over time, if the user ever edits the main config file. Thus, I think that it's reasonable to: - Install the main config file to /usr/lib so that it serves as reference for syntax and option names and default values and is properly updated on package upgrades. - Recommend to users to always use drop-ins for configuration and systemd-analyze cat-config to view the documentation. This setting makes this change opt-in. Fixes #18420. [zjs: add more text to the description] --- meson.build | 6 ++++++ meson_options.txt | 4 +++- src/core/meson.build | 6 +++--- src/coredump/meson.build | 2 +- src/home/meson.build | 2 +- src/journal-remote/meson.build | 2 +- src/journal/meson.build | 2 +- src/login/meson.build | 2 +- src/network/meson.build | 2 +- src/oom/meson.build | 2 +- src/pstore/meson.build | 2 +- src/resolve/meson.build | 2 +- src/sleep/meson.build | 2 +- src/timesync/meson.build | 2 +- src/udev/meson.build | 4 ++-- 15 files changed, 25 insertions(+), 17 deletions(-) diff --git a/meson.build b/meson.build index 356e1839e9..7f5d465783 100644 --- a/meson.build +++ b/meson.build @@ -175,6 +175,12 @@ repartdefinitionsdir = libexecdir / 'repart/definitions' ntpservicelistdir = prefixdir / 'lib/systemd/ntp-units.d' credstoredir = prefixdir / 'lib/credstore' +configfiledir = get_option('configfiledir') +if configfiledir == '' + configfiledir= sysconfdir +endif +pkgconfigfiledir = configfiledir / 'systemd' + docdir = get_option('docdir') if docdir == '' docdir = datadir / 'doc/systemd' diff --git a/meson_options.txt b/meson_options.txt index b8116bcedd..831d23e299 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -210,7 +210,9 @@ option('libcryptsetup-plugins-dir', type : 'string', option('docdir', type : 'string', description : 'documentation directory') option('install-sysconfdir', type : 'combo', choices : ['true', 'no-samples', 'false'], value : 'true', - description : 'install configuration files and directories to $sysconfdir') + description : 'install configuration files and directories') +option('configfiledir', type : 'string', value : '', + description : 'directory for configuration files') option('fallback-hostname', type : 'string', value : 'localhost', description : 'the hostname used if none configured') diff --git a/src/core/meson.build b/src/core/meson.build index 44af28a3f3..ce20b51aec 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -194,8 +194,8 @@ executables += [ }, ] -in_files = [['system.conf', pkgsysconfdir], - ['user.conf', pkgsysconfdir], +in_files = [['system.conf', pkgconfigfiledir], + ['user.conf', pkgconfigfiledir], ['org.freedesktop.systemd1.policy', polkitpolicydir]] foreach item : in_files @@ -207,7 +207,7 @@ foreach item : in_files input : file + '.in', output: file, command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], - install : (dir == pkgsysconfdir) ? install_sysconfdir_samples : (dir != 'no'), + install : (dir == pkgconfigfiledir) ? install_sysconfdir_samples : (dir != 'no'), install_dir : dir) endforeach diff --git a/src/coredump/meson.build b/src/coredump/meson.build index ba313ce42e..a69974672c 100644 --- a/src/coredump/meson.build +++ b/src/coredump/meson.build @@ -44,5 +44,5 @@ executables += [ if conf.get('ENABLE_COREDUMP') == 1 and install_sysconfdir_samples install_data('coredump.conf', - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) endif diff --git a/src/home/meson.build b/src/home/meson.build index 8dcc4d41f6..b909cfdd47 100644 --- a/src/home/meson.build +++ b/src/home/meson.build @@ -135,6 +135,6 @@ if conf.get('ENABLE_HOMED') == 1 if install_sysconfdir_samples install_data('homed.conf', - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) endif endif diff --git a/src/journal-remote/meson.build b/src/journal-remote/meson.build index 4251624864..964a251774 100644 --- a/src/journal-remote/meson.build +++ b/src/journal-remote/meson.build @@ -102,7 +102,7 @@ foreach tuple : in_files output: file, command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : tuple[1], - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) endforeach if conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1 diff --git a/src/journal/meson.build b/src/journal/meson.build index 4187dab673..36600bf2c6 100644 --- a/src/journal/meson.build +++ b/src/journal/meson.build @@ -163,7 +163,7 @@ executables += [ if install_sysconfdir_samples install_data('journald.conf', - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) endif if get_option('create-log-dirs') diff --git a/src/login/meson.build b/src/login/meson.build index 1ba996d517..6fb09b48e2 100644 --- a/src/login/meson.build +++ b/src/login/meson.build @@ -124,7 +124,7 @@ custom_target( output : 'logind.conf', command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : enable_logind and install_sysconfdir_samples and pkgsysconfdir != 'no', - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) custom_target( 'systemd-user', diff --git a/src/network/meson.build b/src/network/meson.build index 2ca9eac714..5c05eba095 100644 --- a/src/network/meson.build +++ b/src/network/meson.build @@ -261,6 +261,6 @@ if conf.get('ENABLE_NETWORKD') == 1 if install_sysconfdir_samples install_data('networkd.conf', - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) endif endif diff --git a/src/oom/meson.build b/src/oom/meson.build index d2f4c076e3..690ed7ac6b 100644 --- a/src/oom/meson.build +++ b/src/oom/meson.build @@ -39,6 +39,6 @@ if conf.get('ENABLE_OOMD') == 1 if install_sysconfdir_samples install_data('oomd.conf', - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) endif endif diff --git a/src/pstore/meson.build b/src/pstore/meson.build index 122ba2ee3e..b6fda8723d 100644 --- a/src/pstore/meson.build +++ b/src/pstore/meson.build @@ -17,5 +17,5 @@ executables += [ if conf.get('ENABLE_PSTORE') == 1 and install_sysconfdir_samples install_data('pstore.conf', - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) endif diff --git a/src/resolve/meson.build b/src/resolve/meson.build index 2c34dc5032..e7867e2f85 100644 --- a/src/resolve/meson.build +++ b/src/resolve/meson.build @@ -237,4 +237,4 @@ custom_target( output : 'resolved.conf', command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : conf.get('ENABLE_RESOLVE') == 1 and install_sysconfdir_samples, - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) diff --git a/src/sleep/meson.build b/src/sleep/meson.build index da44ee6dca..fc0037e387 100644 --- a/src/sleep/meson.build +++ b/src/sleep/meson.build @@ -18,5 +18,5 @@ executables += [ if install_sysconfdir_samples install_data('sleep.conf', - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) endif diff --git a/src/timesync/meson.build b/src/timesync/meson.build index 27367e311e..684448097c 100644 --- a/src/timesync/meson.build +++ b/src/timesync/meson.build @@ -66,7 +66,7 @@ custom_target( output : 'timesyncd.conf', command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : conf.get('ENABLE_TIMESYNCD') == 1 and install_sysconfdir_samples, - install_dir : pkgsysconfdir) + install_dir : pkgconfigfiledir) if conf.get('ENABLE_TIMESYNCD') == 1 install_data('org.freedesktop.timesync1.conf', diff --git a/src/udev/meson.build b/src/udev/meson.build index cd4d1f4277..ac9a4c3cca 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -253,9 +253,9 @@ meson.add_install_script(sh, '-c', ln_s.format(bindir / 'udevadm', if install_sysconfdir_samples install_data('udev.conf', - install_dir : sysconfdir / 'udev') + install_dir : configfiledir / 'udev') install_data('iocost/iocost.conf', - install_dir : sysconfdir / 'udev') + install_dir : configfiledir / 'udev') endif udev_pc = custom_target(