From 0be7c27439b75a16cd340b4a72855a7cc6cec06a Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 7 Oct 2023 16:59:12 -0400 Subject: [PATCH] guix strap done (hopefully) --- guix-strap/guix-configure | 49 ++++++++++++++++++++++++++++++++++++ guix-strap/guix-env | 3 --- guix-strap/guix-install | 25 +++++++++++++++++++ guix-strap/guix-log | 13 ++++++++++ guix-strap/guix-partition | 13 ---------- guix-strap/guix-password | 51 ++++++++++++++++++++++++++++++++++++++ guix-strap/guix-setup | 9 +++++++ guix-strap/guix-setup-user | 21 ++++++++++++++++ guix-strap/system.scm | 23 +++++++++++++++++ 9 files changed, 191 insertions(+), 16 deletions(-) create mode 100755 guix-strap/guix-configure delete mode 100755 guix-strap/guix-env create mode 100755 guix-strap/guix-install create mode 100755 guix-strap/guix-password create mode 100755 guix-strap/guix-setup-user create mode 100644 guix-strap/system.scm diff --git a/guix-strap/guix-configure b/guix-strap/guix-configure new file mode 100755 index 0000000..f8a3cb6 --- /dev/null +++ b/guix-strap/guix-configure @@ -0,0 +1,49 @@ +#!/run/current-system/profile/bin/bash + +source ./guix-log +source ./guix-env + +HOSTNAME="" +CRYPT_UUID="" +EFI_UUID="" + +get_uuid() { + blkid -s UUID -o value $1 +} + +CRYPT_UUID=$(get_uuid $CRYPT_PARTITION) +EFI_UUID=$(get_uuid $EFI_PARTITION) + +get_hostname() { + CONFIRM="" + read -p "Enter system hostname: " HOSTNAME + if [ ! -z "$HOSTNAME" -a "$HOSTNAME" != " " ]; then + (confirm "$HOSTNAME"); + if [ "$?" -ne 0 ]; then + get_hostname + fi + else + ERROR "'$HOSTNAME' is not a valid hostname" + fi +} + +EVENT "Getting hostname" + +get_hostname + +EVENT "Hostname set to '$HOSTNAME'" + +EVENT "Generating system config file" + +cp system.scm "$HOSTNAME.scm" +sed -i "s/SED_CRYPT_UUID/$CRYPT_UUId/" ./$HOSTNAME.scm +sed -i "s/SED_EFI_UUID/$EFI_UUID/" ./$HOSTNAME.scm +sed -i "s/SED_HOSTNAME/$HOSTNAME/" ./$HOSTNAME.scm + +mv "$HOSTNAME.scm" .. + +EVENT "Successfully configured $HOSTNAME.scm" + +echo "HOSTNAME=\"$HOSTNAME\"" >> ./guix-env +echo "CRYPT_UUID=\"$CRYPT_UUID\"" >> ./guix-env +echo "EFI_UUID=\"$EFI_UUID\"" >> ./guix-env diff --git a/guix-strap/guix-env b/guix-strap/guix-env deleted file mode 100755 index 2caceae..0000000 --- a/guix-strap/guix-env +++ /dev/null @@ -1,3 +0,0 @@ -#!/run/current-system/profile/bin/bash - -# added by scripts during runtime!!! diff --git a/guix-strap/guix-install b/guix-strap/guix-install new file mode 100755 index 0000000..fbfb19a --- /dev/null +++ b/guix-strap/guix-install @@ -0,0 +1,25 @@ +#!/run/current-system/profile/bin/bash + +source ./guix-env +source ./guix-log + +EVENT "Mounting /gnu/store to destination disk..." +herd start cow-store /mnt + +EVENT "Installing non-guix signing keys for substitutes..." +curl -o /tmp/sign-key.pub https://substitutes.nonguix.org/signing-key.pub +guix archive --authorize < /tmp/sign-key.pub + +EVENT "Installing GNU Guix" +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 ../$HOSTNAME.scm /mnt + +EVENT "Installing User Environment" + +USER=tylerm +guix shell git -- git clone https://g.tylerm.dev/tylerm/dotfiles /mnt/home/$USER/.config/guix +cp ../$HOSTNAME.scm /mnt/home/$USER/.config/guix/$HOSTNAME.scm +cp ./guix-setup-user /mnt/home/$USER/.zprofile + +chown 1000:1000 -R /mnt/home/$USER + +EVENT "Successflly installed Guix root and user" diff --git a/guix-strap/guix-log b/guix-strap/guix-log index 4583127..0d26853 100755 --- a/guix-strap/guix-log +++ b/guix-strap/guix-log @@ -8,3 +8,16 @@ EVENT() { printf "\x1b[95m>>> \x1b[0m\x1b[98m$1\n" } +CONFIRM="" + +confirm() { + if [ "$CONFIRM" == "y" ]; then + exit 0 + fi + read -p "Are you sure: ($1)? [y/N] " CONFIRM + if [ "$CONFIRM" == "y" ]; then + exit 0 + else + exit 1 + fi +} diff --git a/guix-strap/guix-partition b/guix-strap/guix-partition index 6669129..7acaefd 100755 --- a/guix-strap/guix-partition +++ b/guix-strap/guix-partition @@ -2,7 +2,6 @@ set -o emacs; -CONFIRM="" DISK="" source ./guix-log @@ -10,18 +9,6 @@ source ./guix-env EVENT "Partitioning disks" -confirm() { - if [ "$CONFIRM" == "y" ]; then - exit 0 - fi - read -p "Are you sure: ($1)? [y/N] " CONFIRM - if [ "$CONFIRM" == "y" ]; then - exit 0 - else - exit 1 - fi -} - check_disk() { lsblk $1 &> /dev/null || exit 1 FS=$(df $1 | tail -n 1 | awk '{print $1}') diff --git a/guix-strap/guix-password b/guix-strap/guix-password new file mode 100755 index 0000000..008ad14 --- /dev/null +++ b/guix-strap/guix-password @@ -0,0 +1,51 @@ +#!/run/current-system/profile/bin/bash + +USER_PASSWORD="" +ROOT_PASSWORD="" + +source ./guix-env +source ./guix-log + +get_root_password() { + read -s -p "Root password: " PASSWORD + printf "\n" + read -s -p "Confirm password: " PASSWORD_CONFIRM + printf "\n" + if [ "$PASSWORD" == "$PASSWORD_CONFIRM" ]; then + ROOT_PASSWORD=$PASSWORD + return + else + ERROR "Passwords do not match" + get_root_password + fi +} + +get_user_password() { + read -s -p "User password: " PASSWORD + printf "\n" + read -s -p "Confirm password: " PASSWORD_CONFIRM + printf "\n" + if [ "$PASSWORD" == "$PASSWORD_CONFIRM" ]; then + USER_PASSWORD=$PASSWORD + return + else + ERROR "Passwords do not match" + get_user_password + fi +} + +EVENT "Setup /etc/shadow for root and user" + +get_root_password +get_user_password + +cat << EOF | chroot /mnt +passwd +$ROOT_PASSWORD +$ROOT_PASSWORD +passwd tylerm +$USER_PASSWORD +$USER_PASSWORD +EOF + +EVENT "Successfully set passwords" diff --git a/guix-strap/guix-setup b/guix-strap/guix-setup index bad7ce7..7fb027b 100755 --- a/guix-strap/guix-setup +++ b/guix-strap/guix-setup @@ -1,5 +1,8 @@ #!/run/current-system/profile/bin/bash +echo "#!/run/current-system/profile/bin/bash" > ./guix-env +echo "" > ./guix-env + welcome() { cat<<"EOF" ░░░ ░░░ @@ -32,3 +35,9 @@ EOF welcome ./guix-partition ./guix-crypt +./guix-configure +./guix-install +./guix-password + +echo "GNU Guix has been installed, you can now reboot..." +exit 0 diff --git a/guix-strap/guix-setup-user b/guix-strap/guix-setup-user new file mode 100755 index 0000000..5933116 --- /dev/null +++ b/guix-strap/guix-setup-user @@ -0,0 +1,21 @@ +#!/run/current-system/profile/bin/bash + +# This should run on user first logon, so let's a go! +# First, we should run a guix pull + +guix pull + +hash guix + +guix home -L ~/.config/guix/modules reconfigure ~/.config/guix/home-config/home-configuration.scm + +sudo -E herd restart nix-daemon + +nix-channel --update + +nix-shell '' -A install + +rm ~/.zprofile +source ~/.config/zsh/.zprofile + +home-manager switch diff --git a/guix-strap/system.scm b/guix-strap/system.scm new file mode 100644 index 0000000..722edef --- /dev/null +++ b/guix-strap/system.scm @@ -0,0 +1,23 @@ +(use-modules (home-config base-system) + (gnu)) + +(operating-system + (inherit base-operating-system) + (host-name "SED_HOSTNAME") + + (mapped-devices (list (mapped-device + (source (uuid + "SED_CRYPT_UUID")) + (target "cryptroot") + (type luks-device-mapping)))) + + (file-systems (cons* (file-system + (mount-point "/") + (device "/dev/mapper/cryptroot") + (type "btrfs") + (dependencies mapped-devices)) + (file-system + (mount-point "/boot/efi") + (device (uuid "SED_EFI_UUID" + 'fat32)) + (type "vfat")) %base-file-systems)))