]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Drop --hostname and default locale configuration
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 13 Apr 2023 18:43:22 +0000 (20:43 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 13 Apr 2023 20:00:03 +0000 (22:00 +0200)
These are trivial to configure manually and with credentials, so
let's drop the options for them.

NEWS.md
mkosi.md
mkosi/__init__.py
mkosi/backend.py
mkosi/config.py
mkosi/distributions/debian.py
tests/test_parse_load_args.py

diff --git a/NEWS.md b/NEWS.md
index fb96b5a39891849e09cb6f6b964d50af763a5247..70ea3c283d5ff2deaf7eab2d38d54e721a70de27 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
   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
index 03ad23775e9567cda45da532700ad2d478ca4e22..b4a744b761fd2844f1b029502d5cbb56838ffe59 100644 (file)
--- 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
index 9e4e41f320e57e39b2f1559c1fb4d8b0512d850a..5cb3b84e8a64450379231de34ef4ae5eeaf5aeb2 100644 (file)
@@ -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:
index fc3e4e534170d274a9ecb14a81d3d0cce85247dc..bec6eea93d4e9e91af4a5e57b98641cb89789e3c 100644 (file)
@@ -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
index 207abcfd4bf8ada2df049b57ac4ef6e539e04995..bb36af8ec0b7e2371efba8c1171e516cf16c6576 100644 (file)
@@ -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(
index ca83ccdd5bdc97c6e3d3c366d4ee7542ea31066a..905c7f01cf3b40f3ca842cfd9e98ff8dfe9a21f0 100644 (file)
@@ -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)
index 18a51b8881d864eb76de4509249b95d08077d7f5..d20523102c50f2534845a855e2b8aec647189430 100644 (file)
@@ -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"):