0xda157's home-manager and nixos config
1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p bash grep curl systemd git git-lfs
3
4set -euo pipefail
5
6grep -q 'NAME=NixOS' /etc/*-release || {
7 echo -e "\033[1m\e[31mYOU ARE NOT ON NIXOS, YOU SHOULDN'T BE RUNNING THIS SCRIPT\033[0m"
8 exit 1
9}
10
11mkdir -p ~/.config/nix
12echo "experimental-features = nix-command flakes pipe-operators" >>~/.config/nix/nix.conf
13
14lsblk
15echo "Which disk do you want to install to (eg /dev/sda)? " && read INSTALL_DISK
16systemd-ask-password "Enter your disk encryption password:" >/tmp/secret.key
17systemd-ask-password "Please confirm your password:" >/tmp/secret2.key
18[ $(cat /tmp/secret.key) = $(cat /tmp/secret2.key) ] || {
19 echo "Passwords don't match, please try again"
20 exit 1
21}
22
23echo "What is your desired host (eg enceladus)? " && read NEW_HOSTNAME
24
25curl https://codeberg.org/da157/nix-config/raw/branch/main/hosts/nixos/$NEW_HOSTNAME/disko.nix \
26 -o /tmp/disko.nix
27nix --experimental-features "nix-command flakes" run github:nix-community/disko \
28 -- -m destroy,format,mount /tmp/disko.nix \
29 --arg disk \"$INSTALL_DISK\" ||
30 {
31 echo "Disk formating failed, exiting"
32 exit 1
33 }
34
35mkdir -p /mnt/etc/nixos
36git clone https://codeberg.org/da157/nix-config.git /mnt/etc/nixos
37cd /mnt/etc/nixos
38
39read -p "Do you want to replace $NEW_HOSTNAME's hardware.nix? (y/n) " a
40[ "$a" = "y" ] && {
41 nixos-generate-config \
42 --root /mnt \
43 --show-hardware-config \
44 --no-filesystems \
45 >/mnt/etc/nixos/hosts/nixos/$NEW_HOSTNAME/hardware.nix
46 git add ./hosts/nixos/$NEW_HOSTNAME/hardware.nix
47}
48nixos-install \
49 --root "/mnt" \
50 --flake "git+file:///mnt/etc/nixos#$NEW_HOSTNAME"
51
52mv ~/.config/sops/age/keys.txt /mnt/home/da157/.config/sops/age/keys.txt