Record nixpkgs.hostPlatform precedence gotcha in nix.md #27

Merged
vnprc merged 1 commit from agent/nix-hostplatform-precedence into master 2026-07-28 20:11:23 +01:00
Member

Records that nixpkgs.hostPlatform defined at any priority — including lib.mkDefault — silently discards the platform a builder passes as nixosSystem { system = platform; }, and corrects the disko snippet that currently teaches the opposite.

mkDefault behaves as a fallback nearly everywhere in the NixOS module system, which is exactly why this one is worth writing down: misc/nixpkgs.nix branches on hostPlatform.isDefined rather than on priority, so the lowest-priority definition wins over the builder's explicit argument. Nothing warns, because nixpkgs' own platform-conflict assertion keys off nixpkgs.localSystem's priority while eval-config.nix defines only nixpkgs.system.

Measured against the pinned nixpkgs b6018f87da91d19d0ab4cf979885689b469cdd41, evaluating with system = "aarch64-linux":

configuration resulting pkgs.stdenv.hostPlatform.system
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux" present x86_64-linux
line absent aarch64-linux
nixpkgs.hostPlatform = platform aarch64-linux

Zero warnings and zero failed assertions in the wrong case.

The disko replaces hardware-configuration.nix snippet carried nixpkgs.hostPlatform = lib.mkDefault platform. That is harmless when platform is already correct, but it models mkDefault as 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 as pkgs.stdenv.hostPlatform.systemconfig.nixpkgs.hostPlatform throws when undefined and config.nixpkgs.system reports 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 eval against the pinned nixpkgs revision, using pkgs.stdenv.hostPlatform.system on a full eval-config.nix evaluation. 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

Records that `nixpkgs.hostPlatform` defined at any priority — including `lib.mkDefault` — silently discards the platform a builder passes as `nixosSystem { system = platform; }`, and corrects the `disko` snippet that currently teaches the opposite. `mkDefault` behaves as a fallback nearly everywhere in the NixOS module system, which is exactly why this one is worth writing down: `misc/nixpkgs.nix` branches on `hostPlatform.isDefined` rather than on priority, so the lowest-priority definition wins over the builder's explicit argument. Nothing warns, because nixpkgs' own platform-conflict assertion keys off `nixpkgs.localSystem`'s priority while `eval-config.nix` defines only `nixpkgs.system`. Measured against the pinned nixpkgs `b6018f87da91d19d0ab4cf979885689b469cdd41`, evaluating with `system = "aarch64-linux"`: | configuration | resulting `pkgs.stdenv.hostPlatform.system` | |---|---| | `nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"` present | `x86_64-linux` | | line absent | `aarch64-linux` | | `nixpkgs.hostPlatform = platform` | `aarch64-linux` | Zero warnings and zero failed assertions in the wrong case. The `disko replaces hardware-configuration.nix` snippet carried `nixpkgs.hostPlatform = lib.mkDefault platform`. That is harmless when `platform` is already correct, but it models `mkDefault` as 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 as `pkgs.stdenv.hostPlatform.system` — `config.nixpkgs.hostPlatform` throws when undefined and `config.nixpkgs.system` reports 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 eval` against the pinned nixpkgs revision, using `pkgs.stdenv.hostPlatform.system` on a full `eval-config.nix` evaluation. 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
vnprc approved these changes 2026-07-28 20:11:15 +01:00
vnprc merged commit c6836a76cb into master 2026-07-28 20:11:23 +01:00
vnprc deleted branch agent/nix-hostplatform-precedence 2026-07-28 20:11:23 +01:00
Sign in to join this conversation.
No description provided.