From 4aaf01ca212d9a2afdad330ffd078abb7a93e166 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 1 Jun 2019 17:40:02 -0300 Subject: Move NixOS public files into public/nixos/ folder --- public/configuration.nix | 1 - public/hardware-configuration.nix | 1 - public/install-nixos.sh | 141 -------------------------------------- public/nixos/configuration.nix | 1 + public/nixos/install.sh | 141 ++++++++++++++++++++++++++++++++++++++ public/nixos/template.nix | 6 ++ public/template.nix | 6 -- 7 files changed, 148 insertions(+), 149 deletions(-) delete mode 120000 public/configuration.nix delete mode 120000 public/hardware-configuration.nix delete mode 100755 public/install-nixos.sh create mode 120000 public/nixos/configuration.nix create mode 100755 public/nixos/install.sh create mode 100644 public/nixos/template.nix delete mode 100644 public/template.nix diff --git a/public/configuration.nix b/public/configuration.nix deleted file mode 120000 index f0b535b..0000000 --- a/public/configuration.nix +++ /dev/null @@ -1 +0,0 @@ -../nixos/configuration.nix \ No newline at end of file diff --git a/public/hardware-configuration.nix b/public/hardware-configuration.nix deleted file mode 120000 index 6ebf69f..0000000 --- a/public/hardware-configuration.nix +++ /dev/null @@ -1 +0,0 @@ -../nixos/hardware-configuration.nix \ No newline at end of file diff --git a/public/install-nixos.sh b/public/install-nixos.sh deleted file mode 100755 index 5e160da..0000000 --- a/public/install-nixos.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell --pure -i bash -p bash jq envsubst wget utillinux -# shellcheck shell=bash -set -Eeuo pipefail - -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 < - - 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/sda' as disk device: - curl https://euandre.org/dotfiles/install-nixos.sh > install-nixos.sh - chmod +x install-nixos.sh - ./install-nixos.sh velhinho-nixos /dev/sda -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}/template.nix" "${SERVER}/template.nix" -green "Done." - -yellow "Creating content of '/etc/nixos/local-configuration.nix'..." -export HOST_NAME -export DEVICE -envsubst < "${TMP_DIR}/template.nix" > "${TMP_DIR}/local-configuration.nix" -blue "$(cat "${TMP_DIR}/local-configuration.nix")" -read -p "Confirm content of '/etc/nixos/local-configuration.nix'? (y/N) " -n 1 -r -echo # Move to a new line -if [[ ! $REPLY =~ ^[Yy]$ ]]; then - red "Unconfirmed content of '/etc/nixos/local-configuration.nix'." - red "Exitting." - exit 1 -fi -green "Done." - -yellow "Moving presented content to '/etc/nixos/local-configuration.nix'..." -mv "${TMP_DIR}/local-configuration.nix" /etc/nixos/local-configuration.nix -green "Done." - -yellow "Wiping '${DEVICE}'and partitioning it..." -wipefs --all --force "${DEVICE}" -sgdisk --clear "${DEVICE}" # Unclear the v -sgdisk --zap-all "${DEVICE}" # order here ^ -sgdisk --mbrtogpt "${DEVICE}" -sgdisk --new 1:2048:4095 --change-name 1:"BIOS boot partition" --typecode 1:EF02 "${DEVICE}" -sgdisk --new 2:4096:1028095 --change-name 2:"EFI System" --typecode 2:EF00 "${DEVICE}" -sgdisk --new 3:1028095:0 --change-name 3:"Linux LVM" --typecode 3:8E00 "${DEVICE}" -sgdisk --print "${DEVICE}" -green "Done." - -yellow "Configuring LUKS encryption on '${DEVICE}3'..." -cryptsetup luksFormat "${DEVICE}3" -cryptsetup luksOpen "${DEVICE}3" enc-pv -pvcreate /dev/mapper/enc-pv -vgcreate vg /dev/mapper/enc-pv -lvcreate -n swap vg -L 10G -lvcreate -n root vg -l 100%FREE -green "Done." - -yellow "Formatting '${DEVICE}'..." -mkfs.vfat -n BOOT "${DEVICE}2" -mkfs.ext4 -L root /dev/vg/root -mkswap -L swap /dev/vg/swap -green "Done." - -yellow "Mounting and activating swap..." -mount /dev/vg/root /mnt -mkdir /mnt/boot -mount "${DEVICE}2" /mnt/boot -swapon /dev/vg/swap -green "Done." - -yellow "Generating '/etc/nixos/*' Nix files'..." -nixos-generate-config --root /mnt -mv /etc/nixos/configuration.nix /etc/nixos/bkp-configuration.nix -mv "${TMP_DIR}/configuration.nix" /etc/nixos/configuration.nix -green "Done." - -yellow "Generating password-hash.txt file for user login..." -while true; do - read -s -p "Password: " password - echo - read -s -p "Password (again): " password_confirmation - echo - [ "$password" = "$password_confirmation" ] && break - red "Please try again" -done -mkpasswd -m sha-512 "$password" > /etc/nixos/password-hash.txt -green "Done." - -yellow "Installing NixOS!" -nixos-install -green "Done." - -yellow "Rebooting..." -reboot diff --git a/public/nixos/configuration.nix b/public/nixos/configuration.nix new file mode 120000 index 0000000..8f24f66 --- /dev/null +++ b/public/nixos/configuration.nix @@ -0,0 +1 @@ +../../nixos/configuration.nix \ No newline at end of file diff --git a/public/nixos/install.sh b/public/nixos/install.sh new file mode 100755 index 0000000..5e160da --- /dev/null +++ b/public/nixos/install.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env nix-shell +#!nix-shell --pure -i bash -p bash jq envsubst wget utillinux +# shellcheck shell=bash +set -Eeuo pipefail + +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 < + + 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/sda' as disk device: + curl https://euandre.org/dotfiles/install-nixos.sh > install-nixos.sh + chmod +x install-nixos.sh + ./install-nixos.sh velhinho-nixos /dev/sda +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}/template.nix" "${SERVER}/template.nix" +green "Done." + +yellow "Creating content of '/etc/nixos/local-configuration.nix'..." +export HOST_NAME +export DEVICE +envsubst < "${TMP_DIR}/template.nix" > "${TMP_DIR}/local-configuration.nix" +blue "$(cat "${TMP_DIR}/local-configuration.nix")" +read -p "Confirm content of '/etc/nixos/local-configuration.nix'? (y/N) " -n 1 -r +echo # Move to a new line +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + red "Unconfirmed content of '/etc/nixos/local-configuration.nix'." + red "Exitting." + exit 1 +fi +green "Done." + +yellow "Moving presented content to '/etc/nixos/local-configuration.nix'..." +mv "${TMP_DIR}/local-configuration.nix" /etc/nixos/local-configuration.nix +green "Done." + +yellow "Wiping '${DEVICE}'and partitioning it..." +wipefs --all --force "${DEVICE}" +sgdisk --clear "${DEVICE}" # Unclear the v +sgdisk --zap-all "${DEVICE}" # order here ^ +sgdisk --mbrtogpt "${DEVICE}" +sgdisk --new 1:2048:4095 --change-name 1:"BIOS boot partition" --typecode 1:EF02 "${DEVICE}" +sgdisk --new 2:4096:1028095 --change-name 2:"EFI System" --typecode 2:EF00 "${DEVICE}" +sgdisk --new 3:1028095:0 --change-name 3:"Linux LVM" --typecode 3:8E00 "${DEVICE}" +sgdisk --print "${DEVICE}" +green "Done." + +yellow "Configuring LUKS encryption on '${DEVICE}3'..." +cryptsetup luksFormat "${DEVICE}3" +cryptsetup luksOpen "${DEVICE}3" enc-pv +pvcreate /dev/mapper/enc-pv +vgcreate vg /dev/mapper/enc-pv +lvcreate -n swap vg -L 10G +lvcreate -n root vg -l 100%FREE +green "Done." + +yellow "Formatting '${DEVICE}'..." +mkfs.vfat -n BOOT "${DEVICE}2" +mkfs.ext4 -L root /dev/vg/root +mkswap -L swap /dev/vg/swap +green "Done." + +yellow "Mounting and activating swap..." +mount /dev/vg/root /mnt +mkdir /mnt/boot +mount "${DEVICE}2" /mnt/boot +swapon /dev/vg/swap +green "Done." + +yellow "Generating '/etc/nixos/*' Nix files'..." +nixos-generate-config --root /mnt +mv /etc/nixos/configuration.nix /etc/nixos/bkp-configuration.nix +mv "${TMP_DIR}/configuration.nix" /etc/nixos/configuration.nix +green "Done." + +yellow "Generating password-hash.txt file for user login..." +while true; do + read -s -p "Password: " password + echo + read -s -p "Password (again): " password_confirmation + echo + [ "$password" = "$password_confirmation" ] && break + red "Please try again" +done +mkpasswd -m sha-512 "$password" > /etc/nixos/password-hash.txt +green "Done." + +yellow "Installing NixOS!" +nixos-install +green "Done." + +yellow "Rebooting..." +reboot diff --git a/public/nixos/template.nix b/public/nixos/template.nix new file mode 100644 index 0000000..53bb695 --- /dev/null +++ b/public/nixos/template.nix @@ -0,0 +1,6 @@ +{ + hostName = "$HOST_NAME"; + luksDevice = "$DEVICE"; + passwordFile = + "/etc/nixos/password-hash.txt"; +} diff --git a/public/template.nix b/public/template.nix deleted file mode 100644 index 53bb695..0000000 --- a/public/template.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - hostName = "$HOST_NAME"; - luksDevice = "$DEVICE"; - passwordFile = - "/etc/nixos/password-hash.txt"; -} -- cgit v1.2.3