From: Daan De Meyer Date: Thu, 13 Apr 2023 18:43:22 +0000 (+0200) Subject: Drop --hostname and default locale configuration X-Git-Tag: v15~257^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8184af8183b48bddf4643e402475a2060e58df0f;p=thirdparty%2Fmkosi.git Drop --hostname and default locale configuration These are trivial to configure manually and with credentials, so let's drop the options for them. --- diff --git a/NEWS.md b/NEWS.md index fb96b5a39..70ea3c283 100644 --- a/NEWS.md +++ b/NEWS.md @@ -161,6 +161,9 @@ image. Note that this option is currently only supported for `pacman` and `dnf`-based distros. - Option `--skeleton-tree` is now supported on Debian-based distros. +- Removed `--hostname` as its trivial to configure using systemd-firstboot. +- Removed default locale configuration as its trivial to configure using + systemd-firstboot and systemd writes a default locale well. ## v12 diff --git a/mkosi.md b/mkosi.md index 03ad23775..b4a744b76 100644 --- a/mkosi.md +++ b/mkosi.md @@ -428,10 +428,6 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0", the `shell`, `boot`, `qemu` verbs are not available when this option is used. Implied for `tar` and `cpio`. -`Hostname=`, `--hostname=` - -: Set the image's hostname to the specified name. - `ImageVersion=`, `--image-version=` : Configure the image version. This accepts any string, but it is @@ -1320,20 +1316,6 @@ EOF # systemd-nspawn -bi image.raw ``` -To create a *Fedora Linux* image with hostname: -```bash -# mkosi --distribution fedora --hostname image -``` - -Also you could set hostname in configuration file: -```bash -# cat mkosi.conf -... -[Output] -Hostname=image -... -``` - # REQUIREMENTS mkosi is packaged for various distributions: Debian, Ubuntu, Arch diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 9e4e41f32..5cb3b84e8 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -128,33 +128,6 @@ def mount_image(state: MkosiState) -> Iterator[None]: yield -def configure_locale(state: MkosiState) -> None: - if state.for_cache: - return - - etc_locale = state.root / "etc/locale.conf" - etc_locale.unlink(missing_ok=True) - # Let's ensure we use a UTF-8 locale everywhere. - etc_locale.write_text("LANG=C.UTF-8\n") - - -def configure_hostname(state: MkosiState) -> None: - if state.for_cache: - return - - etc_hostname = state.root / "etc/hostname" - - # Always unlink first, so that we don't get in trouble due to a - # symlink or suchlike. Also if no hostname is configured we really - # don't want the file to exist, so that systemd's implicit - # hostname logic can take effect. - etc_hostname.unlink(missing_ok=True) - - if state.config.hostname: - with complete_step("Assigning hostname"): - etc_hostname.write_text(state.config.hostname + "\n") - - def prepare_tree_root(state: MkosiState) -> None: if state.config.output_format == OutputFormat.subvolume: with complete_step("Setting up OS tree root…"): @@ -1069,6 +1042,12 @@ def load_credentials(args: argparse.Namespace) -> dict[str, str]: tz = run(["timedatectl", "show", "-p", "Timezone", "--value"], text=True, stdout=subprocess.PIPE).stdout.strip() creds["firstboot.timezone"] = tz + if "firstboot.locale" not in creds: + creds["firstboot.locale"] = "C.UTF-8" + + if "firstboot.hostname" not in creds: + creds["firstboot.hostname"] = machine_name(args) + if args.ssh and "ssh.authorized_keys.root" not in creds and "SSH_AUTH_SOCK" in os.environ: key = run(["ssh-add", "-L"], text=True, stdout=subprocess.PIPE, env=os.environ).stdout.strip() creds["ssh.authorized_keys.root"] = key @@ -1389,9 +1368,6 @@ def print_summary(config: MkosiConfig) -> None: print("\nOUTPUT:") - if config.hostname: - print(" Hostname:", config.hostname) - if config.image_id is not None: print(" Image ID:", config.image_id) @@ -1772,8 +1748,6 @@ def build_image(state: MkosiState, *, manifest: Optional[Manifest] = None) -> No run_prepare_script(state, cached, build=False) install_build_packages(state, cached) run_prepare_script(state, cached, build=True) - configure_locale(state) - configure_hostname(state) configure_root_password(state) configure_autologin(state) configure_initrd(state) @@ -1949,8 +1923,8 @@ def suppress_stacktrace() -> Iterator[None]: raise MkosiException() from e -def machine_name(config: MkosiConfig) -> str: - return config.hostname or config.image_id or config.output.with_suffix("").name.partition("_")[0] +def machine_name(config: Union[MkosiConfig, argparse.Namespace]) -> str: + return config.image_id or config.output.with_suffix("").name.partition("_")[0] def machine_cid(config: MkosiConfig) -> int: diff --git a/mkosi/backend.py b/mkosi/backend.py index fc3e4e534..bec6eea93 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -226,7 +226,6 @@ class MkosiConfig: compress_output: Union[None, str, bool] image_version: Optional[str] image_id: Optional[str] - hostname: Optional[str] tar_strip_selinux_context: bool incremental: bool cache_initrd: bool diff --git a/mkosi/config.py b/mkosi/config.py index 207abcfd4..bb36af8ec 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -418,10 +418,6 @@ class MkosiConfigParser: section="Output", parse=config_parse_compression, ), - MkosiConfigSetting( - dest="hostname", - section="Output", - ), MkosiConfigSetting( dest="image_version", section="Output", @@ -967,7 +963,6 @@ class MkosiConfigParser: nargs="?", action=action, ) - group.add_argument("--hostname", help="Set hostname", action=action) group.add_argument("--image-version", help="Set version for image", action=action) group.add_argument("--image-id", help="Set ID for image", action=action) group.add_argument( diff --git a/mkosi/distributions/debian.py b/mkosi/distributions/debian.py index ca83ccdd5..905c7f01c 100644 --- a/mkosi/distributions/debian.py +++ b/mkosi/distributions/debian.py @@ -134,11 +134,6 @@ class DebianInstaller(DistributionInstaller): # Don't ship dpkg config files in extensions, they belong with dpkg in the base image. dpkg_nodoc_conf.unlink() # type: ignore - # Debian/Ubuntu use a different path to store the locale so let's make sure that path is a symlink to - # etc/locale.conf. - state.root.joinpath("etc/default/locale").unlink(missing_ok=True) - state.root.joinpath("etc/default/locale").symlink_to("../locale.conf") - # Don't enable any services by default. presetdir = state.root / "etc/systemd/system-preset" presetdir.mkdir(exist_ok=True, mode=0o755) diff --git a/tests/test_parse_load_args.py b/tests/test_parse_load_args.py index 18a51b888..d20523102 100644 --- a/tests/test_parse_load_args.py +++ b/tests/test_parse_load_args.py @@ -75,19 +75,6 @@ def test_parse_config_files_filter() -> None: assert parse([]).packages == ["yes"] -def test_hostname() -> None: - with cd_temp_dir(): - assert parse(["--hostname", "name"]).hostname == "name" - with pytest.raises(SystemExit): - parse(["--hostname", "name", "additional_name"]) - with pytest.raises(SystemExit): - parse(["--hostname"]) - - config = Path("mkosi.conf") - config.write_text("[Output]\nHostname=name") - assert parse([]).hostname == "name" - - def test_shell_boot() -> None: with cd_temp_dir(): with pytest.raises(MkosiException, match=".boot.*tar"):