diff --git a/man/ukify.xml b/man/ukify.xml
index 0a9cd5ee38f..3ee1306c6cb 100644
--- a/man/ukify.xml
+++ b/man/ukify.xml
@@ -155,6 +155,13 @@
priority and overwrites the config file setting completely. If some setting behaves differently, this is
described below.
+ If no config file is provided via the option ,
+ ukify will try to look for a default configuration file in the following paths in this
+ order: /run/systemd/ukify.conf, /etc/systemd/ukify.conf,
+ /usr/local/lib/systemd/ukify.conf, and /usr/lib/systemd/ukify.conf,
+ and then load the first one found. ukify will proceed normally if no configuration file
+ is specified and no default one is found.
+
The LINUX and INITRD positional arguments, or
the equivalent Linux= and Initrd= settings, are optional. If more
than one initrd is specified, they will all be combined into a single PE section. This is useful to, for
diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py
index b7e21dafed7..890a694e685 100755
--- a/src/ukify/ukify.py
+++ b/src/ukify/ukify.py
@@ -65,6 +65,11 @@ EFI_ARCH_MAP = {
}
EFI_ARCHES: list[str] = sum(EFI_ARCH_MAP.values(), [])
+# Default configuration directories and file name.
+# When the user does not specify one, the directories are searched in this order and the first file found is used.
+DEFAULT_CONFIG_DIRS = ['/run/systemd', '/etc/systemd', '/usr/local/lib/systemd', '/usr/lib/systemd']
+DEFAULT_CONFIG_FILE = 'ukify.conf'
+
def guess_efi_arch():
arch = os.uname().machine
@@ -1176,6 +1181,7 @@ CONFIG_ITEMS = [
ConfigItem(
('--config', '-c'),
metavar = 'PATH',
+ type = pathlib.Path,
help = 'configuration file',
),
@@ -1394,9 +1400,21 @@ CONFIGFILE_ITEMS = { item.config_key:item
def apply_config(namespace, filename=None):
if filename is None:
- filename = namespace.config
- if filename is None:
- return
+ if namespace.config:
+ # Config set by the user, use that.
+ filename = namespace.config
+ print(f'Using config file: {filename}')
+ else:
+ # Try to look for a config file then use the first one found.
+ for config_dir in DEFAULT_CONFIG_DIRS:
+ filename = pathlib.Path(config_dir) / DEFAULT_CONFIG_FILE
+ if filename.is_file():
+ # Found a config file, use it.
+ print(f'Using found config file: {filename}')
+ break
+ else:
+ # No config file specified or found, nothing to do.
+ return
# Fill in ._groups based on --pcr-public-key=, --pcr-private-key=, and --phases=.
assert '_groups' not in namespace