From ae55d93acea8690fc1ee09b3359db3a57041df8f Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Wed, 24 Jan 2024 18:39:18 -0500
Subject: [PATCH] feat(vars): add different color schemes for starship prompt

---
 common/default.nix                    |  4 +--
 common/home/bash/default.nix          | 41 ++++++++++++------------
 common/nix-on-droid.nix               |  4 +--
 common/{vars.nix => vars/default.nix} | 29 ++++++++++++++++-
 common/vars/prompt-schemes.nix        | 45 +++++++++++++++++++++++++++
 devices/binto/default.nix             |  1 +
 devices/cluster/default.nix           |  6 ++++
 devices/servivi/default.nix           |  1 +
 devices/wim/default.nix               |  1 +
 9 files changed, 106 insertions(+), 26 deletions(-)
 rename common/{vars.nix => vars/default.nix} (59%)
 create mode 100644 common/vars/prompt-schemes.nix

diff --git a/common/default.nix b/common/default.nix
index 424753d1..b4797643 100644
--- a/common/default.nix
+++ b/common/default.nix
@@ -9,7 +9,7 @@
   ...
 } @ inputs: {
   imports = [
-    ./vars.nix
+    ./vars
 
     ./modules
     ./pkgs
@@ -65,7 +65,7 @@
     default = {
       imports = [
         # Make the vars be the same on Nix and HM
-        ./vars.nix
+        ./vars
         {vars = config.vars;}
 
         nur.hmModules.nur
diff --git a/common/home/bash/default.nix b/common/home/bash/default.nix
index 33880c4b..31fd4657 100644
--- a/common/home/bash/default.nix
+++ b/common/home/bash/default.nix
@@ -1,12 +1,10 @@
-{lib, ...}: let
-  inherit (lib) fileContents;
-
-  # TODO: have different colors depending on host
-  textColor = "#e3e5e5";
-  firstColor = "#bd93f9";
-  secondColor = "#715895";
-  thirdColor = "#382c4a";
-  fourthColor = "#120e18";
+{
+  config,
+  lib,
+  ...
+}: let
+  inherit (lib) concatStrings fileContents;
+  inherit (config.vars) promptColors;
 in {
   imports = [./programs.nix];
 
@@ -14,36 +12,37 @@ in {
     starship = {
       enable = true;
       enableBashIntegration = true;
+
       settings = {
-        format = lib.concatStrings [
+        format = concatStrings [
           "╭╴"
-          "[](fg:${firstColor})"
-          "[   ](bg:${firstColor} fg:#090c0c)"
-          "[](bg:${secondColor} fg:${firstColor})"
+          "[](fg:${promptColors.firstColor})"
+          "[   ](bg:${promptColors.firstColor} fg:#090c0c)"
+          "[](bg:${promptColors.secondColor} fg:${promptColors.firstColor})"
           "$username$hostname"
-          "[](fg:${secondColor} bg:${thirdColor})"
+          "[](fg:${promptColors.secondColor} bg:${promptColors.thirdColor})"
           "$directory"
-          "[](fg:${thirdColor} bg:${fourthColor})"
+          "[](fg:${promptColors.thirdColor} bg:${promptColors.fourthColor})"
           "$git_branch"
-          "[](fg:${fourthColor})"
+          "[](fg:${promptColors.fourthColor})"
           "\n╰╴$shlvl$nix_shell$character"
         ];
 
         username = {
           show_always = true;
-          style_user = "fg:${textColor} bg:${secondColor}";
-          style_root = "fg:red bg:${secondColor} blink";
+          style_user = "fg:${promptColors.textColor} bg:${promptColors.secondColor}";
+          style_root = "fg:red bg:${promptColors.secondColor} blink";
           format = "[ $user]($style)";
         };
 
         hostname = {
           ssh_only = false;
-          style = "fg:${textColor} bg:${secondColor}";
+          style = "fg:${promptColors.textColor} bg:${promptColors.secondColor}";
           format = "[@$hostname ]($style)";
         };
 
         directory = {
-          style = "fg:${firstColor} bg:${thirdColor}";
+          style = "fg:${promptColors.firstColor} bg:${promptColors.thirdColor}";
           format = "[ $path ]($style)";
           truncate_to_repo = false;
           truncation_length = 0;
@@ -57,7 +56,7 @@ in {
         };
 
         git_branch = {
-          style = "fg:${secondColor} bg:${fourthColor}";
+          style = "fg:${promptColors.secondColor} bg:${promptColors.fourthColor}";
           symbol = "";
           format = "[ $symbol $branch ]($style)";
         };
diff --git a/common/nix-on-droid.nix b/common/nix-on-droid.nix
index 4b0c6bb7..e7c7fd3a 100644
--- a/common/nix-on-droid.nix
+++ b/common/nix-on-droid.nix
@@ -4,7 +4,7 @@
   ...
 }: {
   imports = [
-    ./vars.nix
+    ./vars
     ./pkgs
     ./modules/global.nix
     nur.nixosModules.nur
@@ -39,7 +39,7 @@
   home-manager.config = {
     imports = [
       # Make the vars be the same on Nix and HM
-      ./vars.nix
+      ./vars
       {vars = config.vars;}
 
       nur.hmModules.nur
diff --git a/common/vars.nix b/common/vars/default.nix
similarity index 59%
rename from common/vars.nix
rename to common/vars/default.nix
index b4eb3afd..4bf0a401 100644
--- a/common/vars.nix
+++ b/common/vars/default.nix
@@ -21,6 +21,32 @@
       '';
     };
 
+    promptMainColor = mkOption {
+      type = types.enum ["red" "green" "blue" "purple"];
+      default = "purple";
+    };
+
+    promptColors = mkOption {
+      description = ''
+        Colors used in starship prompt
+      '';
+
+      default = import ./prompt-schemes.nix cfg.promptMainColor;
+
+      # FIXME: doesn't work when passing vars to home-manager
+      # readOnly = true;
+      type = with types;
+        submodule {
+          options = {
+            textColor = mkOption {type = str;};
+            firstColor = mkOption {type = str;};
+            secondColor = mkOption {type = str;};
+            thirdColor = mkOption {type = str;};
+            fourthColor = mkOption {type = str;};
+          };
+        };
+    };
+
     configDir = mkOption {
       type = types.str;
       default = "/home/${cfg.mainUser}/.nix/devices/${cfg.hostName}/config";
@@ -35,11 +61,12 @@
         The name of the main monitor used for Hyprland
         and Regreet which also uses Hyprland
       '';
+      # This is to allow a bash script to know wether this value exists
       default = "null";
     };
 
     greetdDupe = mkOption {
-      type = types.nullOr types.bool;
+      type = types.bool;
       description = ''
         If we should duplicate regreet on all monitors
       '';
diff --git a/common/vars/prompt-schemes.nix b/common/vars/prompt-schemes.nix
new file mode 100644
index 00000000..209d8d3f
--- /dev/null
+++ b/common/vars/prompt-schemes.nix
@@ -0,0 +1,45 @@
+color: let
+  schemes = {
+    "purple" = {
+      textColor = "#e3e5e5";
+      firstColor = "#bd93f9";
+      secondColor = "#715895";
+      thirdColor = "#382c4a";
+      fourthColor = "#120e18";
+    };
+
+    "green" = {
+      textColor = "#e3e5e5";
+      firstColor = "#78ae66";
+      secondColor = "#567c49";
+      thirdColor = "#334a2c";
+      fourthColor = "#11180e";
+    };
+
+    "red" = {
+      textColor = "#e3e5e5";
+      firstColor = "#9d0909";
+      secondColor = "#700707";
+      thirdColor = "#430404";
+      fourthColor = "#160101";
+    };
+
+    "blue" = {
+      textColor = "#e3e5e5";
+      firstColor = "#092a9d";
+      secondColor = "#071e70";
+      thirdColor = "#041243";
+      fourthColor = "#010616";
+    };
+
+    # Template
+    "color" = {
+      textColor = "#e3e5e5";
+      firstColor = "";
+      secondColor = "";
+      thirdColor = "";
+      fourthColor = "";
+    };
+  };
+in
+  schemes.${color}
diff --git a/devices/binto/default.nix b/devices/binto/default.nix
index 597a3fde..7dce410e 100644
--- a/devices/binto/default.nix
+++ b/devices/binto/default.nix
@@ -21,6 +21,7 @@ in {
   vars = {
     mainUser = "matt";
     hostName = "binto";
+    promptMainColor = "purple";
     mainMonitor = "desc:GIGA-BYTE TECHNOLOGY CO. LTD. G27QC 0x00000B1D";
     greetdDupe = false;
     fontSize = 12.5;
diff --git a/devices/cluster/default.nix b/devices/cluster/default.nix
index 9cad057e..204d3529 100644
--- a/devices/cluster/default.nix
+++ b/devices/cluster/default.nix
@@ -16,6 +16,12 @@ in {
   vars = {
     mainUser = "matt";
     hostName = deviceName;
+    promptMainColor =
+      if deviceName == "thingone"
+      then "green"
+      else if deviceName == "thingtwo"
+      then "red"
+      else "purple";
   };
 
   users.users.${mainUser} = {
diff --git a/devices/servivi/default.nix b/devices/servivi/default.nix
index 29f01c21..be183132 100644
--- a/devices/servivi/default.nix
+++ b/devices/servivi/default.nix
@@ -18,6 +18,7 @@ in {
   vars = {
     mainUser = "matt";
     hostName = "servivi";
+    promptMainColor = "blue";
   };
 
   users.users = {
diff --git a/devices/wim/default.nix b/devices/wim/default.nix
index d2d33e18..93f6963b 100644
--- a/devices/wim/default.nix
+++ b/devices/wim/default.nix
@@ -19,6 +19,7 @@ in {
   vars = {
     mainUser = "matt";
     hostName = "wim";
+    promptMainColor = "purple";
     fontSize = 12.5;
     mainMonitor = "eDP-1";
   };