1
0
Fork 0

Fix .chezmoi.yaml.tmpl: handle missing ID_LIKE on debian-stable

debian-stable's /etc/os-release has no ID_LIKE field. Template crashed
with 'map has no entry for key idLike' when chezmoi init ran on rye.

Two fixes:
1. hasKey() guard around .chezmoi.osRelease.idLike so missing key
   doesn't error out
2. Flip contains() arg order: sprig's signature is contains(substr, str),
   not contains(str, substr). Was checking backwards.

Tested against:
- miche (ID=debian-derivative with ID_LIKE=arch) -> os_family=arch
- empty ID_LIKE fallback (debian-stable) -> falls through to .id=debian
  -> os_family=debian
This commit is contained in:
Rain 2026-06-21 19:37:06 -04:00
parent ef9b7dcd2a
commit 0cc12f050a

View file

@ -1,8 +1,12 @@
{{- $osFamily := "unknown" -}}
{{- if eq .chezmoi.osRelease.idLike "arch" -}}
{{- $osFamily = "arch" -}}
{{- else if or (eq .chezmoi.osRelease.id "debian") (eq .chezmoi.osRelease.idLike "debian") -}}
{{- $osFamily = "debian" -}}
{{- $idLike := "" -}}
{{- if hasKey .chezmoi.osRelease "idLike" -}}
{{- $idLike = .chezmoi.osRelease.idLike -}}
{{- end -}}
{{- if or (eq .chezmoi.osRelease.id "arch") (contains "arch" $idLike) -}}
{{- $osFamily = "arch" -}}
{{- else if or (eq .chezmoi.osRelease.id "debian") (contains "debian" $idLike) -}}
{{- $osFamily = "debian" -}}
{{- end -}}
encryption: "age"
sourceDir: {{ .chezmoi.sourceDir | quote }}