feat: catchup local installer to remote

This commit is contained in:
Leon Schwarzäugl 2024-12-28 14:11:03 +01:00
parent 665abecc5b
commit cb47c8e13e
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
7 changed files with 347 additions and 64 deletions

View file

@ -1074,6 +1074,11 @@ In this section I am creating some attributes that define general concepts of my
program = "${self.packages.${system}.swarsel-install}/bin/swarsel-install"; program = "${self.packages.${system}.swarsel-install}/bin/swarsel-install";
}; };
postinstall = {
type = "app";
program = "${self.packages.${system}.swarsel-postinstall}/bin/swarsel-postinstall";
};
rebuild = { rebuild = {
type = "app"; type = "app";
program = "${self.packages.${system}.swarsel-rebuild}/bin/swarsel-rebuild"; program = "${self.packages.${system}.swarsel-rebuild}/bin/swarsel-rebuild";
@ -2176,6 +2181,7 @@ Note: The structure of generating the packages was changed in commit =2cf03a3 re
"bootstrap" "bootstrap"
"swarsel-rebuild" "swarsel-rebuild"
"swarsel-install" "swarsel-install"
"swarsel-postinstall"
"t2ts" "t2ts"
"ts2t" "ts2t"
"vershell" "vershell"
@ -3261,29 +3267,33 @@ This program sets up a new NixOS host locally.
set -eo pipefail set -eo pipefail
target_config="chaostheatre" target_config="chaostheatre"
target_hostname="chaostheatre"
target_user="swarsel" target_user="swarsel"
fs_type="ext4" persist_dir=""
disk="" disk_encryption=0
function help_and_exit() { function help_and_exit() {
echo echo
echo "Locally installs SwarselSystem on this machine." echo "Locally installs SwarselSystem on this machine."
echo echo
echo "USAGE: $0 -d <disk> [OPTIONS]" echo "USAGE: $0 -n <target_config> [OPTIONS]"
echo echo
echo "ARGS:" echo "ARGS:"
echo " -d <disk> specify disk to install on."
echo " -n <target_config> specify the nixos config to deploy." echo " -n <target_config> specify the nixos config to deploy."
echo " Default: chaostheatre" echo " Default: chaostheatre"
echo " Default: chaostheatre" echo " Default: chaostheatre"
echo " -u <target_user> specify user to deploy for." echo " -u <target_user> specify user to deploy for."
echo " Default: swarsel" echo " Default: swarsel"
echo " -t <fs_type> specify file system type to deploy for."
echo " Default: ext4"
echo " -h | --help Print this help." echo " -h | --help Print this help."
exit 0 exit 0
} }
function red() {
echo -e "\x1B[31m[!] $1 \x1B[0m"
if [ -n "${2-}" ]; then
echo -e "\x1B[31m[!] $($2) \x1B[0m"
fi
}
function green() { function green() {
echo -e "\x1B[32m[+] $1 \x1B[0m" echo -e "\x1B[32m[+] $1 \x1B[0m"
if [ -n "${2-}" ]; then if [ -n "${2-}" ]; then
@ -3302,19 +3312,12 @@ This program sets up a new NixOS host locally.
-n) -n)
shift shift
target_config=$1 target_config=$1
target_hostname=$1
;; ;;
-u) -u)
shift shift
target_user=$1 target_user=$1
;; ;;
-t)
shift
fs_type=$1
;;
-d)
shift
disk=$1
;;
-h | --help) help_and_exit ;; -h | --help) help_and_exit ;;
,*) ,*)
echo "Invalid option detected." echo "Invalid option detected."
@ -3324,14 +3327,59 @@ This program sets up a new NixOS host locally.
shift shift
done done
function cleanup() {
sudo rm -rf .cache/nix
sudo rm -rf /root/.cache/nix
}
trap cleanup exit
green "~SwarselSystems~ remote installer"
cd /home/"$target_user" cd /home/"$target_user"
sudo rm -rf /root/.cache/nix
sudo rm -rf .cache/nix sudo rm -rf .cache/nix
sudo rm -rf .dotfiles sudo rm -rf .dotfiles
green "Cloning repository from GitHub" green "Cloning repository from GitHub"
git clone https://github.com/Swarsel/.dotfiles.git git clone https://github.com/Swarsel/.dotfiles.git
green "Reading system information for $target_config ..."
DISK="$(nix eval --raw ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.rootDisk)"
green "Root Disk: $DISK"
CRYPTED="$(nix eval ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.isCrypted)"
if [[ $CRYPTED == "true" ]]; then
green "Encryption: ✓"
disk_encryption=1
else
red "Encryption: X"
disk_encryption=0
fi
IMPERMANENCE="$(nix eval ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.isImpermanence)"
if [[ $IMPERMANENCE == "true" ]]; then
green "Impermanence: ✓"
persist_dir="/persist"
else
red "Impermanence: X"
persist_dir=""
fi
SWAP="$(nix eval ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.isSwap)"
if [[ $SWAP == "true" ]]; then
green "Swap: ✓"
else
red "Swap: X"
fi
SECUREBOOT="$(nix eval ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.isSecureBoot)"
if [[ $SECUREBOOT == "true" ]]; then
green "Secure Boot: ✓"
else
red "Secure Boot: X"
fi
local_keys=$(ssh-add -L || true) local_keys=$(ssh-add -L || true)
pub_key=$(cat /home/"$target_user"/.dotfiles/secrets/keys/ssh/nbl-imba-2.pub) pub_key=$(cat /home/"$target_user"/.dotfiles/secrets/keys/ssh/nbl-imba-2.pub)
read -ra pub_arr <<< "$pub_key" read -ra pub_arr <<< "$pub_key"
@ -3346,33 +3394,38 @@ This program sets up a new NixOS host locally.
green "Valid SSH key found! Continuing with installation" green "Valid SSH key found! Continuing with installation"
fi fi
green "Creating /boot partition" if [ "$disk_encryption" -eq 1 ]; then
sudo parted -a optimal --script "$disk" mklabel gpt while true; do
sudo parted -a optimal --script "$disk" mkpart "boot" fat32 1MiB 1025MiB green "Set disk encryption passphrase:"
sudo parted -a optimal --script "$disk" set 1 esp on read -rs luks_passphrase
green "Please confirm passphrase:"
read -rs luks_passphrase_confirm
if [[ $luks_passphrase == "$luks_passphrase_confirm" ]]; then
echo "$luks_passphrase" > /tmp/disko-password
break
else
red "Passwords do not match"
fi
done
fi
green "Creating / partition" green "Setting up disk"
sudo parted -a optimal --script "$disk" mkpart "root" "$fs_type" 1025MiB 100% sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount --flake .#"$target_config" --yes-wipe-all-disks
sudo parted -a optimal --script "$disk" type 2 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709 sudo mkdir -p /mnt/"$persist_dir"/home/"$target_user"/
sudo cp -r /home/"$target_user"/.dotfiles /mnt/"$persist_dir"/home/"$target_user"/
green "Ensuring proper file systems" sudo chown -R 1000:100 /mnt/"$persist_dir"/home/"$target_user"
sudo mkfs.fat -F32 "$disk"1
sudo mkfs."${fs_type}" -F "$disk"2
green "Generating hardware configuration" green "Generating hardware configuration"
sudo mount "$disk"2 /mnt sudo nixos-generate-config --root /mnt --no-filesystems --dir /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/
sudo mkdir -p /mnt/boot
sudo mount "$disk"1 /mnt/boot green "Injecting initialSetup"
sudo nixos-generate-config --root /mnt --dir /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/ sudo sed -i '/ boot.extraModulePackages /a \ swarselsystems.initialSetup = true;' /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/hardware-configuration.nix
git add /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/hardware-configuration.nix git add /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/hardware-configuration.nix
# sudo rm -rf /root/.nix-defexpr/channels
# sudo rm -rf /nix/var/nix/profiles/per-user/channels
sudo mkdir -p /root/.local/share/nix/ sudo mkdir -p /root/.local/share/nix/
printf '{\"extra-substituters\":{\"https://nix-community.cachix.org\":true,\"https://nix-community.cachix.org https://cache.ngi0.nixos.org/\":true},\"extra-trusted-public-keys\":{\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=\":true,\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= cache.ngi0.nixos.org-1:KqH5CBLNSyX184S9BKZJo1LxrxJ9ltnY2uAs5c/f1MA=\":true}}' | sudo tee /root/.local/share/nix/trusted-settings.json > /dev/null printf '{\"extra-substituters\":{\"https://nix-community.cachix.org\":true,\"https://nix-community.cachix.org https://cache.ngi0.nixos.org/\":true},\"extra-trusted-public-keys\":{\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=\":true,\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= cache.ngi0.nixos.org-1:KqH5CBLNSyX184S9BKZJo1LxrxJ9ltnY2uAs5c/f1MA=\":true}}' | sudo tee /root/.local/share/nix/trusted-settings.json > /dev/null
green "Installing flake $target_config" green "Installing flake $target_config"
sudo nixos-install --flake .#"$target_config" sudo nixos-install --flake .#"$target_config"
yellow "Please keep in mind that this is only a demo of the configuration. Things might break unexpectedly."
green "Installation finished! Reboot to see changes" green "Installation finished! Reboot to see changes"
#+end_src #+end_src
@ -3388,6 +3441,100 @@ This program sets up a new NixOS host locally.
} }
#+end_src #+end_src
**** swarsel-postinstall
This program sets up a new NixOS host locally.
#+begin_src shell :tangle scripts/swarsel-postinstall.sh
set -eo pipefail
target_config="chaostheatre"
target_user="swarsel"
function help_and_exit() {
echo
echo "Locally installs SwarselSystem on this machine."
echo
echo "USAGE: $0 -d <disk> [OPTIONS]"
echo
echo "ARGS:"
echo " -d <disk> specify disk to install on."
echo " -n <target_config> specify the nixos config to deploy."
echo " Default: chaostheatre"
echo " Default: chaostheatre"
echo " -u <target_user> specify user to deploy for."
echo " Default: swarsel"
echo " -h | --help Print this help."
exit 0
}
function green() {
echo -e "\x1B[32m[+] $1 \x1B[0m"
if [ -n "${2-}" ]; then
echo -e "\x1B[32m[+] $($2) \x1B[0m"
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
-n)
shift
target_config=$1
;;
-u)
shift
target_user=$1
;;
-h | --help) help_and_exit ;;
,*)
echo "Invalid option detected."
help_and_exit
;;
esac
shift
done
function cleanup() {
sudo rm -rf .cache/nix
sudo rm -rf /root/.cache/nix
}
trap cleanup exit
sudo rm -rf .cache/nix
sudo rm -rf /root/.cache/nix
green "~SwarselSystems~ remote post-installer"
cd /home/"$target_user"/.dotfiles
SECUREBOOT="$(nix eval ~/.dotfiles#nixosConfigurations."$target_config".config.swarselsystems.isSecureBoot)"
if [[ $SECUREBOOT == "true" ]]; then
green "Setting up secure boot keys"
sudo mkdir -p /var/lib/sbctl
sbctl create-keys || true
sbctl enroll-keys --ignore-immutable --microsoft || true
fi
green "Disabling initialSetup"
sed -i '/swarselsystems\.initialSetup = true;/d' /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/hardware-configuration.nix
sudo nixos-rebuild --flake .#"$target_config" switch
green "Post-install finished!"
#+end_src
#+begin_src nix :tangle pkgs/swarsel-postinstall/default.nix
{ writeShellApplication, git }:
writeShellApplication {
name = "swarsel-postinstall";
runtimeInputs = [ git ];
text = builtins.readFile ../../scripts/swarsel-postinstall.sh;
}
#+end_src
**** t2ts **** t2ts
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: h:5ad99997-e54c-4f0b-9ab7-15f76b1e16e1 :CUSTOM_ID: h:5ad99997-e54c-4f0b-9ab7-15f76b1e16e1
@ -5679,6 +5826,7 @@ Normally, doing that also resets the lecture that happens on the first use of =s
"/etc/nix" "/etc/nix"
"/etc/NetworkManager/system-connections" "/etc/NetworkManager/system-connections"
# "/etc/secureboot" # "/etc/secureboot"
"/home/swarsel/.dotfiles"
"/var/db/sudo" "/var/db/sudo"
"/var/cache" "/var/cache"
"/var/lib" "/var/lib"

