diff --git a/home/.chezmoi.toml.tmpl b/home/.chezmoi.toml.tmpl index f2820fa..1522d38 100644 --- a/home/.chezmoi.toml.tmpl +++ b/home/.chezmoi.toml.tmpl @@ -1,5 +1,5 @@ {{- /* Detect chassis type (likely: laptop | desktop | container) */ -}} -{{- /* https://www.freedesktop.org/software/systemd/man/latest/hostnamectl.html#chassis%20%5BTYPE%5D */ -}} +{{- /* Chassis type mapping: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.6.0.pdf */ -}} {{- $chassisType := "desktop" }} {{- if eq .chezmoi.os "darwin" }} {{- if contains "MacBook" (output "sysctl" "-n" "hw.model") }} @@ -8,7 +8,14 @@ {{- $chassisType = "desktop" }} {{- end }} {{- else if eq .chezmoi.os "linux" }} -{{- $chassisType = (output "hostnamectl" "--json=short" | mustFromJson).Chassis }} +{{- $chassisRaw := output "cat" "/sys/class/dmi/id/chassis_type" | trim }} +{{- if or (eq $chassisRaw "8") (eq $chassisRaw "9") (eq $chassisRaw "10") (eq $chassisRaw "14") }} +{{- $chassisType = "laptop" }} +{{- else if or (eq $chassisRaw "3") (eq $chassisRaw "4") (eq $chassisRaw "5") (eq $chassisRaw "6") (eq $chassisRaw "7") }} +{{- $chassisType = "desktop" }} +{{- else }} +{{- $chassisType = "desktop" }} +{{- end }} {{- else if eq .chezmoi.os "windows" }} {{- $chassisType = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "if ((Get-CimInstance -Class Win32_Battery | Measure-Object).Count -gt 0) { Write-Output 'laptop' } else { Write-Output 'desktop' }") | trim }} {{- end }} @@ -20,8 +27,8 @@ {{- $cpuCores = (output "sysctl" "-n" "hw.physicalcpu_max") | trim | atoi }} {{- $cpuThreads = (output "sysctl" "-n" "hw.logicalcpu_max") | trim | atoi }} {{- else if eq .chezmoi.os "linux" }} -{{- $cpuCores = (output "sh" "-c" "lscpu --online --parse | grep --invert-match '^#' | sort --field-separator=',' --key='2,4' --unique | wc --lines") | trim | atoi }} -{{- $cpuThreads = (output "sh" "-c" "lscpu --online --parse | grep --invert-match '^#' | wc --lines") | trim | atoi }} +{{- $cpuThreads = (output "nproc" "--all") | trim | atoi }} +{{- $cpuCores = (output "sh" "-c" "lscpu | grep 'Core(s) per socket' | awk '{print $4}'") | trim | atoi }} {{- else if eq .chezmoi.os "windows" }} {{- $cpuCores = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "(Get-CimInstance -ClassName 'Win32_Processor').NumberOfCores") | trim | atoi }} {{- $cpuThreads = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "(Get-CimInstance -ClassName 'Win32_Processor').NumberOfLogicalProcessors") | trim | atoi }}