Skip to content

Commit a432b91

Browse files
khanelimanauscyber
authored andcommitted
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 <[email protected]>
1 parent a09f276 commit a432b91

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

modules/programs/zsh/default.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,24 @@ in
343343
in
344344
mkIf cfg.enable (
345345
lib.mkMerge [
346+
{
347+
warnings =
348+
lib.optionals
349+
(cfg.dotDir != homeDir && !lib.hasPrefix "/" cfg.dotDir && !lib.hasPrefix "$" cfg.dotDir)
350+
[
351+
''
352+
Using relative paths in programs.zsh.dotDir is deprecated and will be removed in a future release.
353+
Current dotDir: ${cfg.dotDir}
354+
Consider using absolute paths or home-manager config options instead.
355+
You can replace relative paths or environment variables with options like:
356+
- config.home.homeDirectory (user's home directory)
357+
- config.xdg.configHome (XDG config directory)
358+
- config.xdg.dataHome (XDG data directory)
359+
- config.xdg.cacheHome (XDG cache directory)
360+
''
361+
];
362+
}
363+
346364
(mkIf (cfg.envExtra != "") {
347365
home.file."${dotDirRel}/.zshenv".text = cfg.envExtra;
348366
})

modules/programs/zsh/history.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ in
171171
};
172172

173173
config = {
174+
warnings =
175+
lib.optionals (!lib.hasPrefix "/" cfg.history.path && !lib.hasInfix "$" cfg.history.path)
176+
[
177+
''
178+
Using relative paths in programs.zsh.history.path is deprecated and will be removed in a future release.
179+
Consider using absolute paths or home-manager config options instead.
180+
You can replace relative paths or environment variables with options like:
181+
- config.home.homeDirectory (user's home directory)
182+
- config.xdg.configHome (XDG config directory)
183+
- config.xdg.dataHome (XDG data directory)
184+
- config.xdg.cacheHome (XDG cache directory)
185+
Current history.path: ${cfg.history.path}
186+
''
187+
];
188+
174189
programs.zsh.initContent = lib.mkMerge [
175190
(lib.mkOrder 910 ''
176191
# History options should be set in .zshrc and after oh-my-zsh sourcing.

tests/modules/programs/zsh/dotdir.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ in
3535

3636
test.stubs.zsh = { };
3737

38+
test.asserts.warnings.expected = lib.optionals (case == "relative") [
39+
''
40+
Using relative paths in programs.zsh.dotDir is deprecated and will be removed in a future release.
41+
Current dotDir: subdir/subdir2
42+
Consider using absolute paths or home-manager config options instead.
43+
You can replace relative paths or environment variables with options like:
44+
- config.home.homeDirectory (user's home directory)
45+
- config.xdg.configHome (XDG config directory)
46+
- config.xdg.dataHome (XDG data directory)
47+
- config.xdg.cacheHome (XDG cache directory)
48+
''
49+
];
50+
3851
nmt.script =
3952
if case == "xdg-variable" then
4053
''

tests/modules/programs/zsh/history-path.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ in
4747

4848
test.stubs.zsh = { };
4949

50+
test.asserts.warnings.expected = lib.optionals (case == "relative") [
51+
''
52+
Using relative paths in programs.zsh.history.path is deprecated and will be removed in a future release.
53+
Consider using absolute paths or home-manager config options instead.
54+
You can replace relative paths or environment variables with options like:
55+
- config.home.homeDirectory (user's home directory)
56+
- config.xdg.configHome (XDG config directory)
57+
- config.xdg.dataHome (XDG data directory)
58+
- config.xdg.cacheHome (XDG cache directory)
59+
Current history.path: some/subdir/.zsh_history
60+
''
61+
];
62+
5063
nmt.script =
5164
if case == "xdg-variable" then
5265
''

0 commit comments

Comments
 (0)