aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpublic/install-nixos.sh67
-rw-r--r--public/template.nix6
-rwxr-xr-xscripts/burn-nixos.sh2
3 files changed, 68 insertions, 7 deletions
diff --git a/public/install-nixos.sh b/public/install-nixos.sh
index 311205f..f5bf321 100755
--- a/public/install-nixos.sh
+++ b/public/install-nixos.sh
@@ -1,9 +1,70 @@
#!/usr/bin/env nix-shell
-#!nix-shell --pure -i bash -p bash jq envsubst
+#!nix-shell --pure -i bash -p bash jq envsubst wget
# shellcheck shell=bash
set -Eeuo pipefail
-# download nix files before starting
-# generate local nix-file: get input for hostName
+end="\033[0m"
+
+green() {
+ green_color="\033[0;32m"
+ echo -e "${green_color}${1}${end}"
+}
+
+yellow() {
+ yellow_color="\033[0;33m"
+ echo -e "${yellow_color}${1}${end}"
+}
+
+blue() {
+ blue_color="\033[0;34m"
+ echo -e "${blue_color}${1}${end}"
+}
+
+red() {
+ red_color="\033[0;31m"
+ echo -e "${red_color}${1}${end}"
+}
+
+usage() {
+ red "Missing input argument $1.\n"
+ cat <<EOF
+Usage:
+ install-nixos.sh <HOST_NAME> <DEVICE>
+
+ Arguments
+ HOST_NAME The networking.hostName of the installation. Something like 'velhinho-nixos'.
+ DEVICE The LUKS device where to install to. Use lsblk or similar tools to get it's name.
+
+Examples:
+ Download install-nixos.sh and run it with 'velhinho-nixos' as hostName and '/dev/sda3' as LUKS device:
+ wget -O- https://euandre.org/dotfiles/install-nixos.sh | sh -s velhinho-nixos /dev/sda3
+EOF
+}
+
+HOST_NAME="${1:-}"
+DEVICE="${2:-}"
+
+[[ -z "${HOST_NAME}" ]] && {
+ usage 'HOST_NAME'
+ exit 2
+}
+
+[[ -z "${DEVICE}" ]] && {
+ usage 'DEVICE'
+ exit 2
+}
+
+SERVER="https://euandre.org/dotfiles"
+
+yellow "Downloading Nix files..."
+TMP_DIR="$(mktemp -d)"
+wget -O "${TMP_DIR}/configuration.nix" "${SERVER}/configuration.nix"
+wget -O "${TMP_DIR}/hardware-configuration.nix" "${SERVER}/hardware-configuration.nix"
+wget -O "${TMP_DIR}/template.nix" "${SERVER}/template.nix"
+green "Done."
+
+export HOST_NAME
+export DEVICE
+envsubst < "${TMP_DIR}/template.nix" > /etc/nixos/local-configuration.nix
# fdisk
diff --git a/public/template.nix b/public/template.nix
index b0da84f..5cfc9f8 100644
--- a/public/template.nix
+++ b/public/template.nix
@@ -1,6 +1,6 @@
{
- hostName = "$host_name";
- luksDevice = "$device";
+ hostName = "$HOST_NAME";
+ luksDevice = "$DEVICE";
passwordFile =
- "/home/andreh/dev/libre/dotfiles/encrypted/$host_name/password-hash.txt";
+ "/home/andreh/dev/libre/dotfiles/encrypted/$HOST_NAME/password-hash.txt";
}
diff --git a/scripts/burn-nixos.sh b/scripts/burn-nixos.sh
index 85ab9e2..b88ba79 100755
--- a/scripts/burn-nixos.sh
+++ b/scripts/burn-nixos.sh
@@ -2,7 +2,7 @@
set -Eeuo pipefail
usage() {
- red "Missing argument $1."
+ red "Missing argument $1.\n"
cat <<EOF
Usage:
burn-nixos.sh <NIXOS_URL> <USB_STICK>