Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/mise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ jobs:
- name: Test isolated sudoers policy as the runner account
run: bash modules/system/tests/test_sudoers.sh

- name: Test keymap choice as the runner account
run: bash modules/system/tests/test_keymap.sh

macos:
runs-on: macos-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ It requires a non-root Linux account, installed `visudo`, bubblewrap, permitted

The workflow defines a dedicated `system-sudoers` Ubuntu job that installs packaged sudo/bubblewrap, loads an AppArmor profile that grants user namespaces to `/usr/bin/bwrap` only (Ubuntu 24.04 otherwise blocks them for unprivileged programs; the host-wide restriction stays on), and runs the same test script directly as the non-root runner account, outside the wildcard suites. This route covers isolated sudoers safety, not full Omarchy provisioning or desktop runtime; consult the workflow results for execution evidence.

The same job runs `check:system-keymap`, which checks the Dvorak and virtual-machine US keymap choice against a stubbed `localectl`. It needs only a non-root Linux account.

</details>

## Documentation
Expand Down
2 changes: 1 addition & 1 deletion docs/fork.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The other 1Password references:

| Setting | Where | What it does |
| --- | --- | --- |
| Keyboard and locale (Linux) | `modules/system/bootstrap.sh` | Sets the console keymap to `dvorak`, the X11 layout to `us` / `dvorak` with `caps:none`, and the locale to `en_US.UTF-8` |
| Keyboard and locale (Linux) | `modules/system/bootstrap.sh` | Sets the console keymap to `dvorak`, the X11 layout to `us` / `dvorak` with `caps:none`, and the locale to `en_US.UTF-8`. In a virtual machine both are plain `us`, because a hypervisor console sends US key positions |
| Passwordless sudo (Linux) | `modules/system/bootstrap.sh` | Installs `/etc/sudoers.d/techdufus`, granting the account that runs bootstrap `NOPASSWD: ALL` |
| Login shell | `[bootstrap.user]` in `modules/zsh/mise.linux.toml` and `mise.macos.toml` | Changes it to zsh |
| CapsLock | `modules/omarchy/hypr/keyboard.lua` and `summon.lua`; `modules/hammerspoon/karabiner/karabiner.json` | CapsLock stops being CapsLock and becomes the app leader |
Expand Down
17 changes: 13 additions & 4 deletions modules/system/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ fi

field() { printf '%s\n' "$status" | sed -n "s/^[[:space:]]*$1:[[:space:]]*//p" | head -n 1; }

if [ "$(field 'VC Keymap')" != "dvorak" ]; then
sudo localectl set-keymap dvorak
# A virtual machine is typed on through its hypervisor console, which sends each
# character as its US QWERTY key (QEMU -k en-us), so the guest must read US QWERTY
# or every key is remapped twice. gliff and SSH carry the client's own layout.
keymap=dvorak variant=dvorak
if systemd-detect-virt --quiet --vm; then
keymap=us variant=
fi

if [ "$(field 'VC Keymap')" != "$keymap" ]; then
sudo localectl set-keymap "$keymap"
fi

# localectl prints no X11 Variant row when the variant is unset.
if [ "$(field 'X11 Layout')" != "us" ] || [ "$(field 'X11 Model')" != "pc105" ] ||
[ "$(field 'X11 Variant')" != "dvorak" ] || [ "$(field 'X11 Options')" != "caps:none" ]; then
sudo localectl set-x11-keymap us pc105 dvorak caps:none
[ "$(field 'X11 Variant')" != "$variant" ] || [ "$(field 'X11 Options')" != "caps:none" ]; then
sudo localectl set-x11-keymap us pc105 "$variant" caps:none
fi

if [ "$(field 'System Locale')" != "LANG=en_US.UTF-8" ]; then
Expand Down
6 changes: 6 additions & 0 deletions modules/system/mise.linux.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ run = "./bootstrap.sh"
[tasks."check:system-sudoers"]
description = "Test sudoers with real visudo in an isolated Linux namespace"
run = "bash ./tests/test_sudoers.sh"

# Requires a non-root Linux account: bootstrap refuses root, which the Arch CI
# container runs as, so this stays out of the `test:*` wildcard too.
[tasks."check:system-keymap"]
description = "Test the Dvorak and virtual-machine US keymap choice against a stubbed localectl"
run = "bash ./tests/test_keymap.sh"
66 changes: 66 additions & 0 deletions modules/system/tests/test_keymap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
# Run the shipped bootstrap with stubbed sudo, localectl and systemd-detect-virt and check
# the layout it converges to on bare metal and in a virtual machine. Requires a non-root
# account, because bootstrap refuses root; nothing privileged or live is called.
set -euo pipefail

MODULE=$(cd "$(dirname "$0")/.." && pwd)
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
fail() { echo "FAIL: $*" >&2; exit 1; }
[ "$(/usr/bin/id -u)" -ne 0 ] || fail "run as a non-root account"
mkdir "$T/bin"

# sudo runs nothing: the sudoers step has its own test and udev must not be touched. It
# logs each localectl call with every argument bracketed, so an empty variant stays visible.
cat >"$T/bin/sudo" <<'EOF'
#!/usr/bin/env bash
[ "$1" = localectl ] || exit 0
shift
printf '[%s]' "$@" >>"$STUB_LOG"
echo >>"$STUB_LOG"
EOF
cat >"$T/bin/localectl" <<'EOF'
#!/usr/bin/env bash
cat "$STUB_STATUS"
EOF
cat >"$T/bin/systemd-detect-virt" <<'EOF'
#!/usr/bin/env bash
[ "$STUB_VM" = 1 ]
EOF
chmod +x "$T/bin"/*

# `localectl status` as systemd prints it: an unset X11 variant has no row.
cat >"$T/dvorak" <<'EOF'
System Locale: LANG=en_US.UTF-8
VC Keymap: dvorak
X11 Layout: us
X11 Model: pc105
X11 Variant: dvorak
X11 Options: caps:none
EOF
cat >"$T/us" <<'EOF'
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
X11 Model: pc105
X11 Options: caps:none
EOF

# $1 = 1 in a virtual machine, 0 on bare metal; $2 = the layout the machine has now;
# $3 = the localectl calls bootstrap must make, one per line.
check() {
: >"$T/log"
PATH="$T/bin:$PATH" STUB_VM="$1" STUB_STATUS="$T/$2" STUB_LOG="$T/log" \
bash "$MODULE/bootstrap.sh" >"$T/out" 2>&1 || { cat "$T/out" >&2; fail "vm=$1 from $2: bootstrap failed"; }
[ "$(cat "$T/log")" = "$3" ] || fail "vm=$1 from $2: localectl calls were: $(cat "$T/log")"
}

check 1 dvorak '[set-keymap][us]
[set-x11-keymap][us][pc105][][caps:none]'
check 1 us ''
check 0 us '[set-keymap][dvorak]
[set-x11-keymap][us][pc105][dvorak][caps:none]'
check 0 dvorak ''

echo "system keymap tests passed"
Loading