|
7 | 7 | }: |
8 | 8 | let |
9 | 9 | home = config.home.homeDirectory; |
| 10 | + subDir = "subdir/subdir2"; |
10 | 11 |
|
11 | | - dotDir = |
| 12 | + dotDirCases = { |
| 13 | + absolute = "${home}/${subDir}"; |
| 14 | + relative = subDir; |
| 15 | + inherit (options.programs.zsh.dotDir) default; |
| 16 | + shell-variable = "\${XDG_CONFIG_HOME:-$HOME/.config}/zsh"; |
| 17 | + |
| 18 | + # Path normalization cases |
| 19 | + abs-no-slash = "${home}/subdir"; |
| 20 | + abs-slash = "${home}/subdir/"; |
| 21 | + rel-no-slash = "subdir"; |
| 22 | + rel-slash = "subdir/"; |
| 23 | + root-no-slash = "${home}"; |
| 24 | + root-slash = "${home}/"; |
| 25 | + abs-space = "${home}/subdir with space"; |
| 26 | + }; |
| 27 | + |
| 28 | + dotDir = dotDirCases.${case} or (abort "Unknown case: ${case}"); |
| 29 | + |
| 30 | + # Normalize absolute path to match module behavior (no trailing slash) |
| 31 | + absDotDir = |
12 | 32 | let |
13 | | - subDir = "subdir/subdir2"; |
| 33 | + fullPath = if lib.hasPrefix "/" dotDir then dotDir else "${home}/${dotDir}"; |
14 | 34 | in |
15 | | - if case == "absolute" then |
16 | | - "${home}/${subDir}" |
17 | | - else if case == "relative" then |
18 | | - subDir |
19 | | - else if case == "default" then |
20 | | - options.programs.zsh.dotDir.default |
21 | | - else if case == "shell-variable" then |
22 | | - "\${XDG_CONFIG_HOME:-\$HOME/.config}/zsh" |
23 | | - else |
24 | | - abort "Test condition not provided."; |
| 35 | + lib.removeSuffix "/" fullPath; |
| 36 | + |
| 37 | + # Calculate relative path for file location assertions |
| 38 | + relDotDir = |
| 39 | + let |
| 40 | + # Use the normalized absDotDir to determine relative location |
| 41 | + rawRel = lib.removePrefix home absDotDir; |
| 42 | + in |
| 43 | + if lib.hasPrefix "/" rawRel then lib.removePrefix "/" rawRel else rawRel; |
| 44 | + |
| 45 | + isRelative = case == "relative" || case == "rel-no-slash" || case == "rel-slash"; |
25 | 46 |
|
26 | | - absDotDir = lib.optionalString (!lib.hasPrefix home dotDir) "${home}/" + dotDir; |
27 | | - relDotDir = lib.removePrefix home dotDir; |
28 | 47 | in |
29 | 48 | { |
30 | 49 | config = { |
|
33 | 52 | inherit dotDir; |
34 | 53 | }; |
35 | 54 |
|
36 | | - test.stubs.zsh = { }; |
| 55 | + test = { |
| 56 | + stubs.zsh = { }; |
37 | 57 |
|
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 | | - ]; |
| 58 | + asserts = { |
| 59 | + assertions.expected = lib.optionals (case == "shell-variable") [ |
| 60 | + '' |
| 61 | + programs.zsh.dotDir cannot contain shell variables as it is used for file creation at build time. |
| 62 | + Current dotDir: ''${XDG_CONFIG_HOME:-''$HOME/.config}/zsh |
| 63 | + Consider using an absolute path or home-manager config options instead. |
| 64 | + You can replace shell variables with options like: |
| 65 | + - config.home.homeDirectory (user's home directory) |
| 66 | + - config.xdg.configHome (XDG config directory) |
| 67 | + - config.xdg.dataHome (XDG data directory) |
| 68 | + - config.xdg.cacheHome (XDG cache directory) |
| 69 | + '' |
| 70 | + ]; |
50 | 71 |
|
51 | | - test.asserts.assertions.expected = lib.optionals (case == "shell-variable") [ |
52 | | - '' |
53 | | - programs.zsh.dotDir cannot contain shell variables as it is used for file creation at build time. |
54 | | - Current dotDir: ''${XDG_CONFIG_HOME:-''$HOME/.config}/zsh |
55 | | - Consider using an absolute path or home-manager config options instead. |
56 | | - You can replace shell variables with options like: |
57 | | - - config.home.homeDirectory (user's home directory) |
58 | | - - config.xdg.configHome (XDG config directory) |
59 | | - - config.xdg.dataHome (XDG data directory) |
60 | | - - config.xdg.cacheHome (XDG cache directory) |
61 | | - '' |
62 | | - ]; |
| 72 | + warnings.expected = lib.optionals isRelative [ |
| 73 | + '' |
| 74 | + Using relative paths in programs.zsh.dotDir is deprecated and will be removed in a future release. |
| 75 | + Current dotDir: ${dotDir} |
| 76 | + Consider using absolute paths or home-manager config options instead. |
| 77 | + You can replace relative paths or environment variables with options like: |
| 78 | + - config.home.homeDirectory (user's home directory) |
| 79 | + - config.xdg.configHome (XDG config directory) |
| 80 | + - config.xdg.dataHome (XDG data directory) |
| 81 | + - config.xdg.cacheHome (XDG cache directory) |
| 82 | + '' |
| 83 | + ]; |
| 84 | + }; |
| 85 | + }; |
63 | 86 |
|
64 | 87 | nmt.script = |
65 | 88 | if case == "shell-variable" then |
|
70 | 93 | else |
71 | 94 | lib.concatStringsSep "\n" [ |
72 | 95 | # check dotDir entrypoint exists |
73 | | - "assertFileExists home-files/${relDotDir}/.zshenv" |
| 96 | + "assertFileExists 'home-files/${if relDotDir == "" then "" else "${relDotDir}/"}.zshenv'" |
74 | 97 |
|
75 | 98 | # for non-default dotDir only: |
76 | | - (lib.optionalString (case != "default") '' |
| 99 | + (lib.optionalString (case != "default" && case != "root-slash" && case != "root-no-slash") '' |
77 | 100 | # check .zshenv in homeDirectory sources .zshenv in dotDir |
78 | | - assertFileRegex home-files/.zshenv \ |
79 | | - "source [\"']\?${absDotDir}/.zshenv[\"']\?" |
| 101 | + assertFileRegex home-files/.zshenv "source ${lib.escapeShellArg absDotDir}/.zshenv" |
80 | 102 |
|
81 | 103 | # check that .zshenv in dotDir exports ZDOTDIR |
82 | | - assertFileRegex home-files/${relDotDir}/.zshenv \ |
83 | | - "export ZDOTDIR=[\"']\?${absDotDir}[\"']\?" |
| 104 | + assertFileRegex 'home-files/${relDotDir}/.zshenv' "export ZDOTDIR=${lib.escapeShellArg absDotDir}" |
84 | 105 | '') |
85 | 106 | ]; |
86 | 107 | }; |
|
0 commit comments