)
-def finalize_default_tools(main: ParseContext, finalized: dict[str, Any], *, resources: Path) -> Config:
+def finalize_default_tools(
+ main: ParseContext,
+ finalized: dict[str, Any],
+ *,
+ configdir: Path,
+ resources: Path,
+) -> Config:
context = ParseContext(resources)
for s in SETTINGS:
for name in finalized.get("environment", {}).keys() & finalized.get("pass_environment", [])
}
- if (p := Path("mkosi.tools.conf").absolute()).exists():
+ if (p := configdir / "mkosi.tools.conf").exists():
with chdir(p if p.is_dir() else Path.cwd()):
context.parse_config_one(p, parse_profiles=p.is_dir(), parse_local=p.is_dir())
if not args.verb.needs_config():
return args, None, ()
- # Allow locating all mkosi configuration in a mkosi/ subdirectory instead of in the top-level directory
- # of a git repository.
- if (
- args.directory is not None
- and not (Path("mkosi.conf").exists() or Path("mkosi.tools.conf").exists())
- and (Path("mkosi/mkosi.conf").is_file() or Path("mkosi/mkosi.tools.conf").exists())
- ):
- os.chdir(args.directory / "mkosi")
- args = dataclasses.replace(args, directory=args.directory / "mkosi")
-
if have_history(args):
try:
j = json.loads(Path(".mkosi-private/history/latest.json").read_text())
context.config["files"] = []
+ # Allow locating all mkosi configuration in a mkosi/ subdirectory instead of in the top-level directory
+ # of a git repository.
+ if (
+ args.directory is not None
+ and not (Path("mkosi.conf").exists() or Path("mkosi.tools.conf").exists())
+ and (Path("mkosi/mkosi.conf").is_file() or Path("mkosi/mkosi.tools.conf").exists())
+ ):
+ configdir = Path.cwd() / "mkosi"
+ else:
+ configdir = Path.cwd()
+
# Parse the global configuration unless the user explicitly asked us not to.
if args.directory is not None:
- context.parse_config_one(Path.cwd(), parse_profiles=True, parse_local=True)
+ with chdir(configdir):
+ context.parse_config_one(configdir, parse_profiles=True, parse_local=True)
config = context.finalize()
return args, tools, (*subimages, Config.from_dict(config))
if config.get("tools_tree") == Path("default"):
- tools = finalize_default_tools(context, config, resources=resources)
+ tools = finalize_default_tools(context, config, configdir=configdir, resources=resources)
config["tools_tree"] = tools.output_dir_or_cwd() / tools.output
images = []
None if "dependencies" in context.cli or "dependencies" in context.config else []
)
- if args.directory is not None and Path("mkosi.images").exists():
+ if args.directory is not None and (imagedir := configdir / "mkosi.images").exists():
# For the subimages in mkosi.images/, we want settings that are marked as
# "universal" to override whatever settings are specified in the subimage
# configuration files. We achieve this by making it appear like these settings
elif s.dest in context.cli:
del context.cli[s.dest]
- for p in sorted(Path("mkosi.images").iterdir()):
+ for p in sorted(imagedir.iterdir()):
p = p.absolute()
if not p.is_dir() and not p.suffix == ".conf":
working directory. If the empty string is specified, all configuration in
the current working directory will be ignored.
-: If the specified directory does not contain a `mkosi.conf` or
- `mkosi.tools.conf` and a `mkosi/mkosi.conf` or `mkosi/mkosi.tools.conf`
- exists, the `mkosi/` subdirectory of the specified directory will be
- used instead.
-
`--debug`
: Enable additional debugging output.
corresponding path exists.
* `mkosi.conf` is parsed if it exists in the directory configured with
`--directory=` or the current working directory if `--directory=` is
- not used.
-* `mkosi.conf.d/` is parsed in the same directory if it exists. Each
- directory and each file with the `.conf` extension in `mkosi.conf.d/`
- is parsed. Any directory in `mkosi.conf.d` is parsed as if it were
- a regular top level directory.
+ not used. If the specified directory does not contain a `mkosi.conf` or
+ `mkosi.tools.conf` and a `mkosi/mkosi.conf` or `mkosi/mkosi.tools.conf`
+ exists, the configuration will be parsed from the `mkosi/`
+ subdirectory of the specified directory instead.
+* `mkosi.conf.d/` is parsed in the same directory as `mkosi.conf` if it
+ exists. Each directory and each file with the `.conf` extension in
+ `mkosi.conf.d/` is parsed. Any directory in `mkosi.conf.d` is parsed
+ as if it were a regular top level directory.
* If any profiles are configured, their configuration is parsed from the
`mkosi.profiles/` directory.
-* Subimages are parsed from the `mkosi.images` directory if it exists.
+* Subimages are parsed from the `mkosi.images/` directory if it exists.
Note that settings configured via the command line always override
settings configured via configuration files. If the same setting is