Closed gadams999 closed 1 year ago
I think this is because .chezmoi.osRelease
is null
.
/etc/os-release
does not exist on darwin
, or at least it doesn't exist on my MBP:
❯ /etc/os-release
zsh: no such file or directory: /etc/os-release
Agreed that there is no os-release
file. I would think since .chezmoi.osRelease
is null and doesn't have the key, that shouldn't blow up? If so, it makes is challenging to have template logic that spans Windows, macOS, and Linux.
What's really weird is I had no issues a couple months ago the last time I did a chezmoi apply
. Only after the update to 2.25.0 is when I saw the error. I may look to downgrade to a previous version and see that changes anything.
You can just check if .chezmoi.osRelease
isn't null
by and
ing it: {{- if and (.chezmoi.osRelease) (hasKey .chezmoi.osRelease "id") -}}
:
❯ chezmoi execute-template '{{- $osid := .chezmoi.os -}}{{- if hasKey .chezmoi.osRelease "id" -}}{{- $osid = printf "%s-%s" .chezmoi.os .chezmoi.osRelease.id -}}{{- end -}}{{- $osid -}}'
chezmoi: template: arg1:1:50: executing "arg1" at <.chezmoi.osRelease>: wrong type for value; expected map[string]interface {}; got interface {}
❯ chezmoi execute-template '{{- $osid := .chezmoi.os -}}{{- if and (.chezmoi.osRelease) (hasKey .chezmoi.osRelease "id") -}}{{- $osid = printf "%s-%s" .chezmoi.os .chezmoi.osRelease.id -}}{{- end -}}{{- $osid -}}'
windows
@twpayne We should probably add something like this to the template. I can do this tomorrow if you want. (Assuming this isn't a bug)
@twpayne, @bradenhilton this looks like a regression from 2.24.0 to 2.25.0.
❯ for d in 3 4 5
echo 2.2$d.0 && ./chezmoi-2.2$d.0 execute-template '{{ .chezmoi.osRelease | toJson }}' -W . | jq .
end
2.23.0
{}
2.24.0
{}
2.25.0
null
I think that the current behaviour is more or less correct, but it’s a regression. That said, we might want to consider options to enhance the osRelease
data on macOS in any case, since there may be value in knowing the difference between macOS 12 and macOS 13.
@halostatue Interesting. Would you be willing to try a bisect?
Re: osRelease
, it's populated by reading /etc/os-release
or /usr/lib/os-release
:
Are you suggesting we manually populate it with equivalent data if this isn't possible?
I’m doing a code comparison now to investigate.
I am suggesting manually populating it with equivalent data. There are alternate keys for some of these (e.g., windowsVersion
), but it feels like we could probably shift some of this into interesting places on a more regular basis. I have a bunch of functions I’ve written for fish
that do this for macOS.
I know which commit is causing this, but I can’t quite figure out why the previous commit returns {}
and the suspect commit returns null
.
Found it…and it’s a doozy. Specifically, this is because of the JSON roundtrip in func (c *Config) getTemplateDataMap() map[string]any
.
Specifically https://github.com/twpayne/chezmoi/commit/964810aa28319a720fe800b6e6b0a1934e2c8056 if I'm not mistaken.
What exactly are you trying to do?
I upgraded chezmoi to version:
and started to see my OS detection fail. I had been using this for detecting Linux variants:
but then started to get errors about nil values (from the first line above):
Reading the docs, I saw the reference to using
hasKey
to check forid
and then create anosid
entry in my config file:Now when trying
chezmoi init
I get the error:Below is the output from
--verbose
and my redacted data when running this on macOS.Looking for guidance on why
hasKey
errors out (details fromchezmoi data
below).What have you tried so far?
hasKey
approach in my.tmpl
files (with the same error above from the config file when runningchezmoi init
.Where else have you checked for solutions?
Output of any commands you've tried with
--verbose
flagOutput of
chezmoi doctor
Additional context