chezmoi
chezmoi copied to clipboard
Custom data fields appear as all lowercase strings
Troubleshooting
- [x] I ran
chezmoi doctor
and fixed as many issues as possible and retried my command. - [x] I have double checked the instructions for Installation and the Quickstart Guide.
- [x] I have search for previous issues that have been reported/opened, and none of them relate to my problem.
Failure to follow the troubleshooting steps (and to report information requested below), may make it difficult to provide the proper support required. Furthermore, your issue may be closed without reply, if the instructions were not properly followed.
Description of issue
I added this block in my .chezmoi.toml.tmpl
:
[data]
isLinux = {{if eq .chezmoi.os “linux”}}true{{else}}false{{end}}
isMac = {{if eq .chezmoi.os “darwin”}}true{{else}}false{{end}}
isUnix = {{if eq .chezmoi.os “linux” }}true{{else if eq .chezmoi.os “darwin”}}true{{else}}false{{end}}
isWindows = {{if eq .chezmoi.os “windows”}}true{{else}}false{{end}}
The file that got generated is this one:
[data]
isLinux = false
isMac = true
isUnix = true
isWindows = false
But trying to use those variables doesn't work, unless I write them down all in lowercase, i.e islinux
.
A quick note is that it looks like my system (macOS Mojave, 10.14.6) has a non case-sensitive file system, which might or might not be the cause of this. But I would like to not have to change that setting because this machine is my main programming device, and I am afraid changing that setting might cause other issues. Also, all other chezMoi
data strings are cased correctly (like chezmoi.fullHostname
)
EDIT: Looks like the same thing happens in WSL (Linux subsystem on Windows), so might not be related to the filesystem being case-sensitive.
I could also just use the .chezmoi.os
data directly, but those data fields help me keep things more readable and avoid typos better.
Also, just wanted to say I really appreciate this software, it really helps me manage my dotfiles much better!
Command that failed
✔ sammy in ~/.local/share/chezmoi [master ↑·5| ✚ 2 … 11]
17:28:00.3N $ cat .chezmoi.toml.tmpl
[data]
isLinux = {{if eq .chezmoi.os "linux"}}true{{else}}false{{end}}
isMac = {{if eq .chezmoi.os "darwin"}}true{{else}}false{{end}}
isUnix = {{if eq .chezmoi.os "linux" }}true{{else if eq .chezmoi.os "darwin"}}true{{else}}false{{end}}
isWindows = {{if eq .chezmoi.os "windows"}}true{{else}}false{{end}}
✔ sammy in ~/.local/share/chezmoi [master ↑·5| ✚ 2 … 11]
17:28:20.3N $ cat ~/.config/chezmoi/chezmoi.toml
[data]
isLinux = false
isMac = true
isUnix = true
isWindows = false
✔ sammy in ~/.local/share/chezmoi [master ↑·5| ✚ 2 … 11]
17:28:33.3N $ chezmoi data
{
"chezmoi": {
"arch": "amd64",
"fullHostname": "Sammys-Macbook-Pro.local",
"group": "staff",
"homedir": "/Users/sammy",
"hostname": "Sammys-Macbook-Pro",
"os": "darwin",
"username": "sammy"
},
"islinux": false,
"ismac": true,
"isunix": true,
"iswindows": false
}
Output of command with --verbose
✔ sammy in ~/.local/share/chezmoi [master ↑·5| ✚ 2 … 11]
17:31:23.3N $ chezmoi data --verbose
{
"chezmoi": {
"arch": "amd64",
"fullHostname": "Sammys-Macbook-Pro.local",
"group": "staff",
"homedir": "/Users/sammy",
"hostname": "Sammys-Macbook-Pro",
"os": "darwin",
"username": "sammy"
},
"islinux": false,
"ismac": true,
"isunix": true,
"iswindows": false
}
Output of chezmoi doctor
✔ sammy in ~/.local/share/chezmoi [master ↑·5| ✚ 2 … 11]
17:34:49.3N $ chezmoi doctor
ok: version 1.7.2, commit 41c4fdc2faf1bf9f0ded922d1ea7724a838bca3f, built at 2019-10-17T00:29:03Z
ok: /Users/sammy/.local/share/chezmoi (source directory, perm 700)
ok: /Users/sammy (destination directory, perm 755)
ok: /Users/sammy/.config/chezmoi/chezmoi.toml (configuration file)
ok: /usr/local/bin/bash (shell)
ok: /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code (editor)
ok: /usr/bin/vimdiff (merge command)
ok: /usr/local/bin/git (source VCS command, version 2.23.0)
warning: gpg (GnuPG, not found)
ok: /Users/sammy/bin/op (1Password CLI, version 0.6.2)
warning: bw (Bitwarden CLI, not found)
warning: gopass (gopass CLI, not found)
warning: keepassxc-cli (KeePassXC CLI, not found)
ok: /usr/local/bin/lpass (LastPass CLI, version 1.3.3)
warning: pass (pass CLI, not found)
warning: vault (Vault CLI, not found)
Output of chezmoi --version
✘-1 sammy in ~/.local/share/chezmoi [master ↑·5| ✚ 2 … 11]
17:39:07.3N $ chezmoi --version
chezmoi version 1.7.2, commit 41c4fdc2faf1bf9f0ded922d1ea7724a838bca3f, built at 2019-10-17T00:29:03Z
Thanks for reporting the issue. I did some digging and this is actually a bug/feature in the github.com/spf13/viper
package that chezmoi uses to read the configuration file, see https://github.com/spf13/viper/issues/260 and https://github.com/spf13/viper/issues/373 for example.
Apparently a fix is in and should be released soon. If that doesn't happen then I'll remove the dependency on Viper - chezmoi uses so little of the Viper's functionality that it's not really worth using the package anyway.
Awesome, thanks for looking into it, hope they fix it soon!
So viper 1.5.0 got released, but the bug was not actually fixed. See this comment. I tried building chezmoi with viper 1.5.0 and the lowercasing was still present.
Thanks for following up on this! Guess we'll have to wait a bit more
I just encountered this behavior. I'm glad this issue was reported and that it's being tracked by the chezmoi team. It's worth noting that #593 was closed and that it looks like we're waiting for viper team to release 2.0.
I ran into this issue today. It's been over a year since the last comment. Is it worth removing Viper as a dependency, which was proposed earlier in the thread?
Sadly it looks like it's going to be a while before Viper implements this - there was a survey for interest about 13 months ago, but still many open issues.
Fixing this in chezmoi will take some time as it will take several steps:
- Replace Viper while keeping all-lowercase fields for backwards compatibility.
- Add case-sensitive fields while keeping all-lowercase fields.
- (In chezmoi v3) Remove all-lowercase fields.
Given that the current state does work, even though it's a little annoying, and fixing this will require significant effort (replacing Viper), I think the patience
label on this issue is appropriate.
I'm starting to use chezmoi so I'm interested in helping. No promises, but I'd like to help make things better.