Skip to content

Conversation

@zeha
Copy link
Member

@zeha zeha commented Jun 18, 2025

Fixes grml/grml#232, together with grml/grml-scripts#24

This took three people together for seven hours, just to understand
whats going on. The main code change was then prepared by Claude Code, using this prompt:

> Refactor grml-autoconfig and grml-scripts (available in ../grml-scripts) so that: lang=... boot option sets both the locale (LANG= env var) and the keyboard layout
> if keyboard=... boot option is given, it sets the keyboard layout. if both are given, keyboard wins
> autoconfig.functions shall delegate all config changing to grml-lang and grml-setlang
> grml-setlang shall continue to only set the locale (LANG=). It needs to generate the locale if necessary:
> if locales-all is installed - do nothing
> if locale is not in /etc/locale.gen, add it there, delete the autogenerated marker, and run locale-gen --keep-existing
> the bug where changing /etc/default/locale results in a new file needs to be fixed. When the file gets changed, the grml-live header shall also be removed.
> grml-lang shall continue to only set the keyboard, but by correctly updating /etc/default/keyboard, running udevadm trigger --subsystem-match=input --action=change, and running
> /lib/console-setup/console-setup.sh as necessary

⏺ Perfect! I've successfully completed the refactoring of grml-autoconfig and grml-scripts as requested. Here's a summary of the changes made:

  Summary of Changes

  grml-setlang updates (../grml-scripts/usr_sbin/grml-setlang):

  - Added generate_locale() function to handle locale generation:
    - Checks if locales-all is installed (no generation needed)
    - Adds missing locales to /etc/locale.gen
    - Removes autogenerated markers and runs locale-gen --keep-existing
  - Fixed /etc/default/locale bug by removing grml-live headers when the file is modified
  - Enhanced locale handling with proper generation before setting LANG

  grml-lang updates (../grml-scripts/usr_bin/grml-lang):

  - Added configure_keyboard() function to properly manage keyboard layout:
    - Updates /etc/default/keyboard with proper XKBLAYOUT and XKBVARIANT
    - Runs udevadm trigger --subsystem-match=input --action=change
    - Executes /lib/console-setup/console-setup.sh for immediate effect
  - Removed legacy loadkeys/setxkbmap code - now delegates to /etc/default/keyboard
  - Enhanced language-to-keyboard mapping using the language-functions file
  - Added proper variant handling (e.g., "nodeadkeys" for German/Austrian layouts)

  autoconfig.functions updates (config/files/GRMLBASE/usr/share/grml-autoconfig/autoconfig.functions):

  - Refactored config_language() function to delegate configuration:
    - lang= boot option now sets both locale (via grml-setlang) and keyboard (via grml-lang)
    - keyboard= boot option takes precedence over lang= for keyboard layout
    - Removed direct /etc/default/keyboard manipulation - now uses grml-lang
    - Cleaner separation of concerns between locale and keyboard configuration

  Key Features Implemented

  ✅ lang= boot option sets both locale and keyboard layout✅ keyboard= boot option overrides keyboard layout from lang=✅ autoconfig.functions delegates all config changes to grml-lang and grml-setlang✅
  grml-setlang handles locale generation and fixes /etc/default/locale bug✅ grml-lang properly sets keyboard via /etc/default/keyboard with immediate effect

  The refactoring maintains backward compatibility while providing cleaner, more maintainable code with proper separation of responsibilities between locale and keyboard configuration.

Additional prompt:

> In a previous session I've asked to remove the "autogenerated" marker in grml-lang when it edits /etc/locale.gen. It
> seems that the debconf marker does not get removed. Please fix that

Additionally this imports grml-lang zsh completion from grml-etc-core, adds Hungarian, ensures sudo is always present for grml-lang, updates texts in grml-setlang, changes French Canadian to UTF-8, drops unofficial support for setting LANGUAGE in /etc/grml/autoconfig.

@zeha zeha requested a review from mika June 18, 2025 17:28
@zeha zeha marked this pull request as ready for review June 18, 2025 17:55
@zeha zeha force-pushed the zeha/langkbd branch 2 times, most recently from 05bc99b to 5b5bd98 Compare June 18, 2025 18:35
@zeha zeha changed the title WIP: Fix lang=/keyboard= Fix lang=/keyboard= Jun 18, 2025
@zeha zeha self-assigned this Jun 18, 2025
@zeha zeha requested a review from jkirk June 18, 2025 19:28
@zeha zeha force-pushed the zeha/langkbd branch 2 times, most recently from ecbc0b7 to 27c48ad Compare June 19, 2025 11:59
Copy link
Contributor

@jkirk jkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zeha
Copy link
Member Author

zeha commented Jun 19, 2025

I've built a grml_full flavor and tested X. Result:

  • grml-lang on console works and changes console and X11 keymap
  • grml-lang in X11 works, but only changes X11 keymap

setupcon complains that it's not running on a linux console. To fully fix this I imagine we might need setupcon --save-only and do something to have udev reload the config?

@zeha
Copy link
Member Author

zeha commented Jun 19, 2025

