-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·48 lines (40 loc) · 1.78 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
#!/bin/bash
# Check if all the arguments are provided
if [ -z "$1" ]; then
echo "ERROR: Invalid disk. Please enter a valid disk to install NixOS on e.g. `/dev/sda`"
exit 1
fi
if [ -z "$2" ]; then
echo "ERROR: Invalid hostname. Please enter a valid hostname e.g. `neo`"
exit 1
fi
# Inform user that installation is starting
echo "Beginning NixOS installation with NixDots on disk `$1` with host `$2`..."
# Confirm disk selection (Optional, but a safety step)
echo "WARNING: All data on disk `$1` will be lost. Proceed? (y/n)"
read -n 1 -s response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "Aborted installation"
exit 1
fi
# Partition and format disks
echo "Partitioning and formatting the disk `$1`..."
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- -m disko --argstr device "$1" ./disko.nix
# Generate a new `hardware-configuration.nix` for the new system
echo "Generating hardware configuration..."
sudo nixos-generate-config --show-hardware-config --no-filesystems --root /mnt > hardware-configuration.nix
# Move NixDots to the new system - `/etc/nixos` by default but you can move it wherever you want after installing
echo "Copying NixDots to the new system..."
sudo mkdir -p /mnt/etc/nixos
sudo cp -r ./* /mnt/etc/nixos/
# Install NixOS - Replace `<hostname>` with the actual host to install e.g. `neo`
echo "Installing NixOS with the specified host `$2`..."
sudo nixos-install \
--flake /mnt/etc/nixos/#"$2" \
--option binary-caches https://hyprland.cachix.org \
--option trusted-public-keys hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=
# Installation complete
echo "NixDots is installed successfully! Press any key to power off"
echo "IMPORTANT: Remove the installation media before rebooting"
read -n 1 -s
systemctl poweroff