Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom data fields appear as all lowercase strings #463

Closed
3 tasks done
spatenotte opened this issue Oct 20, 2019 · 8 comments · Fixed by #2376
Closed
3 tasks done

Custom data fields appear as all lowercase strings #463

spatenotte opened this issue Oct 20, 2019 · 8 comments · Fixed by #2376
Labels
bug Something isn't working in dependency In a dependency, not in chezmoi patience Patience required, there is no date for this being fixed

Comments

@spatenotte
Copy link

spatenotte commented Oct 20, 2019

Troubleshooting

  • I ran chezmoi doctor and fixed as many issues as possible and retried my command.
  • I have double checked the instructions for Installation and the Quickstart Guide.
  • 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
@twpayne
Copy link
Owner

twpayne commented Oct 20, 2019

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 spf13/viper#260 and spf13/viper#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.

@twpayne twpayne added the bug Something isn't working label Oct 20, 2019
@spatenotte
Copy link
Author

Awesome, thanks for looking into it, hope they fix it soon!

@twpayne
Copy link
Owner

twpayne commented Nov 3, 2019

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.

@twpayne twpayne mentioned this issue Nov 3, 2019
@spatenotte
Copy link
Author

Thanks for following up on this! Guess we'll have to wait a bit more

@twpayne twpayne added the in dependency In a dependency, not in chezmoi label Apr 8, 2020
@gotgenes
Copy link
Contributor

gotgenes commented Apr 16, 2020

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.

@twpayne twpayne added the patience Patience required, there is no date for this being fixed label Apr 18, 2020
@skyfaller
Copy link

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?

@twpayne
Copy link
Owner

twpayne commented Oct 15, 2021

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:

  1. Replace Viper while keeping all-lowercase fields for backwards compatibility.
  2. Add case-sensitive fields while keeping all-lowercase fields.
  3. (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.

@spf13
Copy link

spf13 commented Nov 28, 2021

I'm starting to use chezmoi so I'm interested in helping. No promises, but I'd like to help make things better.

skaldarnar added a commit to skaldarnar/chezmoi that referenced this issue Apr 13, 2022
Hi, 

I'm new to chezmoi and started to look into templates. I've spent quite some time to figure out why I could not get custom variables in the `data` section of the config to work until I realized that I've stumbled upon twpayne#463.

I propose to add a hint or disclaimer to the documentation here to make it easier for newcomers to spot this pitfall (and avoid it).

Please let me know if I need to change or update anything.
twpayne pushed a commit that referenced this issue Apr 14, 2022
Hi, 

I'm new to chezmoi and started to look into templates. I've spent quite some time to figure out why I could not get custom variables in the `data` section of the config to work until I realized that I've stumbled upon #463.

I propose to add a hint or disclaimer to the documentation here to make it easier for newcomers to spot this pitfall (and avoid it).

Please let me know if I need to change or update anything.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working in dependency In a dependency, not in chezmoi patience Patience required, there is no date for this being fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants