From f15cfcf16b80507e3d993d9dd15a4602318b2649 Mon Sep 17 00:00:00 2001
From: NullBite <me@nullbite.com>
Date: Sun, 14 Jan 2024 23:16:24 +0100
Subject: [PATCH] WIP: add some functions for more modular flake

---
 flake.nix | 37 ++++++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)

diff --git a/flake.nix b/flake.nix
index 7749655..81cf2d0 100644
--- a/flake.nix
+++ b/flake.nix
@@ -14,16 +14,27 @@
     # TODO once i have a better way to manage multiarch packages
     # 33.0.3p2 as suggested by https://xdaforums.com/t/guide-january-3-2024-root-pixel-7-pro-unlock-bootloader-pass-safetynet-both-slots-bootable-more.4505353/
     # android tools versions [ 34.0.0, 34.0.5 ) causes bootloops somehow and 34.0.5 isn't in nixpkgs yet
-    # pkg-android-tools.url = "github:NixOS/nixpkgs/55070e598e0e03d1d116c49b9eff322ef07c6ac6";
+    pkg-android-tools.url = "github:NixOS/nixpkgs/55070e598e0e03d1d116c49b9eff322ef07c6ac6";
   };
 
   outputs = { self, nixpkgs, nixpkgs-unstable, ... }@inputs: 
   let
+    inherit (self) outputs;
+    # inputs is already defined
+
     lib = nixpkgs.lib;
-    username = "nullbite";
     systems = [ "x86_64-linux" "aarch64-linux" ];
 
-    homeManagerModule = inputs.home-manager.nixosModules.home-manager;
+    ### Configuration
+    # My username
+    username = "nullbite";
+    # My current timezone for any mobile devices (i.e., my laptop)
+    mobileTimeZone = "Europe/Amsterdam";
+
+    # Variables to be passed to NixOS modules in the vars attrset
+    vars = {
+      inherit username mobileTimeZone;
+    };
 
     # This function produces a module that adds the home-manager module to the
     # system and configures the given module to the user's Home Manager
@@ -40,9 +51,25 @@
       };
     };
 
-    oldPkgs = {
-
+    mkExtraPkgs = system: {
+      android-tools = inputs.pkg-android-tools.legacyPackages.${system}.android-tools;
     };
+
+    mkSystem = system: hostname:
+      let
+        extraPkgs = mkExtraPkgs system;
+      in
+        lib.nixosSystem {
+          inherit system;
+          modules = [
+            ./hosts/${hostname}/configuration.nix
+            (homeManagerInit username (import ./hosts/${hostname}/home.nix))
+          ];
+          specialArgs = {
+            inherit inputs outputs vars extraPkgs;
+          };
+        };
+
   in {
     # for repl debugging via :lf .
     inherit inputs;