-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·224 lines (187 loc) · 5.17 KB
/
setup.sh
File metadata and controls
executable file
·224 lines (187 loc) · 5.17 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env bash
set -euo pipefail
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
# --- Get hostname ---
if [ -n "${1:-}" ]; then
HOSTNAME="$1"
else
read -rp "Hostname for this machine: " HOSTNAME
fi
if [ -z "$HOSTNAME" ]; then
echo "Error: hostname cannot be empty"
exit 1
fi
HOST_DIR="$REPO_DIR/hosts/$HOSTNAME"
if [ -d "$HOST_DIR" ]; then
echo "Error: hosts/$HOSTNAME already exists"
exit 1
fi
# --- Detect architecture ---
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) SYSTEM="x86_64-linux" ;;
aarch64) SYSTEM="aarch64-linux" ;;
*)
echo "Error: unsupported architecture: $ARCH"
exit 1
;;
esac
echo "Detected architecture: $SYSTEM"
# --- Detect bootloader type ---
if [ -d /sys/firmware/efi ]; then
BOOT_MODE="efi"
echo "Detected boot mode: EFI (systemd-boot)"
else
BOOT_MODE="bios"
echo "Detected boot mode: Legacy BIOS (GRUB)"
fi
# --- Pick home-manager config ---
echo ""
echo "Which home-manager config?"
echo " 1) home.nix (full — desktop with i3, kitty, pywal, etc.)"
echo " 2) hosts/aarch64/home.nix (arm — aarch64/UTM VM setup)"
read -rp "Choice [1/2]: " HOME_CHOICE
case "${HOME_CHOICE:-1}" in
1) HOME_MODULE="./home.nix" ;;
2) HOME_MODULE="./hosts/aarch64/home.nix" ;;
*)
echo "Error: invalid choice"
exit 1
;;
esac
# --- Generate hardware configuration ---
echo ""
echo "Generating hardware configuration (requires sudo)..."
mkdir -p "$HOST_DIR"
sudo nixos-generate-config --show-hardware-config > "$HOST_DIR/hardware-configuration.nix"
echo "Wrote hosts/$HOSTNAME/hardware-configuration.nix"
# --- Create configuration.nix ---
cat > "$HOST_DIR/configuration.nix" << 'NIXEOF'
{ config, lib, pkgs, ... }:
{
imports = [
./hardware-configuration.nix
];
# Bootloader
BOOTLOADER_PLACEHOLDER
# Networking
networking.hostName = "HOSTNAME_PLACEHOLDER";
networking.networkmanager.enable = true;
# Time and locale
time.timeZone = "Europe/London";
# Security
security.rtkit.enable = true;
# Audio (PipeWire)
services.pipewire = {
enable = true;
alsa.enable = true;
pulse.enable = true;
wireplumber.enable = true;
};
# Display and desktop
services.xserver.enable = true;
services.xserver.xkb.layout = "gb";
services.displayManager.defaultSession = "none+i3";
services.displayManager.sddm = {
enable = true;
theme = "sddm-astronaut-theme";
extraPackages = [
(pkgs.sddm-astronaut.override { embeddedTheme = "astronaut"; })
];
};
services.xserver.windowManager.i3 = {
enable = true;
package = pkgs.i3;
extraPackages = with pkgs; [
rofi
i3lock
kitty
dex
xss-lock
networkmanagerapplet
];
};
# Services
services.tailscale.enable = false;
# Users
users.users.sage = {
isNormalUser = true;
shell = pkgs.zsh;
extraGroups = [ "wheel" "networkmanager" "audio" ];
initialPassword = "changeme";
};
# System-wide programs
programs.zsh.enable = true;
programs.firefox = {
enable = true;
policies = {
ExtensionSettings = {
"tridactyl.vim@cmcaine.co.uk" = {
install_url = "https://addons.mozilla.org/firefox/downloads/latest/tridactyl-vim/latest.xpi";
installation_mode = "force_installed";
};
};
};
};
# System packages
environment.systemPackages = with pkgs; [
vim
wget
git
pamixer
playerctl
pavucontrol
brightnessctl
(sddm-astronaut.override { embeddedTheme = "astronaut"; })
];
# Environment variables
environment.sessionVariables = {
TERMINAL = "kitty";
};
# Allow unfree packages
nixpkgs.config.allowUnfree = true;
# Enable flakes
nix.settings.experimental-features = [ "nix-command" "flakes" ];
system.stateVersion = "25.05";
}
NIXEOF
sed -i "s/HOSTNAME_PLACEHOLDER/$HOSTNAME/" "$HOST_DIR/configuration.nix"
if [ "$BOOT_MODE" = "efi" ]; then
BOOT_CONFIG="boot.loader.systemd-boot.enable = true;\n boot.loader.efi.canTouchEfiVariables = true;"
else
BOOT_CONFIG="boot.loader.grub.enable = true;\n boot.loader.grub.device = \"/dev/sda\"; # adjust to your disk"
fi
sed -i "s|BOOTLOADER_PLACEHOLDER|$BOOT_CONFIG|" "$HOST_DIR/configuration.nix"
echo "Wrote hosts/$HOSTNAME/configuration.nix"
# --- Add entry to flake.nix ---
# Insert new host block before the final two closing braces
LAST_CONFIG_LINE=$(grep -n ' };' "$REPO_DIR/flake.nix" | tail -1 | cut -d: -f1)
FLAKE="$REPO_DIR/flake.nix"
TMPFLAKE="$FLAKE.tmp"
{
head -n "$LAST_CONFIG_LINE" "$FLAKE"
cat <<EOF
# $HOSTNAME
nixosConfigurations.$HOSTNAME = nixpkgs.lib.nixosSystem {
system = "$SYSTEM";
modules = [
./hosts/$HOSTNAME/configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.sage = import $HOME_MODULE;
}
];
};
EOF
tail -n +"$((LAST_CONFIG_LINE + 1))" "$FLAKE"
} > "$TMPFLAKE"
mv "$TMPFLAKE" "$FLAKE"
echo "Added $HOSTNAME to flake.nix"
# --- Summary ---
echo ""
echo "Setup complete! To build:"
echo " sudo nixos-rebuild switch --flake ~/nixos-config#$HOSTNAME"
echo ""
echo "Review and customize hosts/$HOSTNAME/configuration.nix as needed."