keylength = 2048
expiration_date = datetime.date.today() + datetime.timedelta(int(args.genkey_valid_days))
- configdir = finalize_configdir(args)
+ configdir = finalize_configdir(args.directory)
+ if not configdir:
+ die("genkey cannot be used with empty --directory")
for f in (configdir / "mkosi.key", configdir / "mkosi.crt"):
if f.exists() and not args.force:
def finalize_image_version(args: Args, config: Config) -> None:
- p = finalize_configdir(args) / "mkosi.version"
+ configdir = finalize_configdir(args.directory)
+ if not configdir:
+ die("Image version cannot be finalized with empty --directory")
+ p = configdir / "mkosi.version"
assert config.image_version
p.write_text(config.image_version)
logging.info(f"Wrote new version {config.image_version} to {p}")
return cast(str, namespace["distribution"].default_release())
+def config_default_tools_tree(namespace: dict[str, Any]) -> Optional[Path]:
+ if namespace.get("image") != "main":
+ return None
+
+ configdir = finalize_configdir(namespace["directory"])
+ return Path("default") if configdir and (configdir / "mkosi.tools.conf").exists() else None
+
+
def config_default_tools_tree_distribution(namespace: dict[str, Any]) -> Distribution:
if d := os.getenv("MKOSI_HOST_DISTRIBUTION"):
return Distribution(d).default_tools_tree_distribution()
section="Build",
parse=config_make_path_parser(constants=("default",)),
path_suffixes=("tools",),
+ default_factory=config_default_tools_tree,
help="Look up programs to execute inside the given tree",
scope=SettingScope.universal,
),
main: ParseContext,
finalized: dict[str, Any],
*,
- configdir: Path,
+ configdir: Optional[Path],
resources: Path,
) -> Config:
context = ParseContext(resources)
for name in finalized.get("environment", {}).keys() & finalized.get("pass_environment", [])
}
- if (p := configdir / "mkosi.tools.conf").exists():
+ if configdir and (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())
return Config.from_dict(context.finalize())
-def finalize_configdir(args: Args) -> Path:
+def finalize_configdir(directory: Optional[Path]) -> Optional[Path]:
"""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())
+ if directory is None:
+ return None
+
+ if not ((directory / "mkosi.conf").exists() or (directory / "mkosi.tools.conf").exists()) and (
+ (directory / "mkosi/mkosi.conf").is_file() or (directory / "mkosi/mkosi.tools.conf").exists()
):
- return Path.cwd() / "mkosi"
+ return directory / "mkosi"
- return Path.cwd()
+ return directory
def bump_image_version(configdir: Path) -> str:
context.config["files"] = []
- configdir = finalize_configdir(args)
+ configdir = finalize_configdir(args.directory)
if (
- (args.auto_bump and args.verb.needs_build())
- or args.verb == Verb.bump
+ ((args.auto_bump and args.verb.needs_build()) or args.verb == Verb.bump)
and context.cli.get("image_version") is not None
+ and configdir is not None
):
context.cli["image_version"] = bump_image_version(configdir)
# Parse the global configuration unless the user explicitly asked us not to.
- if args.directory is not None:
+ if configdir is not None:
with chdir(configdir):
context.parse_config_one(configdir, parse_profiles=True, parse_local=True)
None if "dependencies" in context.cli or "dependencies" in context.config else []
)
- if args.directory is not None and (imagedir := configdir / "mkosi.images").exists():
+ if configdir 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
: Specifies whether to install an **sshd** socket unit and matching service
in the final image. Takes one of `always`, `never`, `auto` or `runtime`.
Defaults to `auto`.
-
+
If set to `auto` and the generator binary `systemd-ssh-generator`
is not preset in the image, or set to `always`, mkosi will install **sshd** units
in the final image that expose SSH over VSock. If set to `never`,
using the settings below or with `mkosi.tools.conf` which can either be a
file or directory containing extra configuration for the default tools tree.
+ If `mkosi.tools.conf` exists in the directory mkosi is invoked in,
+ a default tools tree is used if no tools tree is specified.
+
The following table shows for which distributions default tools tree
packages are defined and which packages are included in those default
tools trees: