From a27b90af9eddd992f68a823a711ca5ff3ba8d05f Mon Sep 17 00:00:00 2001
From: Matei Adriel <rafaeladriel11@gmail.com>
Date: Fri, 11 Mar 2022 00:49:44 +0200
Subject: [PATCH] feat: useless feature which makes the theme change based on
 an env var

---
 dotfiles/neovim/lua/my/options.lua            |  3 ---
 modules/applications/alacritty.nix            | 12 +++++----
 modules/applications/neovim.nix               |  9 ++++---
 modules/applications/shells/aliases.nix       |  2 +-
 .../applications/shells/sessionVariables.nix  |  6 ++++-
 modules/applications/xmonad/Main.hs           | 15 ++++++++---
 modules/helpers.nix                           |  2 +-
 modules/overlays/flakes.nix                   |  1 -
 modules/themes/githubVariant.nix              | 25 +++++++++++--------
 modules/themes/themes.nix                     | 10 +++-----
 10 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/dotfiles/neovim/lua/my/options.lua b/dotfiles/neovim/lua/my/options.lua
index f95d801..fdf771b 100644
--- a/dotfiles/neovim/lua/my/options.lua
+++ b/dotfiles/neovim/lua/my/options.lua
@@ -31,9 +31,6 @@ function M.setup()
 
     -- Set leader
     helpers.global("mapleader", "<Space>")
-
-    -- Set theme
-    -- require('github-theme').setup({theme_style = "light", dark_float = true, transparent = true})
 end
 
 return M
diff --git a/modules/applications/alacritty.nix b/modules/applications/alacritty.nix
index f40508d..c70e482 100644
--- a/modules/applications/alacritty.nix
+++ b/modules/applications/alacritty.nix
@@ -4,14 +4,16 @@ let
   themes = pkgs.myThemes;
 
   createTheme = (theme: {
-    xdg.configFile."alacritty/themes/${theme.name}.yml".text = builtins.toJSON
-      (lib.attrs.recursiveUpdate theme.alacritty.settings {
-        import = [ "~/.config/alacritty/alacritty.yml" ];
-      });
+    xdg.configFile."alacritty/themes/${theme.name}.yml".text =
+      builtins.toJSON
+        (lib.attrsets.recursiveUpdate theme.alacritty.settings {
+          import = theme.alacritty.settings.import ++ [ "~/.config/alacritty/alacritty.yml" ];
+        });
   });
 
   createThemeConfigs = lib.lists.foldr
-    (acc: theme: lib.attrs.recursiveUpdate acc (createTheme theme))
+    (theme: acc: lib.attrsets.recursiveUpdate acc (createTheme theme)
+    )
     { }
     themes;
 in
diff --git a/modules/applications/neovim.nix b/modules/applications/neovim.nix
index ef1f155..8d0677b 100644
--- a/modules/applications/neovim.nix
+++ b/modules/applications/neovim.nix
@@ -11,7 +11,7 @@ let
   themePlugins = lib.lists.concatMap (theme: theme.neovim.plugins) themes;
 
   loadTheme = (theme: ''
-    if currentTheme = "${theme.name}" then
+    if currentTheme == "${theme.name}" then
       ${theme.neovim.theme}
 
       vim.g.lualineTheme = ${theme.neovim.lualineTheme}
@@ -19,12 +19,12 @@ let
   '');
 
   loadThemes = ''
+    lua << EOF
     local currentTheme = os.getenv("THEME");
 
     ${pkgs.myHelpers.mergeLines (lib.lists.forEach themes loadTheme)};
+    EOF
   '';
-
-
 in
 {
   home-manager.users.adrielus.programs.neovim = {
@@ -32,6 +32,7 @@ in
     package = pkgs.neovim-nightly;
 
     extraConfig = ''
+      ${loadThemes}
       luafile ${config-nvim}/init.lua
     '';
 
@@ -57,7 +58,7 @@ in
     ];
 
     plugins = with pkgs.vimPlugins;
-      with pkgs.vimExtraPlugins; with pkgs.myVimPlugins; themePlugins + [
+      with pkgs.vimExtraPlugins; with pkgs.myVimPlugins; themePlugins ++ [
         config-nvim # my neovim config
         nvim-lspconfig # configures lsps for me
         nvim-autopairs # close pairs for me
diff --git a/modules/applications/shells/aliases.nix b/modules/applications/shells/aliases.nix
index 9613d4f..a87623e 100644
--- a/modules/applications/shells/aliases.nix
+++ b/modules/applications/shells/aliases.nix
@@ -24,5 +24,5 @@
   # Render git repo using gource
   "git-render" = "gource -f -s 1 -c 4 --key";
 
-  alacritty = "alacritty --config-file $XDG_CONFIG_HOME/alacritty/themes/$THEME.yml";
+  alacritty = "alacritty --config-file ~/.config/alacritty/themes/$THEME.yml";
 }
diff --git a/modules/applications/shells/sessionVariables.nix b/modules/applications/shells/sessionVariables.nix
index b79204b..bf37c1e 100644
--- a/modules/applications/shells/sessionVariables.nix
+++ b/modules/applications/shells/sessionVariables.nix
@@ -1,6 +1,7 @@
 { ... }:
 with import ../../../secrets.nix;
 let
+  theme = "github-dark";
   variables = {
     # Configure github cli
     GITHUB_USERNAME = "Mateiadrielrafael";
@@ -10,7 +11,10 @@ let
     EDITOR = "nvim";
 
     # Sets the current theme used by all programs
-    THEME = "github-light";
+    THEME = theme;
+
+    # Common command for launching alacritty with the correct theme
+    # LAUNCH_ALACRITTY = "alacritty --config-file ~/.config/alacritty/themes/$THEME.yml";
   };
 in
 {
diff --git a/modules/applications/xmonad/Main.hs b/modules/applications/xmonad/Main.hs
index 634b461..6a80614 100644
--- a/modules/applications/xmonad/Main.hs
+++ b/modules/applications/xmonad/Main.hs
@@ -1,7 +1,11 @@
 {-# LANGUAGE BlockArguments #-}
 
+import System.Environment
+import System.Process
+
 import Control.Monad (join)
 import Data.Function ((&))
+
 import XMonad
 import XMonad.Actions.SpawnOn
 import XMonad.Config (defaultConfig)
@@ -71,6 +75,9 @@ main =
             manageWorkspaces
           ]
 
+    spawnTerminal = do
+      spawn "fish -c 'alacritty --config-file ~/.config/alacritty/themes/$THEME.yml'"
+
     myTerminal = "alacritty"
     myBrowser = "google-chrome-stable"
 
@@ -78,9 +85,8 @@ main =
     keymap =
       [ ("M-p", spawn "rofi -show run"),
         ("M-g", spawn myBrowser),
-        ("M-d", spawn "Discord"),
-        ("M-s", spawn "slack"),
-        ("M-r", spawn "ksysgurad")
+        ("M-s", spawnTerminal),
+        ("M-d", spawn "Discord")
       ]
 
     uniformBorder = join $ join $ join Border
@@ -95,8 +101,9 @@ main =
 
     startup :: X ()
     startup = do
-      spawn "xwallpaper --zoom ./picutres/portal.png"
+      spawn "xwallpaper --zoom ./background.jpg"
 
 -- spawn "Discord"
 -- spawn "google-chrome-stable"
 -- spawn "alacritty"
+
diff --git a/modules/helpers.nix b/modules/helpers.nix
index 8ed12f7..5f84b6c 100644
--- a/modules/helpers.nix
+++ b/modules/helpers.nix
@@ -1,5 +1,5 @@
 { lib, ... }: {
-  mergeLines = (lines: lib.foldr
+  mergeLines = (lines: lib.lists.foldr
     (a: b: ''
       ${a}
       ${b}
diff --git a/modules/overlays/flakes.nix b/modules/overlays/flakes.nix
index 22edf56..8acb35d 100644
--- a/modules/overlays/flakes.nix
+++ b/modules/overlays/flakes.nix
@@ -11,7 +11,6 @@
 , fish-theme-dangerous
 , oh-my-fish
 , githubNvimTheme
-, vim-extra-plugins
 , vim-plugin-arpeggio
 , telescope-file-browser-nvim
 , sddm-theme-chili
diff --git a/modules/themes/githubVariant.nix b/modules/themes/githubVariant.nix
index e7f0299..b9d44cc 100644
--- a/modules/themes/githubVariant.nix
+++ b/modules/themes/githubVariant.nix
@@ -1,29 +1,32 @@
-variant: { pkgs, ... }: {
+{ variant, transparency ? 1 }: { pkgs, ... }:
+let
+  githubTheme = pkgs.myVimPlugins.githubNvimTheme; # github theme for neovim
+in
+{
   name = "github-${variant}";
   neovim = {
-    plugins = [
-      pkgs.myVimPlugins.github-nvim-theme # github theme for neovim
-    ];
+    plugins = [ pkgs.vimExtraPlugins.github-nvim-theme ];
 
     theme = ''
-      require('github-theme').setup({theme_style = "light", dark_float = true, transparent = true})
+      require('github-theme').setup({theme_style = "${variant}", dark_float = true, transparent = true})
     '';
 
     lualineTheme = "github";
   };
-  tmux.path = "${pkgs.githubNvimTheme}/terminal/tmux/github_light.conf";
+  tmux.path = "${githubTheme}/terminal/tmux/github_${variant}.conf";
   alacritty.settings = {
-    import = [ "${pkgs.githubNvimTheme}/terminal/alacritty/github_light.yml" ];
+    import = [ "${githubTheme}/terminal/alacritty/github_${variant}.yml" ];
     window = {
       padding = {
         x = 8;
         y = 8;
       };
 
-      # transparent bg:)
-      background_opacity = 0.8;
-
-      gtk_theme_variant = "light";
+      gtk_theme_variant = if variant == "light" then "light" else "dark";
     };
+
+    # transparent bg:)
+    background_opacity = transparency;
   };
 }
+
diff --git a/modules/themes/themes.nix b/modules/themes/themes.nix
index 57b2937..7cd8460 100644
--- a/modules/themes/themes.nix
+++ b/modules/themes/themes.nix
@@ -1,9 +1,7 @@
-{ pkgs }:
+{ pkgs, lib, ... }:
 let githubVariant = import ./githubVariant.nix;
 in
-lib.map (theme: pkgs.callPackage theme { }) [
-  githubVariant
-  "light"
-  githubVariant
-  "dark"
+lib.lists.map (theme: pkgs.callPackage theme { }) [
+  (githubVariant { variant = "light"; })
+  (githubVariant { variant = "dark"; transparency = 0.8; })
 ]