2022-11-30 02:37:28 +00:00
|
|
|
#!/usr/bin/env sh
|
2022-12-03 10:17:50 +00:00
|
|
|
## Configures a new nixos system to this repository
|
|
|
|
## Blame: Hung Tran (Pegasust) <pegasucksgg@gmail.com>
|
|
|
|
|
2022-11-30 02:37:28 +00:00
|
|
|
set -xv
|
|
|
|
|
|
|
|
HOSTNAME=${1}
|
|
|
|
|
|
|
|
if [ -z $HOSTNAME ]; then
|
2022-12-03 10:52:27 +00:00
|
|
|
current_hostname=$(hostname)
|
|
|
|
echo "Missing hostname as first param."
|
|
|
|
echo "Type the hostname you want to be here"
|
|
|
|
read -p "[${current_hostname}] > " HOSTNAME
|
|
|
|
HOSTNAME=${HOSTNAME:-${current_hostname}}
|
|
|
|
read -p "Using hostname: ${HOSTNAME}. Press ENTER to continue." _WHATEVER_
|
2022-11-30 02:37:28 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Where is this script located
|
|
|
|
SCRIPT_DIR=$(realpath $(dirname $0))
|
|
|
|
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
|
|
|
|
|
2022-12-03 00:01:48 +00:00
|
|
|
SYSNIX_DIR="${SCRIPT_DIR}/../nix-conf/system"
|
2022-11-30 02:37:28 +00:00
|
|
|
|
|
|
|
# Copy hardware-configuration of existing machine onto our version control
|
2022-11-30 02:58:57 +00:00
|
|
|
SYSNIX_PROF="${SYSNIX_DIR}/profiles/${HOSTNAME}"
|
|
|
|
HARDWARE_CONF="${SYSNIX_PROF}/hardware-configuration.nix"
|
2022-12-03 10:17:50 +00:00
|
|
|
if [ ! -f "${HARDWARE_CONF}" ]; then
|
2022-11-30 02:58:57 +00:00
|
|
|
mkdir "$SYSNIX_PROF"
|
2022-11-30 02:37:28 +00:00
|
|
|
sudo cp /etc/nixos/hardware-configuration.nix ${HARDWARE_CONF}
|
|
|
|
fi
|
2022-11-30 02:58:57 +00:00
|
|
|
git add "${HARDWARE_CONF}"
|
2022-11-30 02:37:28 +00:00
|
|
|
|
2022-12-22 23:04:04 +00:00
|
|
|
# Copy ssh/id-rsa details onto ssh/authorized_keys
|
|
|
|
SSH_PRIV="${HOME}/.ssh/id_rsa"
|
|
|
|
SSH_PUB="${SSH_PRIV}.pub"
|
|
|
|
SSH_DIR="${SCRIPT_DIR}/../ssh"
|
|
|
|
if [ ! -f "${SSH_PRIV}" ]; then
|
|
|
|
ssh-keygen -b 2048 -t rsa -f "${SSH_PRIV}" -q -N ""
|
|
|
|
fi
|
|
|
|
# idempotently adds to authorized_keys
|
|
|
|
cat "${SSH_PUB}" >> "${SSH_DIR}/authorized_keys"
|
|
|
|
# If we do this, then uniq is performed first :?
|
|
|
|
# sort "${SSH_DIR}/authorized_keys" | uniq >"${SSH_DIR}/authorized_keys"
|
|
|
|
sort "${SSH_DIR}/authorized_keys" | uniq | tee "${SSH_DIR}/authorized_keys"
|
|
|
|
cat "${SSH_DIR}/authorized_keys"
|
|
|
|
|
2022-11-30 02:37:28 +00:00
|
|
|
echo "Apply nixos-rebuild"
|
|
|
|
sudo nixos-rebuild switch --flake "${SYSNIX_DIR}#${HOSTNAME}"
|
|
|
|
|