[ubuntu] Onboard an ubuntu config.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
# Ubuntu machines
|
||||
|
||||
Ubuntu machines are managed in layers:
|
||||
|
||||
| Layer | Where | Applied by |
|
||||
|---|---|---|
|
||||
| User env: CLI tools, dotfiles, fonts, ssh hosts | `hosts/ubuntu/home.nix` | Home Manager |
|
||||
| Desktop apps (flatpak) | `services.flatpak` in `hosts/ubuntu/home.nix` | nix-flatpak, on HM activation |
|
||||
| OS packages | `apt-packages.txt` | `bootstrap.sh` |
|
||||
| Third-party apt repos (tailscale/docker) | `bootstrap.sh` | `bootstrap.sh` |
|
||||
| System config files | `etc/**`, mirrored into `/etc` | `bootstrap.sh` |
|
||||
| Self-updating tools from upstream installers (mise, herdr, tuicr) into `~/.local/bin` | `bootstrap.sh` | `bootstrap.sh tools` (kept up to date with update commands) |
|
||||
|
||||
## Fresh machine
|
||||
|
||||
```sh
|
||||
sudo apt install -y git curl
|
||||
git clone <this repo> ~/nixos
|
||||
~/nixos/ubuntu/bootstrap.sh
|
||||
sudo tailscale up
|
||||
# log out and back in
|
||||
```
|
||||
|
||||
After that:
|
||||
|
||||
- `homesw`: Home Manager only.
|
||||
- `syssw`: everything (same as running `bootstrap.sh`).
|
||||
|
||||
## Keyboard (keyd)
|
||||
|
||||
`etc/keyd/default.conf` applies to every keyboard except YubiKeys:
|
||||
|
||||
- Caps Lock and Left Control are swapped.
|
||||
- Left Alt and Left Meta are swapped, so the key next to space is Meta.
|
||||
- Meta+C, Meta+V and Meta+X copy, paste and cut. keyd sends Ctrl+Insert,
|
||||
Shift+Insert and Ctrl+X, the same as omarchy's Hyprland binds. These work
|
||||
in GTK/Qt apps, browsers and Electron. Ghostty gets the matching bindings
|
||||
in `home-modules/ghostty-config.nix`.
|
||||
|
||||
To test keyd: `sudo keyd.rvaiya monitor`. To bypass a broken config: press Backspace+Escape+Enter together, which kills keyd.
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] **YubiKey**: port `modules/nixos/yubikey` and `home-modules/sops.nix`. ykman and pcscd from apt, the udev rule plus yubikey-up/down scripts in `etc/`, the sops age key from cold storage, and the `id_yubikey` identity files in the ssh config.
|
||||
- [ ] **system-manager**: explore [numtide/system-manager](https://github.com/numtide/system-manager) to move `etc/` and the systemd service setup into Nix.
|
||||
@@ -0,0 +1,24 @@
|
||||
# Installed by bootstrap.sh. One package per line, # for comments.
|
||||
|
||||
# Shell:
|
||||
zsh
|
||||
|
||||
# Desktop:
|
||||
flatpak
|
||||
ghostty
|
||||
wl-clipboard
|
||||
|
||||
# Input:
|
||||
keyd
|
||||
logiops
|
||||
|
||||
# Containers:
|
||||
docker.io
|
||||
docker-buildx
|
||||
docker-compose-v2
|
||||
|
||||
# C toolchain:
|
||||
build-essential
|
||||
clang
|
||||
cmake
|
||||
pkg-config
|
||||
Executable
+186
@@ -0,0 +1,186 @@
|
||||
#!/usr/bin/env bash
|
||||
# Bootstrap / sync an Ubuntu machine from this repo. Idempotent: re-run it
|
||||
# whenever apt-packages.txt, ubuntu/etc/**, or the Home Manager config change.
|
||||
set -euo pipefail
|
||||
|
||||
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
HERE="$REPO/ubuntu"
|
||||
HM_TARGET="${HM_TARGET:-ubuntu}"
|
||||
ALL_STEPS=(nix repos apt etc services shell tools home)
|
||||
|
||||
# Tools installed with their upstream install script instead of Nix/apt.
|
||||
TOOLS=(
|
||||
"mise|https://mise.run"
|
||||
"herdr|https://herdr.dev/install.sh"
|
||||
"tuicr|https://tuicr.dev/install.sh"
|
||||
)
|
||||
|
||||
log() { printf '\n\033[1;34m==> %s\033[0m\n' "$*"; }
|
||||
info() { printf ' %s\n' "$*"; }
|
||||
|
||||
# Strip comments/blank lines from a list file.
|
||||
read_list() { sed -e 's/#.*//' -e 's/[[:space:]]*$//' -e '/^$/d' "$1"; }
|
||||
|
||||
step_nix() {
|
||||
log "nix"
|
||||
if command -v nix >/dev/null 2>&1; then
|
||||
info "already installed: $(nix --version)"
|
||||
return
|
||||
fi
|
||||
# Determinate's installer, but upstream Nix (makes it easier to uninstall if needed).
|
||||
curl -fsSL https://install.determinate.systems/nix \
|
||||
| sh -s -- install --no-confirm --prefer-upstream-nix
|
||||
# shellcheck disable=SC1091
|
||||
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
|
||||
}
|
||||
|
||||
step_repos() {
|
||||
log "third-party apt repos"
|
||||
local codename changed=0
|
||||
# shellcheck disable=SC1091
|
||||
codename="$(. /etc/os-release && echo "$VERSION_CODENAME")"
|
||||
|
||||
# Tailscale: https://tailscale.com/kb/1031/install-linux
|
||||
if [ ! -f /etc/apt/sources.list.d/tailscale.list ]; then
|
||||
curl -fsSL "https://pkgs.tailscale.com/stable/ubuntu/${codename}.noarmor.gpg" \
|
||||
| sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null
|
||||
curl -fsSL "https://pkgs.tailscale.com/stable/ubuntu/${codename}.tailscale-keyring.list" \
|
||||
| sudo tee /etc/apt/sources.list.d/tailscale.list >/dev/null
|
||||
changed=1
|
||||
fi
|
||||
info "tailscale repo present"
|
||||
|
||||
if [ "$changed" = 1 ]; then sudo apt-get update; fi
|
||||
}
|
||||
|
||||
step_apt() {
|
||||
log "apt packages"
|
||||
local pkgs=() missing=() p
|
||||
mapfile -t pkgs < <(read_list "$HERE/apt-packages.txt")
|
||||
pkgs+=(tailscale) # From step_repos.
|
||||
for p in "${pkgs[@]}"; do
|
||||
dpkg-query -W -f='${Status}' "$p" 2>/dev/null | grep -q 'install ok installed' \
|
||||
|| missing+=("$p")
|
||||
done
|
||||
if [ ${#missing[@]} -eq 0 ]; then
|
||||
info "all ${#pkgs[@]} packages installed"
|
||||
return
|
||||
fi
|
||||
info "installing: ${missing[*]}"
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y "${missing[@]}"
|
||||
}
|
||||
|
||||
# Copy ubuntu/etc/** to /etc. Only touches files that differ, and reloads the
|
||||
# daemons whose config changed. Removed files are orphaned.
|
||||
step_etc() {
|
||||
log "/etc files"
|
||||
local src rel dst changed=()
|
||||
while IFS= read -r -d '' src; do
|
||||
rel="${src#"$HERE/etc/"}"
|
||||
dst="/etc/$rel"
|
||||
if sudo cmp -s "$src" "$dst"; then
|
||||
info "unchanged $dst"
|
||||
continue
|
||||
fi
|
||||
if sudo test -e "$dst"; then
|
||||
sudo diff -u "$dst" "$src" || true
|
||||
fi
|
||||
sudo install -D -m 0644 -o root -g root "$src" "$dst"
|
||||
info "updated $dst"
|
||||
changed+=("$rel")
|
||||
done < <(find "$HERE/etc" -type f -print0 | sort -z)
|
||||
|
||||
local rel_changed
|
||||
for rel_changed in "${changed[@]}"; do
|
||||
case "$rel_changed" in
|
||||
keyd/*)
|
||||
# (Ubuntu ships the CLI as keyd.rvaiya)
|
||||
if systemctl is-active -q keyd.service; then sudo systemctl restart keyd.service && info "restarted keyd"; fi ;;
|
||||
logid.cfg)
|
||||
if systemctl is-active -q logid.service; then sudo systemctl restart logid.service && info "restarted logid"; fi ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
step_services() {
|
||||
log "system services"
|
||||
local unit
|
||||
for unit in keyd.service logid.service docker.service tailscaled.service; do
|
||||
if ! systemctl cat "$unit" >/dev/null 2>&1; then
|
||||
info "skip $unit (not installed)"
|
||||
continue
|
||||
fi
|
||||
if ! systemctl is-enabled -q "$unit" 2>/dev/null || ! systemctl is-active -q "$unit"; then
|
||||
sudo systemctl enable --now "$unit"
|
||||
fi
|
||||
info "running $unit"
|
||||
done
|
||||
|
||||
if getent group docker >/dev/null && ! id -nG "$USER" | grep -qw docker; then
|
||||
sudo usermod -aG docker "$USER"
|
||||
info "added $USER to docker group (log out/in to apply)"
|
||||
fi
|
||||
}
|
||||
|
||||
step_shell() {
|
||||
log "login shell"
|
||||
local want=/usr/bin/zsh current
|
||||
current="$(getent passwd "$USER" | cut -d: -f7)"
|
||||
if [ "$current" = "$want" ]; then
|
||||
info "already $want"
|
||||
return
|
||||
fi
|
||||
sudo chsh -s "$want" "$USER"
|
||||
info "changed $current -> $want (log out/in to apply)"
|
||||
}
|
||||
|
||||
step_tools() {
|
||||
log "self-installing tools (~/.local/bin)"
|
||||
local entry name url
|
||||
for entry in "${TOOLS[@]}"; do
|
||||
IFS='|' read -r name url <<<"$entry"
|
||||
# Also check ~/.local/bin directly: on a fresh machine this script may run from a shell that doesn't have it on PATH yet.
|
||||
if command -v "$name" >/dev/null 2>&1 || [ -x "$HOME/.local/bin/$name" ]; then
|
||||
info "already installed: $name"
|
||||
continue
|
||||
fi
|
||||
info "installing $name from $url"
|
||||
# TUICR_INSTALL_YES skips tuicr's confirmation prompt.
|
||||
curl -fsSL "$url" | TUICR_INSTALL_YES=1 sh
|
||||
done
|
||||
}
|
||||
|
||||
step_home() {
|
||||
log "home-manager ($HM_TARGET)"
|
||||
local out
|
||||
out="$(nix build --no-link --print-out-paths "$REPO#homeConfigurations.$HM_TARGET.activationPackage")"
|
||||
HOME_MANAGER_BACKUP_EXT=hm-backup "$out/activate"
|
||||
|
||||
if flatpak info --user app.zen_browser.zen >/dev/null 2>&1 \
|
||||
&& flatpak info --system app.zen_browser.zen >/dev/null 2>&1; then
|
||||
sudo flatpak uninstall --system -y --noninteractive app.zen_browser.zen
|
||||
info "removed system-wide Zen (user install takes over)"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local steps=("$@") s
|
||||
[ ${#steps[@]} -eq 0 ] && steps=("${ALL_STEPS[@]}")
|
||||
for s in "${steps[@]}"; do
|
||||
if ! declare -F "step_$s" >/dev/null; then
|
||||
echo "unknown step: $s (valid: ${ALL_STEPS[*]})" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
for s in "${steps[@]}"; do "step_$s"; done
|
||||
|
||||
log "done"
|
||||
cat <<'EOF'
|
||||
First run only:
|
||||
- sudo tailscale up
|
||||
- log out and back in (zsh login shell, docker group, keyd is live already)
|
||||
EOF
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -0,0 +1,23 @@
|
||||
# Managed by ~/nixos/ubuntu (bootstrap.sh etc). Local edits get overwritten.
|
||||
[ids]
|
||||
*
|
||||
# YubiKey enumerates as a keyboard, ignore it.
|
||||
-1050:0407
|
||||
# logid's virtual keyboard.
|
||||
-0000:0000:48cf0dd2
|
||||
|
||||
[main]
|
||||
# Caps Lock <-> Left Control.
|
||||
capslock = layer(control)
|
||||
leftcontrol = capslock
|
||||
# Left Alt <-> Left Meta.
|
||||
leftalt = layer(meta)
|
||||
leftmeta = layer(alt)
|
||||
|
||||
# macOS-style clipboard, same mapping as omarchy's Hyprland binds
|
||||
# (default/hypr/bindings/clipboard.conf), done in keyd instead.
|
||||
# Ctrl/Shift+Insert copy/paste in GTK, Qt, browsers, Electron, and terminals.
|
||||
[meta]
|
||||
c = C-insert
|
||||
v = S-insert
|
||||
x = C-x
|
||||
@@ -0,0 +1,69 @@
|
||||
// Managed by ~/nixos/ubuntu (bootstrap.sh etc). Local edits get overwritten.
|
||||
// Ported from hosts/nixbox/configuration.nix.
|
||||
devices: (
|
||||
{
|
||||
name: "Wireless Mouse MX Master 3";
|
||||
|
||||
hiresscroll: {
|
||||
};
|
||||
|
||||
thumbwheel: {
|
||||
invert: true;
|
||||
};
|
||||
|
||||
buttons: (
|
||||
{
|
||||
cid: 0x53;
|
||||
action =
|
||||
{
|
||||
type : "Keypress";
|
||||
keys: ["KEY_LEFTMETA", "KEY_LEFT"];
|
||||
};
|
||||
},
|
||||
{
|
||||
cid: 0x56;
|
||||
action =
|
||||
{
|
||||
type : "Keypress";
|
||||
keys: ["KEY_LEFTMETA", "KEY_RIGHT"];
|
||||
};
|
||||
}
|
||||
);
|
||||
},
|
||||
{
|
||||
name: "MX Vertical Advanced Ergonomic Mouse";
|
||||
|
||||
hiresscroll: {
|
||||
hires: true;
|
||||
invert: false;
|
||||
target: false;
|
||||
};
|
||||
|
||||
buttons: (
|
||||
{
|
||||
cid: 0x53;
|
||||
action =
|
||||
{
|
||||
type : "Keypress";
|
||||
keys: ["KEY_LEFTMETA", "KEY_PAGEUP"];
|
||||
};
|
||||
},
|
||||
{
|
||||
cid: 0x56;
|
||||
action =
|
||||
{
|
||||
type : "Keypress";
|
||||
keys: ["KEY_LEFTMETA", "KEY_PAGEDOWN"];
|
||||
};
|
||||
},
|
||||
{
|
||||
cid: 0xfd;
|
||||
action =
|
||||
{
|
||||
type : "Keypress";
|
||||
keys: ["KEY_LEFTMETA"];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user