My Nix Infra
nix
nixos
1#!/usr/bin/env bash
2
3set -e
4
5DOTFILES="$(dirname "$(dirname "$(realpath "$0")")")"
6
7if [[ "$#" != 1 ]]; then
8 echo "Usage: $0 <hostname>"
9 exit 1
10fi
11
12# validation
13for host in "$DOTFILES"/hosts/*; do
14 if [[ "$host" != *"$1" ]]; then
15 echo -n "Host $1 not found in "
16 ls "$DOTFILES/hosts"
17 exit 1
18 fi
19done
20
21# 1. Boot into NixOS installer, change passwd of current user
22passwd "$(whoami)"
23
24# 2. Check disk-config.nix
25read -rp "Checked ./hosts/$1/disk-config.nix? (y/n): " ans
26
27if [[ "$ans" == "n" ]]; then
28 echo "Please check disk-config.nix"
29 exit 1
30else
31 read -rp "Disk encryption passwd: " pw
32 echo -n "$pw" >/tmp/key
33fi
34
35# 3. Final NixOS install
36if [[ -f "$DOTFILES/hosts/$1/hardware-configuration.nix" ]]; then
37 nix run --extra-experimental-features 'nix-command flakes' \
38 github:nix-community/nixos-anywhere -- --flake .\#"$1" \
39 "$(whoami)"@localhost
40else
41 nix run --extra-experimental-features 'nix-command flakes' \
42 github:nix-community/nixos-anywhere -- --flake .\#"$1" \
43 --generate-hardware-config nixos-generate-config "$DOTFILES/hosts/$1/hardware-configuration.nix" \
44 "$(whoami)"@localhost
45fi