guix-dotfiles/deploy.sh

114 lines
3.7 KiB
Bash
Raw Normal View History

2023-09-14 14:34:48 -04:00
#!/run/current-system/profile/bin/bash
2023-09-14 13:36:03 -04:00
gather_env() {
# Gather needed information
2023-12-28 01:14:23 -05:00
echo -n "Type 'eb' for encrypted w/ boot, 'en' for encrypted w/o boot, or 'd' for decrypted install: "
2023-09-14 13:36:03 -04:00
read install_type
echo -n "Type system hostname: "
read install_hostname
echo -n "Type device file for ROOT data: "
read root_dev
echo -n "Type device file for BOOT data: "
read boot_dev
echo -n "Type device file for SWAP: "
read swap_dev
2023-12-28 01:14:23 -05:00
echo -n "Add local device on network as substitute server? (y/n): "
read add_local_sub
if [ "$add_local_sub" == "y" ]
then
echo -n "Enter IP address of server: "
read substitute_ip
fi
2023-09-14 13:36:03 -04:00
}
copy_and_prepare() {
# Associate devs with uuids
root_uuid=`blkid $root_dev | awk -F\" '{print $2}'`
boot_uuid=`blkid $boot_dev | awk -F\" '{print $2}'`
swap_uuid=`blkid $swap_dev | awk -F\" '{print $2}'`
# Let's a go!
echo "Information gathered. Deploying Guix on $root_dev ($root_uuid) with boot on $boot_dev ($boot_uuid) and swap on $swap_dev ($swap_uuid)"
echo -n "Proceed? (y/n): "
read install_choice
if [ "$install_choice" != "y" ]
then
echo "Bailing!"
exit 1
fi
# We are installing!
# Copy template to root of repo
2023-12-28 01:14:23 -05:00
if [ "$install_type" == "eb" ]
2023-09-14 13:36:03 -04:00
then
2023-09-15 20:57:54 -04:00
cp ./modules/ryan-config/deploy-templates/HostTemplateEncrypted ./$install_hostname.scm
2023-09-14 13:36:03 -04:00
elif [ "$install_type" == "d" ]
then
2023-09-15 20:57:54 -04:00
cp ./modules/ryan-config/deploy-templates/HostTemplate ./$install_hostname.scm
2023-09-14 13:36:03 -04:00
else
2023-12-28 01:14:23 -05:00
echo "Invalid install type (not eb, en, or d), bailing!"
2023-09-14 13:36:03 -04:00
exit 1
fi
# Correct the information
sed -i "s/ChangeMe_ROOT/$root_uuid/" ./$install_hostname.scm
sed -i "s/ChangeMe_BOOTEFI/$boot_uuid/" ./$install_hostname.scm
sed -i "s/ChangeMe_SWAP/$swap_uuid/" ./$install_hostname.scm
sed -i "s/ChangeMe_HOST/$install_hostname/" ./$install_hostname.scm
# Install!
echo "Mounting /gnu/store to destination disk..."
herd start cow-store /mnt
2023-09-14 14:28:21 -04:00
# Install the non-guix signing keys
echo "Installing non-guix signing keys for substitutes..."
curl -o sign-key.pub https://substitutes.nonguix.org/signing-key.pub
guix archive --authorize < sign-key.pub
2023-12-28 01:14:23 -05:00
if [ "$add_local_sub" == "y" ]
then
echo "Installing local substitute server's signing keys"
curl -o local-sign.pub http://$substitute_ip/signing-key.pub
guix archive --authorize < local-sign.pub
fi
2023-09-14 19:57:05 -04:00
}
2023-09-14 14:28:21 -04:00
2023-09-14 19:57:05 -04:00
install_system() {
2023-09-14 13:36:03 -04:00
echo "Beginning install!"
2023-12-28 01:14:23 -05:00
if [ "$add_local_sub" == "y"]
then
guix time-machine -C ./channels.scm -- system -L ./modules --substitute-urls="http://$substitute_ip https://substitutes.nonguix.org https://bordeaux.guix.gnu.org https://ci.guix.gnu.org" init $install_hostname.scm /mnt
else
guix time-machine -C ./channels.scm -- system -L ./modules --substitute-urls="https://substitutes.nonguix.org https://bordeaux.guix.gnu.org https://ci.guix.gnu.org" init $install_hostname.scm /mnt
fi
2023-09-14 19:57:05 -04:00
}
install_user_env() {
# System should be installed now, we can chroot in and configure the user profile now
# NOTE: This assumes the user "ryan" for things, so change the USER var if you change your username
2023-09-15 17:00:17 -04:00
2023-09-15 20:57:54 -04:00
# Copy some files over to prepare for reboot
USER=ryan
guix shell git -- git clone https://git.stationery.faith/ryan77627/guix-dotfiles /mnt/home/$USER/.config/guix
2023-09-15 17:00:17 -04:00
2023-09-15 20:57:54 -04:00
cp ~/guix-dotfiles/$install_hostname.scm /mnt/home/$USER/.config/guix/$install_hostname.scm
cp ~/guix-dotfiles/modules/ryan-config/user_first_run.sh /mnt/home/$USER/.bashrc
2023-09-14 19:57:05 -04:00
2023-09-15 20:57:54 -04:00
chown 1000:1000 -R /mnt/home/ryan
2023-09-14 13:36:03 -04:00
}
gather_env
copy_and_prepare
2023-09-14 19:57:05 -04:00
install_system
install_user_env
2023-09-15 20:57:54 -04:00
# Reboot the machine at this point!
reboot