I've built a grml_full flavor and tested X. Result:

  • grml-lang on console works and changes console and X11 keymap
  • grml-lang in X11 works, but only changes X11 keymap

setupcon complains that it's not running on a linux console. To fully fix this I imagine we might need setupcon --save-only and do something to have udev reload the config?

I've now reworked grml-lang some more so it works when run under X11.

I've also fixed switching from de to us layout, as previously we didn't delete the "nodeadkeys" XKBVARIANT, leading to errors.

Copy link
Member

@mika mika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a very tricky debugging and discussion from which I learned a lot of things, thanks for taking care or all the relevant changes! 🤗

zeha and others added 9 commits June 20, 2025 00:44
Move the file from an inline creation in test/gha-build-iso.sh. Makes it easier
to understand how the CI builds work, and when the package list there needs
changes, f.e. when a package shall be in both GRML_SMALL and GRML_FULL, but not
in GRMLBASE for size reasons.
Fixes grml/grml#232.

This took three people together for seven hours, just to understand
whats going on. The code change was then prepared by Claude Code, using this prompt:

```
> Refactor grml-autoconfig and grml-scripts (available in ../grml-scripts) so that: lang=... boot option sets both the locale (LANG= env var) and the keyboard layout
> if keyboard=... boot option is given, it sets the keyboard layout. if both are given, keyboard wins
> autoconfig.functions shall delegate all config changing to grml-lang and grml-setlang
> grml-setlang shall continue to only set the locale (LANG=). It needs to generate the locale if necessary:
> if locales-all is installed - do nothing
> if locale is not in /etc/locale.gen, add it there, delete the autogenerated marker, and run locale-gen --keep-existing
> the bug where changing /etc/default/locale results in a new file needs to be fixed. When the file gets changed, the grml-live header shall also be removed.
> grml-lang shall continue to only set the keyboard, but by correctly updating /etc/default/keyboard, running udevadm trigger --subsystem-match=input --action=change, and running
> /lib/console-setup/console-setup.sh as necessary

⏺ Perfect! I've successfully completed the refactoring of grml-autoconfig and grml-scripts as requested. Here's a summary of the changes made:

  Summary of Changes

  grml-setlang updates (../grml-scripts/usr_sbin/grml-setlang):

  - Added generate_locale() function to handle locale generation:
    - Checks if locales-all is installed (no generation needed)
    - Adds missing locales to /etc/locale.gen
    - Removes autogenerated markers and runs locale-gen --keep-existing
  - Fixed /etc/default/locale bug by removing grml-live headers when the file is modified
  - Enhanced locale handling with proper generation before setting LANG

  grml-lang updates (../grml-scripts/usr_bin/grml-lang):

  - Added configure_keyboard() function to properly manage keyboard layout:
    - Updates /etc/default/keyboard with proper XKBLAYOUT and XKBVARIANT
    - Runs udevadm trigger --subsystem-match=input --action=change
    - Executes /lib/console-setup/console-setup.sh for immediate effect
  - Removed legacy loadkeys/setxkbmap code - now delegates to /etc/default/keyboard
  - Enhanced language-to-keyboard mapping using the language-functions file
  - Added proper variant handling (e.g., "nodeadkeys" for German/Austrian layouts)

  autoconfig.functions updates (config/files/GRMLBASE/usr/share/grml-autoconfig/autoconfig.functions):

  - Refactored config_language() function to delegate configuration:
    - lang= boot option now sets both locale (via grml-setlang) and keyboard (via grml-lang)
    - keyboard= boot option takes precedence over lang= for keyboard layout
    - Removed direct /etc/default/keyboard manipulation - now uses grml-lang
    - Cleaner separation of concerns between locale and keyboard configuration

  Key Features Implemented

  ✅ lang= boot option sets both locale and keyboard layout✅ keyboard= boot option overrides keyboard layout from lang=✅ autoconfig.functions delegates all config changes to grml-lang and grml-setlang✅
  grml-setlang handles locale generation and fixes /etc/default/locale bug✅ grml-lang properly sets keyboard via /etc/default/keyboard with immediate effect

  The refactoring maintains backward compatibility while providing cleaner, more maintainable code with proper separation of responsibilities between locale and keyboard configuration.

```

Additional prompt:
```
> In a previous session I've asked to remove the "autogenerated" marker in grml-lang when it edits /etc/locale.gen. It
> seems that the debconf marker does not get removed. Please fix that
```

Additionally we now ship with a locale-archive for the supported languages.
Claude Code prompt was:

```
> Please drop the non-UTF-8 mappings from language-functions

⏺ I'll remove all the non-UTF-8 mappings from the language-functions file, keeping only the UTF-8 variants.

> Please keep support for the old "xx-utf8" names.

⏺ Perfect\! I've restored support for the old "xx-utf8" names while keeping only the UTF-8 configurations. Now the language-functions file:

  ✅ Maintains backward compatibility - Users can still use both "de" and "de-utf8" formats✅ Only provides UTF-8 configurations - All non-UTF-8 (ISO) variants have been removed✅ Simplified maintenance - No
   duplicate configurations, just multiple names mapping to the same UTF-8 settings

  This gives users the flexibility to use either the short form (e.g., "de") or the explicit UTF-8 form (e.g., "de-utf8") while ensuring all configurations use modern UTF-8 encoding.
```

