]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Set timezone credential to current timezone by default
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 10 Feb 2023 09:40:03 +0000 (10:40 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 10 Feb 2023 09:55:54 +0000 (10:55 +0100)
We don't configure a default timezone in the images, so let's set
a timezone credential by default to the current timezone to avoid
a prompt during first boot.

mkosi/__init__.py

index bb12edbc7e25b1e136eba22c40e4b298e6f5d67f..0172036166cda9e64fbb8dbd1ef239aee9d7c2ea 100644 (file)
@@ -2467,6 +2467,14 @@ def normalize_script(path: Optional[Path]) -> Optional[Path]:
     return Path(path).absolute()
 
 
+def default_credentials() -> dict[str, str]:
+    tz = run(["timedatectl", "show", "-p", "Timezone", "--value"], text=True, stdout=subprocess.PIPE).stdout.strip()
+
+    return {
+        "firstboot.timezone": tz,
+    }
+
+
 def load_args(args: argparse.Namespace) -> MkosiConfig:
     ARG_DEBUG.update(args.debug)
 
@@ -2617,13 +2625,13 @@ def load_args(args: argparse.Namespace) -> MkosiConfig:
         args.environment = {}
 
     if args.credentials:
-        credentials = {}
+        credentials = default_credentials()
         for s in args.credentials:
             key, _, value = s.partition("=")
             credentials[key] = value
         args.credentials = credentials
     else:
-        args.credentials = {}
+        args.credentials = default_credentials()
 
     if args.cache_path is not None:
         args.cache_path = args.cache_path.absolute()