From 8715109e6e9f43df6ed001cad44e6a95473fc5a3 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Sat, 13 Jul 2024 10:59:09 +0200
Subject: [PATCH] Perform partitioning and repo-cloning in common setup

---
 scripts/Arch/OS/setup.fish   | 14 +++-----------
 scripts/Common/OS/setup.fish |  8 +++++++-
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/scripts/Arch/OS/setup.fish b/scripts/Arch/OS/setup.fish
index fe8fa0fe..f4a7a980 100644
--- a/scripts/Arch/OS/setup.fish
+++ b/scripts/Arch/OS/setup.fish
@@ -6,7 +6,7 @@ begin
 
     set -l mountDir (getConfig valhalla.partition.rootDir)
 
-    function setupOS -V dir -V CONFIG_MODULE -V mountDir
+    function setupOS -S -V dir -V CONFIG_MODULE -V mountDir
         source "$dir/../../Common/Scripts/hooks.fish"
         source "$dir/../../Common/Scripts/wait-network.fish"
 
@@ -16,11 +16,8 @@ begin
 
         waitNetwork
         and begin
-            set -l projectRoot (realpath "$dir/../../..")
-            set -l projectName (basename "$projectRoot")
-            set -l relativeDir (realpath --relative-to "$projectRoot" "$dir")
-            set -l tempRoot "/opt/$(basename "$projectName")"
-            set -l tempDir "$tempRoot/$relativeDir"
+            set -l relativeDir (realpath --relative-to "$dir/../../.." "$dir")
+            set -l tempDir "$PROJECT_CLONE_ROOT/$relativeDir"
 
             if set -l keyMap (getConfig valhalla.keyMap)
                 loadkeys "$keyMap"
@@ -30,8 +27,6 @@ begin
                 timedatectl set-timezone "$timezone"
             end
 
-            and CONFIG_MODULE=$CONFIG_MODULE bash "$dir/../../Common/OS/partition.sh"
-
             and pacman-key --init
             and pacman-key --populate
 
@@ -45,10 +40,7 @@ begin
                 texinfo
 
             and runHook installDrivers "Installing drivers…" || true
-
-            and "$dir/../../copy-repo.fish" "$mountDir$tempRoot"
             and genfstab -U "$mountDir" >> "$mountDir/etc/fstab"
-
             and arch-chroot "$mountDir" systemctl enable NetworkManager
 
             and if set -q timezone
diff --git a/scripts/Common/OS/setup.fish b/scripts/Common/OS/setup.fish
index 88f4e3d2..f457dca8 100644
--- a/scripts/Common/OS/setup.fish
+++ b/scripts/Common/OS/setup.fish
@@ -5,7 +5,13 @@ begin
     source "$dir/../Scripts/hooks.fish"
     set -l name (getConfig valhalla.setupUser.name)
     set -l mountDir (getConfig valhalla.partition.rootDir)
-    runHook setupOS || true
+    set -l projectRoot (realpath "$dir/../../..")
+    set -l projectName (basename "$projectRoot")
+    set -l PROJECT_CLONE_ROOT "/opt/$(basename "$projectName")"
+
+    CONFIG_MODULE=$CONFIG_MODULE bash "$dir/partition.sh"
+    and source "$dir/../../copy-repo.fish" "$mountDir$PROJECT_CLONE_ROOT"
+    and runHook setupOS || true
 
     and runHook createUser || \
         begin