From e00dd0d7d2565a9d79c3826b088bef039624382e Mon Sep 17 00:00:00 2001
From: Mario Rodas <marsam@users.noreply.github.com>
Date: Fri, 23 Apr 2021 02:25:13 -0500
Subject: [PATCH] programs.tmux: use xdg config path (#1928)

Tmux 3.2 includes support to use `$XDG_CONFIG_HOME/tmux/tmux.conf` as
well as `~/.config/tmux/tmux.conf` for configuration file.
---
 modules/programs/tmux.nix                                  | 7 +++----
 tests/modules/programs/tmux/default-shell.nix              | 4 ++--
 .../modules/programs/tmux/disable-confirmation-prompt.nix  | 4 ++--
 tests/modules/programs/tmux/emacs-with-plugins.nix         | 6 ++++--
 tests/modules/programs/tmux/not-enabled.nix                | 2 +-
 tests/modules/programs/tmux/prefix.nix                     | 4 ++--
 tests/modules/programs/tmux/shortcut-without-prefix.nix    | 4 ++--
 tests/modules/programs/tmux/vi-all-true.nix                | 4 ++--
 8 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix
index 295df490..8628155b 100644
--- a/modules/programs/tmux.nix
+++ b/modules/programs/tmux.nix
@@ -109,7 +109,7 @@ let
         }
     )];
 
-    home.file.".tmux.conf".text = ''
+    xdg.configFile."tmux/tmux.conf".text = ''
       # ============================================= #
       # Load plugins with Home Manager                #
       # --------------------------------------------- #
@@ -335,10 +335,9 @@ in
         };
       })
 
-      # config file ~/.tmux.conf
-      { home.file.".tmux.conf".text = mkBefore tmuxConf; }
+      { xdg.configFile."tmux/tmux.conf".text = mkBefore tmuxConf; }
       (mkIf (cfg.plugins != []) configPlugins)
-      { home.file.".tmux.conf".text = mkAfter cfg.extraConfig; }
+      { xdg.configFile."tmux/tmux.conf".text = mkAfter cfg.extraConfig; }
     ])
   );
 }
diff --git a/tests/modules/programs/tmux/default-shell.nix b/tests/modules/programs/tmux/default-shell.nix
index 05091c6a..af05eb0e 100644
--- a/tests/modules/programs/tmux/default-shell.nix
+++ b/tests/modules/programs/tmux/default-shell.nix
@@ -19,8 +19,8 @@ in {
     };
 
     nmt.script = ''
-      assertFileExists home-files/.tmux.conf
-      assertFileContent home-files/.tmux.conf \
+      assertFileExists home-files/.config/tmux/tmux.conf
+      assertFileContent home-files/.config/tmux/tmux.conf \
         ${substituteExpected ./default-shell.conf}
     '';
   };
diff --git a/tests/modules/programs/tmux/disable-confirmation-prompt.nix b/tests/modules/programs/tmux/disable-confirmation-prompt.nix
index 9c65ad6e..aec1f66c 100644
--- a/tests/modules/programs/tmux/disable-confirmation-prompt.nix
+++ b/tests/modules/programs/tmux/disable-confirmation-prompt.nix
@@ -18,8 +18,8 @@ with lib;
     ];
 
     nmt.script = ''
-      assertFileExists home-files/.tmux.conf
-      assertFileContent home-files/.tmux.conf \
+      assertFileExists home-files/.config/tmux/tmux.conf
+      assertFileContent home-files/.config/tmux/tmux.conf \
         ${./disable-confirmation-prompt.conf}
     '';
   };
diff --git a/tests/modules/programs/tmux/emacs-with-plugins.nix b/tests/modules/programs/tmux/emacs-with-plugins.nix
index f9bccaa2..4a0382d8 100644
--- a/tests/modules/programs/tmux/emacs-with-plugins.nix
+++ b/tests/modules/programs/tmux/emacs-with-plugins.nix
@@ -42,8 +42,10 @@ with lib;
     ];
 
     nmt.script = ''
-      assertFileExists home-files/.tmux.conf
-      assertFileContent home-files/.tmux.conf ${./emacs-with-plugins.conf}
+      assertFileExists home-files/.config/tmux/tmux.conf
+      assertFileContent home-files/.config/tmux/tmux.conf ${
+        ./emacs-with-plugins.conf
+      }
     '';
   };
 }
diff --git a/tests/modules/programs/tmux/not-enabled.nix b/tests/modules/programs/tmux/not-enabled.nix
index b7c675a8..d5f08b36 100644
--- a/tests/modules/programs/tmux/not-enabled.nix
+++ b/tests/modules/programs/tmux/not-enabled.nix
@@ -7,7 +7,7 @@ with lib;
     programs.tmux = { enable = false; };
 
     nmt.script = ''
-      assertPathNotExists home-files/.tmux.conf
+      assertPathNotExists home-files/.config/tmux/tmux.conf
     '';
   };
 }
diff --git a/tests/modules/programs/tmux/prefix.nix b/tests/modules/programs/tmux/prefix.nix
index 80ed6964..9f97940e 100644
--- a/tests/modules/programs/tmux/prefix.nix
+++ b/tests/modules/programs/tmux/prefix.nix
@@ -18,8 +18,8 @@ with lib;
     ];
 
     nmt.script = ''
-      assertFileExists home-files/.tmux.conf
-      assertFileContent home-files/.tmux.conf \
+      assertFileExists home-files/.config/tmux/tmux.conf
+      assertFileContent home-files/.config/tmux/tmux.conf \
         ${./prefix.conf}
     '';
   };
diff --git a/tests/modules/programs/tmux/shortcut-without-prefix.nix b/tests/modules/programs/tmux/shortcut-without-prefix.nix
index 52290c4f..5c294ef9 100644
--- a/tests/modules/programs/tmux/shortcut-without-prefix.nix
+++ b/tests/modules/programs/tmux/shortcut-without-prefix.nix
@@ -19,8 +19,8 @@ with lib;
     ];
 
     nmt.script = ''
-      assertFileExists home-files/.tmux.conf
-      assertFileContent home-files/.tmux.conf \
+      assertFileExists home-files/.config/tmux/tmux.conf
+      assertFileContent home-files/.config/tmux/tmux.conf \
         ${./shortcut-without-prefix.conf}
     '';
   };
diff --git a/tests/modules/programs/tmux/vi-all-true.nix b/tests/modules/programs/tmux/vi-all-true.nix
index bce032fd..8b9cf1a3 100644
--- a/tests/modules/programs/tmux/vi-all-true.nix
+++ b/tests/modules/programs/tmux/vi-all-true.nix
@@ -22,8 +22,8 @@ with lib;
     ];
 
     nmt.script = ''
-      assertFileExists home-files/.tmux.conf
-      assertFileContent home-files/.tmux.conf ${./vi-all-true.conf}
+      assertFileExists home-files/.config/tmux/tmux.conf
+      assertFileContent home-files/.config/tmux/tmux.conf ${./vi-all-true.conf}
     '';
   };
 }