-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
64 lines (56 loc) · 2.64 KB
/
Copy pathbootstrap.sh
File metadata and controls
64 lines (56 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
set -euo pipefail
DOTFILES_DIR="$HOME/dotfiles"
# Install Determinate Nix
if command -v nix >/dev/null 2>&1; then
echo " nix already installed, skipping"
else
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix \
| sh -s -- install --no-confirm
# shellcheck disable=SC1091
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
fi
# Symlink dotfiles
ln -sfn "$DOTFILES_DIR" ~/.dotfiles
echo "Personalize the configured username"
# Do this before any sudo call: sudo resets $USER to root, so whoami has to
# run as the real interactive user first.
REAL_USER="$(whoami)"
FLAKE_USER="$(sed -nE 's/^[[:space:]]*user = "([^"]+)";.*/\1/p' "$DIR/flake.nix" | head -n1)"
if [ -z "$FLAKE_USER" ]; then
echo " Could not find the single \"user = \" line in flake.nix."
echo " Edit flake.nix yourself before continuing."
exit 1
elif [ "$FLAKE_USER" != "$REAL_USER" ]; then
echo " flake.nix is configured for user \"$FLAKE_USER\", but you are \"$REAL_USER\"."
read -r -p " Rewrite flake.nix's \"user = \" line to \"$REAL_USER\"? [y/N] " REPLY
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
sed -i '' -E "s/^([[:space:]]*user = \")[^\"]+(\";.*)/\1${REAL_USER}\2/" "$DIR/flake.nix"
echo " Updated. Review the change with: git diff flake.nix"
else
echo " Skipped. Edit the single \"user = \" line in flake.nix yourself before continuing."
exit 1
fi
else
echo " flake.nix already matches \"$REAL_USER\", nothing to do."
fi
echo "First darwin-rebuild switch (pinned to nix-darwin-26.05)"
# darwin-rebuild doesn't exist yet on a fresh machine, so run it straight
# from the flake this once. After this, rebuild.sh works normally.
# This fetches the darwin-rebuild tool from the nix-darwin-26.05 release branch,
# not the exact flake.lock revision. The system config it applies is still pinned
# by this repo's flake.lock.
# sudo resets PATH to a secure default that excludes /nix/.../bin, so a
# freshly installed `nix` would not be found under sudo even though it's
# on PATH here. Resolve the absolute path first and invoke that instead.
NIX_BIN="$(command -v nix)"
# "mac" is the flake host label - if you renamed it, change it in flake.nix
# and rebuild.sh too.
sudo "$NIX_BIN" run github:nix-darwin/nix-darwin/nix-darwin-26.05#darwin-rebuild -- \
switch --flake ~/.dotfiles#mac
# If this still fails with "nix: command not found", open a new terminal
# (Determinate adds nix to new shells' PATH) and re-run ./bootstrap.sh.
# Run install script
cd "$DOTFILES_DIR"
bash install.sh
echo "Dotfiles installed! Restart Terminal or source your shell config. Use ./rebuild.sh for future changes."