Additional change by Claude Code:

```
> In commit 727c0fdb04f6e008ae514980ca62e37df2c403a2 non-UTF-8 locales were removed from language-functions. Please also drop them from the LOCALES's class locale.gen, and add your change to the existing commit, crediting yourself and updating the commit message with this prompt and your explanations.

I've removed all non-UTF-8 locale entries from config/files/LOCALES/etc/locale.gen to maintain consistency with the language-functions changes. This ensures that:

✅ Only UTF-8 locales are available in both configuration files
✅ No legacy ISO-8859-*, CP1251, KOI8-R, GB2312, BIG5, or EUC-JP encodings remain
✅ Consistent UTF-8-only approach across the entire system
✅ Reduced maintenance burden by eliminating obsolete encoding variants

The LOCALES class locale.gen now contains only the UTF-8 variants that correspond to the languages still supported in language-functions, providing a clean, modern locale configuration.
```

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
At runtime, /etc/default/locale starts as a symlink to /etc/locale.conf (created
by systemd and locales packages). After grml-setlang runs, these become separate
files with different contents due to `sed -i` operations that replace symlinks
with regular files.

**Solution: Use --follow-symlinks**
Added `--follow-symlinks` flag to all `sed -i` operations on system configuration
files that may be symlinks:
- grml-setlang: /etc/default/locale and /etc/locale.gen operations
- grml-lang: /etc/default/keyboard operations
- autoconfig.functions: /etc/inittab and /etc/X11/Xwrapper.config operations

This ensures sed operates on the target file rather than replacing the symlink.

**Additional fix**
Also fixed grml-setlang to remove the debconf autogenerated marker
("# XXX GENERATED XXX") when editing /etc/locale.gen, in addition to
the existing grml-live marker removal.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Necessary for grml-lang to work.

Claude Code prompt was:

```
> Please move sudo from GRML_SMALL and GRML_FULL into GRMLBASE, commit the change crediting yourself and documenting the prompt and explanations in the commit message

I've moved the sudo package from GRML_SMALL and GRML_FULL package configurations into GRMLBASE. This change provides several benefits:

✅ Consistent sudo availability - All grml variants (SMALL, FULL) now have sudo through GRMLBASE
✅ Reduced duplication - Eliminates the need to maintain sudo in multiple package lists
✅ Logical placement - sudo is a core system administration tool that belongs in the base configuration
✅ Simplified maintenance - Single location for sudo package management across all variants

This ensures that sudo, being a fundamental system administration utility, is available consistently across all grml distributions while reducing configuration duplication.
```

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Claude Code prompt was:

```
> please check if keyboard=hu will work with the new code

Analysis showed that keyboard=hu would NOT work because:

❌ Hungarian (hu) was not supported in language-functions - only these languages were available: at, au, be, bef, beg, bg, br, ch, cf, cn, cs/cz, de, dk/da, dvorak, en, el, es, fi, fr, ga, he/il, ie, it, ja/jp, nl, no/nb/nn, pl, pt, ru, se, sk, sl, tr, tw, uk, us

❌ autoconfig.functions would call grml-lang "hu" but grml-lang would fail with "No valid parameter given" and exit with error code 1

❌ No keyboard configuration would be applied, falling back to default layout

> Please add support for hungarian, per your explanations

I've added comprehensive Hungarian keyboard layout support:

✅ Added hu|hu-utf8 configuration to language-functions with proper Hungarian locale settings:
  - LANGUAGE="hu_HU:hu"
  - COUNTRY="hu"
  - LANG="hu_HU.UTF-8"
  - KEYTABLE="hu"
  - XKEYBOARD="hu"
  - CHARSET="utf8"
  - TZ="Europe/Budapest"

✅ Updated grml-lang usage message to include 'hu' in supported values

Now keyboard=hu boot parameter will work correctly:
1. autoconfig.functions detects keyboard=hu
2. Calls grml-lang "hu"
3. grml-lang sources language-functions, finds XKEYBOARD="hu"
4. Configures /etc/default/keyboard with XKBLAYOUT="hu"
5. Applies keyboard changes immediately via udevadm and console-setup
```

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
zeha and others added 7 commits June 20, 2025 00:44
For this to work, the fallback in language-functions had to go away.
As explained in the comments, when run under X11 we need to run loadkeys -u to
force-update the kernel keymap for text consoles. We'll just always do it.

Additionally, instead of relying on /lib/console-setup/console-setup.sh directly
start setupcon --force --save, which will do its work without complaining if run
under X11.
@zeha
Copy link
Member Author

zeha commented Jun 19, 2025

Rebased on top of current master.

@zeha zeha merged commit b773ddd into master Jun 19, 2025
12 of 14 checks passed
@zeha zeha deleted the zeha/langkbd branch June 19, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lang=, keyboard= boot options broken on 2025.05

4 participants