View file

@ -218,6 +218,11 @@
program = "${self.packages.${system}.swarsel-install}/bin/swarsel-install"; program = "${self.packages.${system}.swarsel-install}/bin/swarsel-install";
}; };
postinstall = {
type = "app";
program = "${self.packages.${system}.swarsel-postinstall}/bin/swarsel-postinstall";
};
rebuild = { rebuild = {
type = "app"; type = "app";
program = "${self.packages.${system}.swarsel-rebuild}/bin/swarsel-rebuild"; program = "${self.packages.${system}.swarsel-rebuild}/bin/swarsel-rebuild";

View file

@ -19,6 +19,7 @@ let
"bootstrap" "bootstrap"
"swarsel-rebuild" "swarsel-rebuild"
"swarsel-install" "swarsel-install"
"swarsel-postinstall"
"t2ts" "t2ts"
"ts2t" "ts2t"
"vershell" "vershell"

View file

@ -0,0 +1,7 @@
{ writeShellApplication, git }:
writeShellApplication {
name = "swarsel-postinstall";
runtimeInputs = [ git ];
text = builtins.readFile ../../scripts/swarsel-postinstall.sh;
}

View file

@ -75,6 +75,7 @@ in
"/etc/nix" "/etc/nix"
"/etc/NetworkManager/system-connections" "/etc/NetworkManager/system-connections"
# "/etc/secureboot" # "/etc/secureboot"
"/home/swarsel/.dotfiles"
"/var/db/sudo" "/var/db/sudo"
"/var/cache" "/var/cache"
"/var/lib" "/var/lib"

View file

@ -1,29 +1,33 @@
set -eo pipefail set -eo pipefail
target_config="chaostheatre" target_config="chaostheatre"
target_hostname="chaostheatre"
target_user="swarsel" target_user="swarsel"
fs_type="ext4" persist_dir=""
disk="" disk_encryption=0
function help_and_exit() { function help_and_exit() {
echo echo
echo "Locally installs SwarselSystem on this machine." echo "Locally installs SwarselSystem on this machine."
echo echo
echo "USAGE: $0 -d <disk> [OPTIONS]" echo "USAGE: $0 -n <target_config> [OPTIONS]"
echo echo
echo "ARGS:" echo "ARGS:"
echo " -d <disk> specify disk to install on."
echo " -n <target_config> specify the nixos config to deploy." echo " -n <target_config> specify the nixos config to deploy."
echo " Default: chaostheatre" echo " Default: chaostheatre"
echo " Default: chaostheatre" echo " Default: chaostheatre"
echo " -u <target_user> specify user to deploy for." echo " -u <target_user> specify user to deploy for."
echo " Default: swarsel" echo " Default: swarsel"
echo " -t <fs_type> specify file system type to deploy for."
echo " Default: ext4"
echo " -h | --help Print this help." echo " -h | --help Print this help."
exit 0 exit 0
} }
function red() {
echo -e "\x1B[31m[!] $1 \x1B[0m"
if [ -n "${2-}" ]; then
echo -e "\x1B[31m[!] $($2) \x1B[0m"
fi
}
function green() { function green() {
echo -e "\x1B[32m[+] $1 \x1B[0m" echo -e "\x1B[32m[+] $1 \x1B[0m"
if [ -n "${2-}" ]; then if [ -n "${2-}" ]; then
@ -42,19 +46,12 @@ while [[ $# -gt 0 ]]; do
-n) -n)
shift shift
target_config=$1 target_config=$1
target_hostname=$1
;; ;;
-u) -u)
shift shift
target_user=$1 target_user=$1
;; ;;
-t)
shift
fs_type=$1
;;
-d)
shift
disk=$1
;;
-h | --help) help_and_exit ;; -h | --help) help_and_exit ;;
*) *)
echo "Invalid option detected." echo "Invalid option detected."
@ -64,14 +61,59 @@ while [[ $# -gt 0 ]]; do
shift shift
done done
function cleanup() {
sudo rm -rf .cache/nix
sudo rm -rf /root/.cache/nix
}
trap cleanup exit
green "~SwarselSystems~ remote installer"
cd /home/"$target_user" cd /home/"$target_user"
sudo rm -rf /root/.cache/nix
sudo rm -rf .cache/nix sudo rm -rf .cache/nix
sudo rm -rf .dotfiles sudo rm -rf .dotfiles
green "Cloning repository from GitHub" green "Cloning repository from GitHub"
git clone https://github.com/Swarsel/.dotfiles.git git clone https://github.com/Swarsel/.dotfiles.git
green "Reading system information for $target_config ..."
DISK="$(nix eval --raw ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.rootDisk)"
green "Root Disk: $DISK"
CRYPTED="$(nix eval ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.isCrypted)"
if [[ $CRYPTED == "true" ]]; then
green "Encryption: ✓"
disk_encryption=1
else
red "Encryption: X"
disk_encryption=0
fi
IMPERMANENCE="$(nix eval ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.isImpermanence)"
if [[ $IMPERMANENCE == "true" ]]; then
green "Impermanence: ✓"
persist_dir="/persist"
else
red "Impermanence: X"
persist_dir=""
fi
SWAP="$(nix eval ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.isSwap)"
if [[ $SWAP == "true" ]]; then
green "Swap: ✓"
else
red "Swap: X"
fi
SECUREBOOT="$(nix eval ~/.dotfiles#nixosConfigurations."$target_hostname".config.swarselsystems.isSecureBoot)"
if [[ $SECUREBOOT == "true" ]]; then
green "Secure Boot: ✓"
else
red "Secure Boot: X"
fi
local_keys=$(ssh-add -L || true) local_keys=$(ssh-add -L || true)
pub_key=$(cat /home/"$target_user"/.dotfiles/secrets/keys/ssh/nbl-imba-2.pub) pub_key=$(cat /home/"$target_user"/.dotfiles/secrets/keys/ssh/nbl-imba-2.pub)
read -ra pub_arr <<< "$pub_key" read -ra pub_arr <<< "$pub_key"
@ -86,31 +128,36 @@ else
green "Valid SSH key found! Continuing with installation" green "Valid SSH key found! Continuing with installation"
fi fi
green "Creating /boot partition" if [ "$disk_encryption" -eq 1 ]; then
sudo parted -a optimal --script "$disk" mklabel gpt while true; do
sudo parted -a optimal --script "$disk" mkpart "boot" fat32 1MiB 1025MiB green "Set disk encryption passphrase:"
sudo parted -a optimal --script "$disk" set 1 esp on read -rs luks_passphrase
green "Please confirm passphrase:"
read -rs luks_passphrase_confirm
if [[ $luks_passphrase == "$luks_passphrase_confirm" ]]; then
echo "$luks_passphrase" > /tmp/disko-password
break
else
red "Passwords do not match"
fi
done
fi
green "Creating / partition" green "Setting up disk"
sudo parted -a optimal --script "$disk" mkpart "root" "$fs_type" 1025MiB 100% sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount --flake .#"$target_config" --yes-wipe-all-disks
sudo parted -a optimal --script "$disk" type 2 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709 sudo mkdir -p /mnt/"$persist_dir"/home/"$target_user"/
sudo cp -r /home/"$target_user"/.dotfiles /mnt/"$persist_dir"/home/"$target_user"/
green "Ensuring proper file systems" sudo chown -R 1000:100 /mnt/"$persist_dir"/home/"$target_user"
sudo mkfs.fat -F32 "$disk"1
sudo mkfs."${fs_type}" -F "$disk"2
green "Generating hardware configuration" green "Generating hardware configuration"
sudo mount "$disk"2 /mnt sudo nixos-generate-config --root /mnt --no-filesystems --dir /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/
sudo mkdir -p /mnt/boot
sudo mount "$disk"1 /mnt/boot green "Injecting initialSetup"
sudo nixos-generate-config --root /mnt --dir /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/ sudo sed -i '/ boot.extraModulePackages /a \ swarselsystems.initialSetup = true;' /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/hardware-configuration.nix
git add /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/hardware-configuration.nix git add /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/hardware-configuration.nix
# sudo rm -rf /root/.nix-defexpr/channels
# sudo rm -rf /nix/var/nix/profiles/per-user/channels
sudo mkdir -p /root/.local/share/nix/ sudo mkdir -p /root/.local/share/nix/
printf '{\"extra-substituters\":{\"https://nix-community.cachix.org\":true,\"https://nix-community.cachix.org https://cache.ngi0.nixos.org/\":true},\"extra-trusted-public-keys\":{\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=\":true,\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= cache.ngi0.nixos.org-1:KqH5CBLNSyX184S9BKZJo1LxrxJ9ltnY2uAs5c/f1MA=\":true}}' | sudo tee /root/.local/share/nix/trusted-settings.json > /dev/null printf '{\"extra-substituters\":{\"https://nix-community.cachix.org\":true,\"https://nix-community.cachix.org https://cache.ngi0.nixos.org/\":true},\"extra-trusted-public-keys\":{\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=\":true,\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= cache.ngi0.nixos.org-1:KqH5CBLNSyX184S9BKZJo1LxrxJ9ltnY2uAs5c/f1MA=\":true}}' | sudo tee /root/.local/share/nix/trusted-settings.json > /dev/null
green "Installing flake $target_config" green "Installing flake $target_config"
sudo nixos-install --flake .#"$target_config" sudo nixos-install --flake .#"$target_config"
yellow "Please keep in mind that this is only a demo of the configuration. Things might break unexpectedly."
green "Installation finished! Reboot to see changes" green "Installation finished! Reboot to see changes"

View file

@ -0,0 +1,74 @@
set -eo pipefail
target_config="chaostheatre"
target_user="swarsel"
function help_and_exit() {
echo
echo "Locally installs SwarselSystem on this machine."
echo
echo "USAGE: $0 -d <disk> [OPTIONS]"
echo
echo "ARGS:"
echo " -d <disk> specify disk to install on."
echo " -n <target_config> specify the nixos config to deploy."
echo " Default: chaostheatre"
echo " Default: chaostheatre"
echo " -u <target_user> specify user to deploy for."
echo " Default: swarsel"
echo " -h | --help Print this help."
exit 0
}
function green() {
echo -e "\x1B[32m[+] $1 \x1B[0m"
if [ -n "${2-}" ]; then
echo -e "\x1B[32m[+] $($2) \x1B[0m"
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
-n)
shift
target_config=$1
;;
-u)
shift
target_user=$1
;;
-h | --help) help_and_exit ;;
*)
echo "Invalid option detected."
help_and_exit
;;
esac
shift
done
function cleanup() {
sudo rm -rf .cache/nix
sudo rm -rf /root/.cache/nix
}
trap cleanup exit
sudo rm -rf .cache/nix
sudo rm -rf /root/.cache/nix
green "~SwarselSystems~ remote post-installer"
cd /home/"$target_user"/.dotfiles
SECUREBOOT="$(nix eval ~/.dotfiles#nixosConfigurations."$target_config".config.swarselsystems.isSecureBoot)"
if [[ $SECUREBOOT == "true" ]]; then
green "Setting up secure boot keys"
sudo mkdir -p /var/lib/sbctl
sbctl create-keys || true
sbctl enroll-keys --ignore-immutable --microsoft || true
fi
green "Disabling initialSetup"
sed -i '/swarselsystems\.initialSetup = true;/d' /home/"$target_user"/.dotfiles/hosts/nixos/"$target_config"/hardware-configuration.nix
sudo nixos-rebuild --flake .#"$target_config" switch
green "Post-install finished!"