-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·39 lines (28 loc) · 1.13 KB
/
setup.sh
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
#!/bin/bash
if ! command -v nix &> /dev/null
then
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
fi
# Path to your flake.nix file
FLAKE_FILE="$HOME/dotfiles/flake.nix"
# Get the current hostname
CURRENT_HOSTNAME=$(hostname -s)
CURRENT_USER=$(whoami)
echo "Current hostname: $CURRENT_HOSTNAME"
# Temporary file for sed operation
TEMP_FILE=$(mktemp)
sed -e "s/\"<host>\"/\"$CURRENT_HOSTNAME\"/g" \
-e "s/\"<user>\"/\"$CURRENT_USER\"/g" "$FLAKE_FILE" > "$TEMP_FILE"
mv "$TEMP_FILE" "$FLAKE_FILE"
echo "Hostname updated in flake.nix"
# Build and activate the configuration
nix --extra-experimental-features "nix-command flakes" build ".#darwinConfigurations.$CURRENT_HOSTNAME.system"
if [ -e ./result/sw/bin/darwin-rebuild ]; then
./result/sw/bin/darwin-rebuild switch --flake ".#$CURRENT_HOSTNAME"
else
echo "Error: darwin-rebuild not found in expected location. The build may have failed."
fi
sed -e "s/\"$CURRENT_HOSTNAME\"/\"<host>\"/g" \
-e "s/\"$CURRENT_USER\"/\"<user>\"/g" "$FLAKE_FILE" > "$TEMP_FILE"
mv "$TEMP_FILE" "$FLAKE_FILE"
echo "Hostname restored in flake.nix"