-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
109 lines (94 loc) · 3.41 KB
/
install.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
# Colors for better output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}=== Nix and Nix-Darwin Configuration Setup ===${NC}"
echo "This script will install Nix, set up nix-darwin, and configure your personal variables."
echo
# Check if Nix is already installed
if command -v nix >/dev/null 2>&1; then
echo -e "${GREEN}✓ Nix is already installed${NC}"
else
echo -e "${YELLOW}Installing Nix...${NC}"
# Install Nix
sh <(curl -L https://nixos.org/nix/install) --daemon
# Source nix profile to make nix commands available in current shell
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
echo -e "${GREEN}✓ Nix installed successfully${NC}"
fi
# Enable flakes
echo -e "${YELLOW}Enabling Nix flakes...${NC}"
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >~/.config/nix/nix.conf
echo -e "${GREEN}✓ Nix flakes enabled${NC}"
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
VARIABLES_FILE="${SCRIPT_DIR}/variables.nix"
# Get hostname with default
current_hostname=$(hostname)
read -p "Hostname [default: ${current_hostname}]: " hostname
hostname=${hostname:-$current_hostname}
# Get username with default
current_user=$(whoami)
read -p "Username [default: ${current_user}]: " username
username=${username:-$current_user}
# Get home directory with smart default
default_home="/Users/${username}"
read -p "Home directory [default: ${default_home}]: " home_dir
home_dir=${home_dir:-$default_home}
# Get full name
read -p "Full name: " full_name
# Get email address
read -p "Email address: " email
# Generate the variables.nix file
cat >"${VARIABLES_FILE}" <<EOF
{
hostname = "${hostname}";
username = "${username}";
home = "${home_dir}";
fullName = "${full_name}";
email = "${email}";
}
EOF
echo -e "${GREEN}✓ Configuration saved to ${VARIABLES_FILE}${NC}"
echo
echo "Your configuration:"
echo -e " ${BLUE}Hostname:${NC} ${hostname}"
echo -e " ${BLUE}Username:${NC} ${username}"
echo -e " ${BLUE}Home directory:${NC} ${home_dir}"
echo -e " ${BLUE}Full name:${NC} ${full_name}"
echo -e " ${BLUE}Email:${NC} ${email}"
echo
# Check if nix-darwin is installed
if [ -e "/run/current-system/sw/bin/darwin-rebuild" ]; then
echo -e "${GREEN}✓ nix-darwin is already installed${NC}"
else
echo -e "${YELLOW}Installing nix-darwin...${NC}"
# Create the ~/.config/nix-darwin directory if it doesn't exist
mkdir -p ~/.config/nix-darwin
# Install nix-darwin
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer
./result/bin/darwin-installer
echo -e "${GREEN}✓ nix-darwin installed successfully${NC}"
fi
# Run nix-darwin switch with the flake
echo -e "${YELLOW}Applying nix-darwin configuration...${NC}"
if nix run nix-darwin -- switch --flake ~/.config/nix-darwin; then
echo -e "${GREEN}✓ nix-darwin configuration applied successfully${NC}"
else
echo -e "${RED}Failed to apply nix-darwin configuration. Please check for errors.${NC}"
exit 1
fi
echo
echo -e "${GREEN}Setup complete!${NC}"
echo "You can edit your variables directly in ${VARIABLES_FILE} or run this script again."
exit 1
fi
echo
echo -e "${GREEN}Setup complete!${NC}"
echo "You can edit your variables directly in ${VARIABLES_FILE} or run this script again."