summaryrefslogtreecommitdiff
path: root/installer
diff options
context:
space:
mode:
Diffstat (limited to 'installer')
-rwxr-xr-xinstaller/guix-configure49
-rwxr-xr-xinstaller/guix-crypt70
-rwxr-xr-xinstaller/guix-install25
-rwxr-xr-xinstaller/guix-log23
-rwxr-xr-xinstaller/guix-partition66
-rwxr-xr-xinstaller/guix-password51
-rwxr-xr-xinstaller/guix-setup43
-rwxr-xr-xinstaller/guix-setup-user21
-rw-r--r--installer/system.scm23
9 files changed, 371 insertions, 0 deletions
diff --git a/installer/guix-configure b/installer/guix-configure
new file mode 100755
index 0000000..b96c3c1
--- /dev/null
+++ b/installer/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/installer/guix-crypt b/installer/guix-crypt
new file mode 100755
index 0000000..b25bc99
--- /dev/null
+++ b/installer/guix-crypt
@@ -0,0 +1,70 @@
+#!/run/current-system/profile/bin/bash
+
+source ./guix-log
+source ./guix-env
+
+CRYPT_PARTITION=""
+EFI_PARTITION=""
+PASSWORD=""
+PASSWORD_CONFIRM=""
+
+EVENT "Setting up disk encryption with luks"
+
+if [[ $DISK == "/dev/sd"* ]]; then
+ CRYPT_PARTITION="$DISK""2"
+ EFI_PARTITION="$DISK""1"
+elif [[ $DISK == "/dev/vd"* ]]; then
+ CRYPT_PARTITION="$DISK""2"
+ EFI_PARTITION="$DISK""1"
+elif [[ $DISK == "/dev/nvme"* ]]; then
+ CRYPT_PARTITION="$DISK""p2"
+ EFI_PARTITION="$DISK""p1"
+else
+ ERROR "Unsupported drive type, must be sata or nvme!"
+ exit 1
+fi
+
+get_password() {
+ read -s -p "LUKS password: " PASSWORD
+ printf "\n"
+ read -s -p "Confirm password: " PASSWORD_CONFIRM
+ printf "\n"
+ if [ "$PASSWORD" == "$PASSWORD_CONFIRM" ]; then
+ return
+ else
+ ERROR "Passwords do not match"
+ get_password
+ fi
+}
+
+get_password
+
+EVENT "Setting up luks"
+
+cryptsetup luksFormat --type luks1 "$CRYPT_PARTITION" <<EOF
+$PASSWORD
+$PASSWORD_CONFIRM
+EOF
+
+EVENT "Opening root"
+
+cryptsetup open "$CRYPT_PARTITION" root <<EOF
+$PASSWORD
+EOF
+
+EVENT "Setting up root btrfs"
+
+mkfs.btrfs "/dev/mapper/root"
+
+EVENT "Mounting root"
+
+mount /dev/mapper/root /mnt
+
+EVENT "Setting up EFI vfat"
+
+mkfs.vfat "-F32" "$EFI_PARTITION"
+
+EVENT "Successfully setup efi vfat and luks"
+
+echo "CRYPT_PARTITION=\"$CRYPT_PARTITION\"" >> ./guix-env
+echo "EFI_PARTITION=\"$EFI_PARTITION\"" >> ./guix-env
diff --git a/installer/guix-install b/installer/guix-install
new file mode 100755
index 0000000..3b3cb14
--- /dev/null
+++ b/installer/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=freya
+guix shell git -- git clone https://g.freya.cat/freya/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/installer/guix-log b/installer/guix-log
new file mode 100755
index 0000000..0d26853
--- /dev/null
+++ b/installer/guix-log
@@ -0,0 +1,23 @@
+#!/run/current-system/profile/bin/bash
+
+ERROR() {
+ >&2 printf "\x1b[91mError: \x1b[0m\x1b[98m$1\n"
+}
+
+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/installer/guix-partition b/installer/guix-partition
new file mode 100755
index 0000000..7acaefd
--- /dev/null
+++ b/installer/guix-partition
@@ -0,0 +1,66 @@
+#!/run/current-system/profile/bin/bash
+
+set -o emacs;
+
+DISK=""
+
+source ./guix-log
+source ./guix-env
+
+EVENT "Partitioning disks"
+
+check_disk() {
+ lsblk $1 &> /dev/null || exit 1
+ FS=$(df $1 | tail -n 1 | awk '{print $1}')
+ if [ "$FS" == "none" ]; then
+ exit 0
+ else
+ exit 1
+ fi
+}
+
+get_disk() {
+ CONFIRM=""
+ read -ep "Enter disk (e.g. /dev/sda): " DISK
+ if [ ! -b "$DISK" ]; then
+ ERROR "$DISK: file does not exist"
+ get_disk
+ return
+ fi
+ (check_disk "$DISK");
+ if [ "$?" -ne 0 ]; then
+ ERROR "$DISK: not a valid disk"
+ get_disk
+ return
+ fi
+ (confirm "$DISK");
+ if [ "$?" -ne 0 ]; then
+ get_disk
+ fi
+}
+
+get_disk
+
+EVENT "Partitioning disks with fdisk..."
+
+fdisk "$DISK" <<EOF
+g
+n
+
+
++1GiB
+t
+EFI System
+n
+
+
+
+t
+2
+Linux Filesystem
+w
+EOF
+
+echo "DISK=\"$DISK\"" >> ./guix-env
+
+EVENT "Disks have been successfully partitioned on $DISK"
diff --git a/installer/guix-password b/installer/guix-password
new file mode 100755
index 0000000..a39c566
--- /dev/null
+++ b/installer/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 freya
+$USER_PASSWORD
+$USER_PASSWORD
+EOF
+
+EVENT "Successfully set passwords"
diff --git a/installer/guix-setup b/installer/guix-setup
new file mode 100755
index 0000000..7fb027b
--- /dev/null
+++ b/installer/guix-setup
@@ -0,0 +1,43 @@
+#!/run/current-system/profile/bin/bash
+
+echo "#!/run/current-system/profile/bin/bash" > ./guix-env
+echo "" > ./guix-env
+
+welcome() {
+ cat<<"EOF"
+ ░░░ ░░░
+ ░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░
+ ░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░
+ ░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░
+ ░▒▒▒▒░ ░░░░░░
+ ▒▒▒▒▒ ░░░░░░
+ ▒▒▒▒▒ ░░░░░
+ ░▒▒▒▒▒ ░░░░░
+ ▒▒▒▒▒ ░░░░░
+ ▒▒▒▒▒ ░░░░░
+ ░▒▒▒▒▒░░░░░
+ ▒▒▒▒▒▒░░░
+ ▒▒▒▒▒▒░
+ ____ _ _ _____ __ ____ _
+ / ___| | | |_ _\ \/ / / ___|| |_ _ __ __ _ _ __
+ | | _| | | || | \ / \___ \| __| '__/ _` | '_ \
+ | |_| | |_| || | / \ ___) | |_| | | (_| | |_) |
+ \____|\___/|___/_/\_\ |____/ \__|_| \__,_| .__/
+ |_|
+This script installs GNU Guix on your system
+
+https://www.gnu.org/software/guix/
+EOF
+ echo -n "Press return to continue..."
+ read -r ANSWER
+}
+
+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/installer/guix-setup-user b/installer/guix-setup-user
new file mode 100755
index 0000000..5933116
--- /dev/null
+++ b/installer/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 '<home-manager>' -A install
+
+rm ~/.zprofile
+source ~/.config/zsh/.zprofile
+
+home-manager switch
diff --git a/installer/system.scm b/installer/system.scm
new file mode 100644
index 0000000..af791c5
--- /dev/null
+++ b/installer/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 "root")
+ (type luks-device-mapping))))
+
+ (file-systems (cons* (file-system
+ (mount-point "/")
+ (device "/dev/mapper/root")
+ (type "btrfs")
+ (dependencies mapped-devices))
+ (file-system
+ (mount-point "/boot/efi")
+ (device (uuid "SED_EFI_UUID"
+ 'fat32))
+ (type "vfat")) %base-file-systems)))