From 66b5bc189749e6382b6dcc6de651fc98f66f9e70 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Thu, 19 Feb 2026 21:39:37 -0700 Subject: [PATCH] fix: propagate host locale into LXC containers and write locale.conf --- core/src/lxc/config.template | 3 +++ core/src/lxc/mod.rs | 14 +++++++++++++- core/src/system/mod.rs | 8 +++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/src/lxc/config.template b/core/src/lxc/config.template index a85b700e4..4f87fce08 100644 --- a/core/src/lxc/config.template +++ b/core/src/lxc/config.template @@ -17,3 +17,6 @@ lxc.net.0.link = lxcbr0 lxc.net.0.flags = up lxc.rootfs.options = rshared + +# Environment +lxc.environment = LANG={lang} diff --git a/core/src/lxc/mod.rs b/core/src/lxc/mod.rs index baffb041e..b8ac615e5 100644 --- a/core/src/lxc/mod.rs +++ b/core/src/lxc/mod.rs @@ -174,10 +174,15 @@ impl LxcContainer { config: LxcConfig, ) -> Result { let guid = new_guid(); + let lang = std::env::var("LANG").unwrap_or_else(|_| "C.UTF-8".into()); let machine_id = hex::encode(rand::random::<[u8; 16]>()); let container_dir = Path::new(LXC_CONTAINER_DIR).join(&*guid); tokio::fs::create_dir_all(&container_dir).await?; - let config_str = format!(include_str!("./config.template"), guid = &*guid); + let config_str = format!( + include_str!("./config.template"), + guid = &*guid, + lang = &lang, + ); tokio::fs::write(container_dir.join("config"), config_str).await?; let rootfs_dir = container_dir.join("rootfs"); let rootfs = OverlayGuard::mount( @@ -215,6 +220,13 @@ impl LxcContainer { 100000, ) .await?; + write_file_owned_atomic( + rootfs_dir.join("etc/default/locale"), + format!("LANG={lang}\n"), + 100000, + 100000, + ) + .await?; Command::new("sed") .arg("-i") .arg(format!("s/LXC_NAME/{guid}/g")) diff --git a/core/src/system/mod.rs b/core/src/system/mod.rs index 9eec913c6..64af2a2d7 100644 --- a/core/src/system/mod.rs +++ b/core/src/system/mod.rs @@ -1261,9 +1261,15 @@ pub async fn save_language(language: &str) -> Result<(), Error> { "/media/startos/config/overlay/usr/lib/locale/locale-archive", ) .await?; + let locale_content = format!("LANG={language}.UTF-8\n"); write_file_atomic( "/media/startos/config/overlay/etc/default/locale", - format!("LANG={language}.UTF-8\n").as_bytes(), + locale_content.as_bytes(), + ) + .await?; + write_file_atomic( + "/media/startos/config/overlay/etc/locale.conf", + locale_content.as_bytes(), ) .await?; Ok(())