Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ NIX_USER_TRUSTED := $(shell grep -qE "trusted-users.*=.*(\\*|$(shell whoami))" /
NAMED_HOSTS := galactica kyber matic pod viper
NIXOS_NAMED_HOSTS := $(filter matic viper,$(NAMED_HOSTS))
ISO_NAMED_HOSTS := $(filter matic viper,$(NAMED_HOSTS))
DMI_SYS_VENDOR ?= $(shell cat /sys/class/dmi/id/sys_vendor 2>/dev/null || true)
DMI_PRODUCT_NAME ?= $(shell cat /sys/class/dmi/id/product_name 2>/dev/null || true)

# Nix configuration system
NIX_SYSTEM := $(shell if [ "$(OS)" = "Darwin" ] && [ "$(ARCH)" = "arm64" ]; then \
Expand Down Expand Up @@ -106,6 +108,9 @@ DETECTED_HOST := $(shell \
echo "kyber"; \
elif [ "$$hostname" = "matic" ]; then \
echo "matic"; \
elif [ "$(DMI_SYS_VENDOR)" = "Framework" ] \
&& echo "$(DMI_PRODUCT_NAME)" | grep -q "Laptop 13.*AMD Ryzen AI 300"; then \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DMI product-name match is a moving target: grep -q "Laptop 13.*AMD Ryzen AI 300" matches the current Framework AMD 300 DMI string (Laptop 13 (AMD Ryzen AI 300 Series)), but a future Framework BIOS or SKU rename would silently disable auto-detection — make build would still work with HOST=matic, but the auto-detect UX advertised in the README would quietly regress. Consider pinning the exact expected value (or leaving a comment pointing at the source of truth in nixos-hardware) so a future mismatch surfaces as an obvious diff rather than a silent behavior change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer printf over echo for arbitrary values: echo builtin behavior differs across shells when the argument starts with -n/-e or contains backslashes. DMI_PRODUCT_NAME is kernel-provided so this is unlikely in practice, but printf '%s\n' "$(DMI_PRODUCT_NAME)" | grep -q "Laptop 13.*AMD Ryzen AI 300" is the standard, portable form and matches the rest of the shell in this Makefile.

Suggested change
&& echo "$(DMI_PRODUCT_NAME)" | grep -q "Laptop 13.*AMD Ryzen AI 300"; then \
elif [ "$(DMI_SYS_VENDOR)" = "Framework" ] \
&& printf '%s\n' "$(DMI_PRODUCT_NAME)" | grep -q "Laptop 13.*AMD Ryzen AI 300"; then \

echo "matic"; \
Comment on lines +111 to +113

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using echo to print variables that can contain arbitrary system or user input (such as DMI_PRODUCT_NAME) can lead to unexpected behavior if the value starts with a hyphen (interpreted as an option like -n) or contains backslashes. It is safer and more robust to use printf '%s\n' instead of echo.

			elif [ "$(DMI_SYS_VENDOR)" = "Framework" ] \
				&& printf '%s\n' "$(DMI_PRODUCT_NAME)" | grep -q "Laptop 13.*AMD Ryzen AI 300"; then \
				echo "matic"; \

else \
echo ""; \
fi; \
Expand Down
7 changes: 6 additions & 1 deletion named-hosts/matic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ If the boot chain changes (firmware/kernel update), TPM2 will refuse and fall ba
## Building and Switching

```bash
make build HOST=matic && make switch HOST=matic
make build
make switch
```

The Makefile detects matic from its Framework 13 AMD AI 300 DMI identity, even
when a recovery generation still uses a generic hostname. `HOST=matic` remains
available as an explicit override.

Or use `boot` instead of `switch` for major config changes (avoids dbus reload issues):

```bash
Expand Down
14 changes: 14 additions & 0 deletions spec/make_build_host_resolution_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,18 @@ The output should include '.#darwinConfigurations.galactica.system'
The output should not include '.#nixosConfigurations.matic.config.system.build.toplevel'
End

It 'detects matic from Framework 13 AMD AI 300 DMI data when the hostname is generic'
When run bash -c 'make build OS=Linux ARCH=x86_64 NIX_SYSTEM=x86_64-linux NIX_CONFIG_TYPE=nixosConfigurations DMI_SYS_VENDOR=Framework DMI_PRODUCT_NAME="Laptop 13 (AMD Ryzen AI 300 Series)" NIX_EXEC=nix NIX_ENV=ok NIX_FLAGS= NIX_USER_TRUSTED=yes SUDO=env 2>/dev/null; cat "$MOCK_LOG"'
The status should be success
The output should include '--flake .#matic'
The output should not include '--flake .#x86_64-linux'
End

It 'switches the detected matic host through the generic NixOS path'
When run bash -c 'make nix-switch OS=Linux ARCH=x86_64 NIX_SYSTEM=x86_64-linux NIX_CONFIG_TYPE=nixosConfigurations DMI_SYS_VENDOR=Framework DMI_PRODUCT_NAME="Laptop 13 (AMD Ryzen AI 300 Series)" NIX_EXEC=nix NIX_ENV=ok NIX_FLAGS= NIX_USER_TRUSTED=yes SUDO=env 2>/dev/null; cat "$MOCK_LOG"'
The status should be success
The output should include '-- switch --flake .#matic'
The output should not include '-- switch --flake .#x86_64-linux'
End

End
Loading