Record nixpkgs.hostPlatform precedence gotcha in nix.md #27
No reviewers
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
allod/memory!27
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "agent/nix-hostplatform-precedence"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Records that
nixpkgs.hostPlatformdefined at any priority — includinglib.mkDefault— silently discards the platform a builder passes asnixosSystem { system = platform; }, and corrects thediskosnippet that currently teaches the opposite.mkDefaultbehaves as a fallback nearly everywhere in the NixOS module system, which is exactly why this one is worth writing down:misc/nixpkgs.nixbranches onhostPlatform.isDefinedrather than on priority, so the lowest-priority definition wins over the builder's explicit argument. Nothing warns, because nixpkgs' own platform-conflict assertion keys offnixpkgs.localSystem's priority whileeval-config.nixdefines onlynixpkgs.system.Measured against the pinned nixpkgs
b6018f87da91d19d0ab4cf979885689b469cdd41, evaluating withsystem = "aarch64-linux":pkgs.stdenv.hostPlatform.systemnixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"presentx86_64-linuxaarch64-linuxnixpkgs.hostPlatform = platformaarch64-linuxZero warnings and zero failed assertions in the wrong case.
The
disko replaces hardware-configuration.nixsnippet carriednixpkgs.hostPlatform = lib.mkDefault platform. That is harmless whenplatformis already correct, but it modelsmkDefaultas overridable in the one place it is not, so it is now a plain assignment with a pointer to the new section. The entry also records that a built system's platform must be read aspkgs.stdenv.hostPlatform.system—config.nixpkgs.hostPlatformthrows when undefined andconfig.nixpkgs.systemreports the discarded value, so both mislead when verifying the fact survived.Risk
R0. Documentation only, in the public memory repo. No code, no generated behavior, no identity material. The corrected snippet is illustrative and is not imported by any build.
Validation
The three-way comparison above was run with
nix evalagainst the pinned nixpkgs revision, usingpkgs.stdenv.hostPlatform.systemon a fulleval-config.nixevaluation. Control cases confirm the fix works in both directions: removing the line and assigning the real platform both yield the inventory value.Refs allod/vm#1
Refs allod/archetypes#14