diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index ebf1c344e..0a81e0aa2 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -344,9 +344,25 @@ in mkIf cfg.enable ( lib.mkMerge [ { + assertions = [ + { + assertion = !lib.hasInfix "$" cfg.dotDir; + message = '' + programs.zsh.dotDir cannot contain shell variables as it is used for file creation at build time. + Current dotDir: ${cfg.dotDir} + Consider using an absolute path or home-manager config options instead. + You can replace shell 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) + ''; + } + ]; + warnings = lib.optionals - (cfg.dotDir != homeDir && !lib.hasPrefix "/" cfg.dotDir && !lib.hasPrefix "$" cfg.dotDir) + (cfg.dotDir != homeDir && !lib.hasPrefix "/" cfg.dotDir && !lib.hasInfix "$" cfg.dotDir) [ '' Using relative paths in programs.zsh.dotDir is deprecated and will be removed in a future release. diff --git a/tests/modules/programs/zsh/default.nix b/tests/modules/programs/zsh/default.nix index bab5d892e..159fbbcff 100644 --- a/tests/modules/programs/zsh/default.nix +++ b/tests/modules/programs/zsh/default.nix @@ -4,7 +4,7 @@ zsh-dotdir-absolute = import ./dotdir.nix "absolute"; zsh-dotdir-default = import ./dotdir.nix "default"; zsh-dotdir-relative = import ./dotdir.nix "relative"; - zsh-dotdir-xdg-variable = import ./dotdir.nix "xdg-variable"; + zsh-dotdir-shell-variable = import ./dotdir.nix "shell-variable"; zsh-history-ignore-pattern = ./history-ignore-pattern.nix; zsh-history-path-absolute = import ./history-path.nix "absolute"; zsh-history-path-default = import ./history-path.nix "default"; diff --git a/tests/modules/programs/zsh/dotdir.nix b/tests/modules/programs/zsh/dotdir.nix index fd10c6fa3..244b19859 100644 --- a/tests/modules/programs/zsh/dotdir.nix +++ b/tests/modules/programs/zsh/dotdir.nix @@ -18,7 +18,7 @@ let subDir else if case == "default" then options.programs.zsh.dotDir.default - else if case == "xdg-variable" then + else if case == "shell-variable" then "\${XDG_CONFIG_HOME:-\$HOME/.config}/zsh" else abort "Test condition not provided."; @@ -48,12 +48,24 @@ in '' ]; + test.asserts.assertions.expected = lib.optionals (case == "shell-variable") [ + '' + programs.zsh.dotDir cannot contain shell variables as it is used for file creation at build time. + Current dotDir: ''${XDG_CONFIG_HOME:-''$HOME/.config}/zsh + Consider using an absolute path or home-manager config options instead. + You can replace shell 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 + if case == "shell-variable" then '' - # For XDG variable case, check that shell variables are preserved in the generated shell code - # The fixed implementation should preserve variables without wrapping them in single quotes - assertFileContains home-files/.zshenv 'source ''${XDG_CONFIG_HOME:-''$HOME/.config}/zsh/.zshenv' + # Shell variable case should fail assertion, no files to check + echo "Shell variable case should trigger assertion failure" '' else lib.concatStringsSep "\n" [