diff options
| author | sommerfeld <sommerfeld@sommerfeld.dev> | 2026-09-17 15:05:36 +0100 |
|---|---|---|
| committer | sommerfeld <sommerfeld@sommerfeld.dev> | 2026-09-17 15:05:36 +0100 |
| commit | aff435a0fb3a56b1d7b738c7dede363440884b3a (patch) | |
| tree | 07acb41d37760aa169ee42dbeb69da3621cc7489 /nix/switch.sh | |
| parent | a7f74c1fa4b89c5829f5896842eb7248c820704c (diff) | |
| download | dotfiles-aff435a0fb3a56b1d7b738c7dede363440884b3a.tar.gz dotfiles-aff435a0fb3a56b1d7b738c7dede363440884b3a.tar.bz2 dotfiles-aff435a0fb3a56b1d7b738c7dede363440884b3a.zip | |
Add the Canonical laptop profile and setup workflows
Diffstat (limited to 'nix/switch.sh')
| -rw-r--r-- | nix/switch.sh | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/nix/switch.sh b/nix/switch.sh new file mode 100644 index 0000000..ce63855 --- /dev/null +++ b/nix/switch.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -euo pipefail +root=$(cd "$(dirname "$0")/.." && pwd) +cd "$root" +source "$root/just-lib.sh" +profile=$(_machine_role) +if ! command -v nix >/dev/null 2>&1; then + [[ $profile != canonical ]] || { + echo 'Install upstream Nix first.' >&2 + exit 1 + } + echo 'Nix is not installed; skipping Home-Manager.' >&2 + exit 0 +fi +if [[ -n ${1:-} && $profile != "$1" ]]; then + echo "error: expected role $1, got $profile" >&2 + exit 1 +fi +export USER="${USER:-$(id -un)}" +export HOME="${HOME:?HOME must be set}" +generation=$(sh "$root/nix/with-github-auth.sh" \ + nix --extra-experimental-features 'nix-command flakes' build --impure \ + --no-link --print-out-paths "$root/nix#homeConfigurations.$profile.activationPackage") +HOME_MANAGER_BACKUP_EXT=backup "$generation/activate" +if [[ $profile != canonical ]]; then + shell="$HOME/.nix-profile/bin/zsh" + if ! grep -qxF "$shell" /etc/shells; then + printf '%s\n' "$shell" | sudo tee -a /etc/shells >/dev/null + fi + if [[ $(getent passwd "$USER" | cut -d: -f7) != "$shell" ]]; then + sudo chsh -s "$shell" "$USER" + fi +fi |
