This commit is contained in:
caem 2025-01-22 02:18:47 +01:00
parent e38092ec4e
commit d6007cd0cd
Signed by: caem
GPG key ID: 69A830D03203405F
5 changed files with 53 additions and 34 deletions

View file

@ -34,7 +34,7 @@ args() {
echo " -o|--host [hostname] (required) The host from ./hosts you want to install"
echo " -b|--build Build the system without installing"
echo ""
echo "origin: https://github.com/c4em/dotnix"
echo "origin: https://github.com/c4em/caenix"
echo ""
exit 0
;;
@ -46,7 +46,7 @@ args() {
exit 1
fi
DOTNIX_INSTALL_DEVICE="$2"
CAENIX_INSTALL_DEVICE="$2"
shift 2
;;
@ -58,11 +58,11 @@ args() {
exit 1
fi
DOTNIX_HOSTNAME="$2"
CAENIX_HOSTNAME="$2"
shift 2
;;
"-b" | "--build")
DOTNIX_DO_ONLY_BUILD=1
CAENIX_DO_ONLY_BUILD=1
shift 1
;;
*)
@ -72,9 +72,9 @@ args() {
esac
done
args_ensure_is_set "--host" "$DOTNIX_HOSTNAME"
if [ -z "$DOTNIX_DO_ONLY_BUILD" ]; then
args_ensure_is_set "--device" "$DOTNIX_INSTALL_DEVICE"
args_ensure_is_set "--host" "$CAENIX_HOSTNAME"
if [ -z "$CAENIX_DO_ONLY_BUILD" ]; then
args_ensure_is_set "--device" "$CAENIX_INSTALL_DEVICE"
fi
}
@ -84,13 +84,13 @@ sed_safe () {
}
update_managed_values() {
sed -i 's/\( *device = \)".*"\(; #.*\)/\1"'"$(sed_safe "$DOTNIX_INSTALL_DEVICE")"'"\2/' "./hosts/$DOTNIX_HOSTNAME/default.nix"
sed -i 's/\( *device = \)".*"\(; #.*\)/\1"'"$(sed_safe "$DOTNIX_INSTALL_DEVICE")"'"\2/' "./hosts/$DOTNIX_HOSTNAME/disko.nix"
sed -i 's/\( *system.stateVersion = \)".*"\(; #.*\)/\1"'"$(sed_safe "$(nixos-version | cut -f1,2 -d '.')")"'"\2/' "./hosts/$DOTNIX_HOSTNAME/default.nix"
sed -i 's/\( *device = \)".*"\(; #.*\)/\1"'"$(sed_safe "$CAENIX_INSTALL_DEVICE")"'"\2/' "./hosts/$DOTNIX_HOSTNAME/default.nix"
sed -i 's/\( *device = \)".*"\(; #.*\)/\1"'"$(sed_safe "$CAENIX_INSTALL_DEVICE")"'"\2/' "./hosts/$DOTNIX_HOSTNAME/disko.nix"
sed -i 's/\( *system.stateVersion = \)".*"\(; #.*\)/\1"'"$(sed_safe "$(nixos-version | cut -f1,2 -d '.')")"'"\2/' "./hosts/$CAENIX_HOSTNAME/default.nix"
}
build() {
nix build ".#nixosConfigurations.${DOTNIX_HOSTNAME}.config.system.build.toplevel"
nix build ".#nixosConfigurations.${CAENIX_HOSTNAME}.config.system.build.toplevel"
}
permissions() {
@ -105,11 +105,11 @@ permissions() {
ensure_confirmation() {
printf "\e[1;31m=== ARE YOU SURE YOU WANT TO CONTINUE WITH THE INSTALLATION ===\e[0m\n\n"
printf "This will \e[1;31mIRREVERSIBLY\e[0m wipe all data in '%s'\n" "$DOTNIX_INSTALL_DEVICE"
printf "This will \e[1;31mIRREVERSIBLY\e[0m wipe all data in '%s'\n" "$CAENIX_INSTALL_DEVICE"
printf "This disk contains following partitions:\n\n"
lsblk -o NAME,SIZE,TYPE,FSTYPE "$DOTNIX_INSTALL_DEVICE"
lsblk -o NAME,SIZE,TYPE,FSTYPE "$CAENIX_INSTALL_DEVICE"
printf "\n"
lsblk -no NAME "$DOTNIX_INSTALL_DEVICE" | tail -n +2 | tr -cd '[:alnum:][:space:]' | xargs -I {} -- df -h "/dev/{}"
lsblk -no NAME "$CAENIX_INSTALL_DEVICE" | tail -n +2 | tr -cd '[:alnum:][:space:]' | xargs -I {} -- df -h "/dev/{}"
printf "\n"
printf "Please write 'Yes, do as I say!' to continue with the installation\n> "
@ -118,14 +118,14 @@ ensure_confirmation() {
echo "Cancelling installation"
exit 0
else
DOTNIX_CONFIRM_DISK_NUKE="yes"
CAENIX_CONFIRM_DISK_NUKE="yes"
fi
}
partition_disk() {
if [ "$DOTNIX_CONFIRM_DISK_NUKE" = "yes" ]; then
if [ "$CAENIX_CONFIRM_DISK_NUKE" = "yes" ]; then
sudo nix --experimental-features 'flakes nix-command' run github:nix-community/disko/latest -- \
--mode destroy,format,mount --yes-wipe-all-disks "./hosts/$DOTNIX_HOSTNAME/disko.nix"
--mode destroy,format,mount --yes-wipe-all-disks "./hosts/$CAENIX_HOSTNAME/disko.nix"
else
>&2 echo "Aborted installation due to invalid state in the partitioning step."
exit 1
@ -133,7 +133,7 @@ partition_disk() {
}
install() {
yes | sudo nixos-install --no-root-passwd --flake ".#$DOTNIX_HOSTNAME"
yes | sudo nixos-install --no-root-passwd --flake ".#$CAENIX_HOSTNAME"
}
copy_files_to_new_install() {
@ -145,7 +145,7 @@ copy_files_to_new_install() {
sudo cp -vr . /mnt/nix/config
sudo mkdir -p "/mnt/nix/persist/home/$username/programming"
sudo ln -svf /nix/config "/mnt/nix/persist/home/$username/programming/dotnix"
sudo ln -svf /nix/config "/mnt/nix/persist/home/$username/programming/caenix"
sudo chown -R 1000:100 "/mnt/nix/persist/home/$username"
sudo chown -R 1000:100 "/mnt/nix/config"
}
@ -162,8 +162,8 @@ main () {
args "$@"
permissions
if [ -n "$DOTNIX_DO_ONLY_BUILD" ]; then
if [ -n "$DOTNIX_INSTALL_DEVICE" ]; then
if [ -n "$CAENIX_DO_ONLY_BUILD" ]; then
if [ -n "$CAENIX_INSTALL_DEVICE" ]; then
update_managed_values
fi