From 40af7ba06ba959a191ac1297f5f4e6c2786a1e39 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 28 Jul 2025 10:08:42 -0500 Subject: [PATCH] zsh: relative path deprecation warning Warn users when they configure a relative path. We want to encourage using absolute paths and env variables. Signed-off-by: Austin Horstman --- modules/programs/zsh/default.nix | 18 ++++++++++++++++++ modules/programs/zsh/history.nix | 15 +++++++++++++++ tests/modules/programs/zsh/dotdir.nix | 13 +++++++++++++ tests/modules/programs/zsh/history-path.nix | 13 +++++++++++++ 4 files changed, 59 insertions(+) diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index 5179e43a3..ebf1c344e 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -343,6 +343,24 @@ in in mkIf cfg.enable ( lib.mkMerge [ + { + warnings = + lib.optionals + (cfg.dotDir != homeDir && !lib.hasPrefix "/" cfg.dotDir && !lib.hasPrefix "$" cfg.dotDir) + [ + '' + Using relative paths in programs.zsh.dotDir is deprecated and will be removed in a future release. + Current dotDir: ${cfg.dotDir} + Consider using absolute paths or home-manager config options instead. + You can replace relative paths or environment variables with options like: + - config.home.homeDirectory (user's home directory) + - config.xdg.configHome (XDG config directory) + - config.xdg.dataHome (XDG data directory) + - config.xdg.cacheHome (XDG cache directory) + '' + ]; + } + (mkIf (cfg.envExtra != "") { home.file."${dotDirRel}/.zshenv".text = cfg.envExtra; }) diff --git a/modules/programs/zsh/history.nix b/modules/programs/zsh/history.nix index 3c47d2e9d..3b766d62b 100644 --- a/modules/programs/zsh/history.nix +++ b/modules/programs/zsh/history.nix @@ -171,6 +171,21 @@ in }; config = { + warnings = + lib.optionals (!lib.hasPrefix "/" cfg.history.path && !lib.hasInfix "$" cfg.history.path) + [ + '' + Using relative paths in programs.zsh.history.path is deprecated and will be removed in a future release. + Consider using absolute paths or home-manager config options instead. + You can replace relative paths or environment variables with options like: + - config.home.homeDirectory (user's home directory) + - config.xdg.configHome (XDG config directory) + - config.xdg.dataHome (XDG data directory) + - config.xdg.cacheHome (XDG cache directory) + Current history.path: ${cfg.history.path} + '' + ]; + programs.zsh.initContent = lib.mkMerge [ (lib.mkOrder 910 '' # History options should be set in .zshrc and after oh-my-zsh sourcing. diff --git a/tests/modules/programs/zsh/dotdir.nix b/tests/modules/programs/zsh/dotdir.nix index 9df0d309e..fd10c6fa3 100644 --- a/tests/modules/programs/zsh/dotdir.nix +++ b/tests/modules/programs/zsh/dotdir.nix @@ -35,6 +35,19 @@ in test.stubs.zsh = { }; + test.asserts.warnings.expected = lib.optionals (case == "relative") [ + '' + Using relative paths in programs.zsh.dotDir is deprecated and will be removed in a future release. + Current dotDir: subdir/subdir2 + Consider using absolute paths or home-manager config options instead. + You can replace relative paths or environment variables with options like: + - config.home.homeDirectory (user's home directory) + - config.xdg.configHome (XDG config directory) + - config.xdg.dataHome (XDG data directory) + - config.xdg.cacheHome (XDG cache directory) + '' + ]; + nmt.script = if case == "xdg-variable" then '' diff --git a/tests/modules/programs/zsh/history-path.nix b/tests/modules/programs/zsh/history-path.nix index 86bd307b1..f43b1cbca 100644 --- a/tests/modules/programs/zsh/history-path.nix +++ b/tests/modules/programs/zsh/history-path.nix @@ -47,6 +47,19 @@ in test.stubs.zsh = { }; + test.asserts.warnings.expected = lib.optionals (case == "relative") [ + '' + Using relative paths in programs.zsh.history.path is deprecated and will be removed in a future release. + Consider using absolute paths or home-manager config options instead. + You can replace relative paths or environment variables with options like: + - config.home.homeDirectory (user's home directory) + - config.xdg.configHome (XDG config directory) + - config.xdg.dataHome (XDG data directory) + - config.xdg.cacheHome (XDG cache directory) + Current history.path: some/subdir/.zsh_history + '' + ]; + nmt.script = if case == "xdg-variable" then ''