Stumble during nixpkgs minimal-bootstrap

Hi folks,

I’m attempting to build a nixpkgs toolchain starting from minimal bootstrap,
with several unorthodoxies:

  1. nix (2.24.9) built from source.
  2. custom store location (/home/roland/nixroot/nix/store instead of /nix/store)
  3. Local clone of nixpkgs (/home/roland/nixroot/nixpkgs, with 24.05 branch checked out)

Following instructions in nixpkgs/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/
bootstrap-sources.nix and make-bootstrap-sources.nix:

  1. prepared stage0-posix-1.6.0-source from clone of GitHub - oriansj/stage0-posix: A place for public review of the posix port of stage0
    (1.6.0 since this is the version that the 24.05 nixpkgs uses), removed some paths + applied patch to
    parallel make-bootstrap-sources.nix.
  2. adopted patched source tree into local nix store:
    nix-store --add-fixed --recursive sha256 ./stage0-posix-1.6.0-source.
  3. corrected nixpkgs expected sha256s in bootstrap-sources.nix and hex0.nix

Coming here because trouble appears to have accepted my invitation :slight_smile:

Things that work:

$ export NIX_PATH=/home/roland/nixroot
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.hex0
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.hex1
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.hex2-0
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.catm
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.M0_hex2
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.M0
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.cc_arch-0_hex2
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.cc_arch-1_hex2
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.cc_arch
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.M2
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.blood-elf-0
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.M1-0
$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.hex2-1

(look ma, awesome progress)

But now this next target fails

$ nix build -f '<nixpkgs>' minimal-bootstrap.stage0-posix.mescc-tools-boot.hex2_linker-0_M1

Error looks like misdirection – I don’t believe we’re actually missing a {

error: builder for '/home/roland/nixroot/nix/store/gng04lkk280m2jz90p8gvqb94f5nyaw9-hex2_linker-0.M1-1.6.0.drv' failed with exit code 1;
       last 2 log lines:
       > /home/roland/nixroot/nix/store/0j9jp0xkxcr7f7mp4r43bap9zkd0rz2r-stage0-posix-1.6.0-source/M2libc/amd64/linux/unistd.c:186:ERROR in create_struct
       >  Missing {

Inspecting the offending file in nix store, we have at line 186:

int uname(struct utsname* unameData)
{
	asm("lea_rdi,[rsp+DWORD] %8"
	    "mov_rdi,[rdi]"
	    "mov_rax, %63"
	    "syscall");
}

This looks reasonable to me, but I do notice this is the first use of ‘struct foo…’ syntax in unistd.c
Everything that precedes it uses native data types.

In sys/unistd.h we find a reasonable declaration:

struct utsname
{
	char sysname[65];    /* Operating system name (e.g., "Linux") */
	char nodename[65];   /* Name within "some implementation-defined network" */
	char release[65];    /* Operating system release (e.g., "2.6.28") */
	char version[65];    /* Operating system version */
	char machine[65];    /* Hardware identifier */
};

Any advice as to how to diagnose this? Experiencing some FOTLNSP

I’m planning to try:

  1. verify that released nixpkgs-24.05 with nix store in /nix builds minimal-bootstrap.stage0-posix.mescc-tools-boot.hex2_linker-0_M1
  2. verify that my manually-prepared stage0-posix-1.6.0-source actually matches what make-bootstrap-sources constructs.
  3. try more recent stage0-posix-1.7.0-source

Hoping one of these sheds some light

Found something provocative: looking at changelog from stage0-posix 1.6.0 → stage0-posix 1.7.0:

+** stage0-posix-amd64

    • Fix encoding of some mov instructions to actually use 64-bit registers rather than 32
    • Fix encoding for sal_rax,cl.
    • Fix regression caused by M2libc’s fb6701a73189afca152ea1154650c315df4e6a93 commit

and in stage0-posix/M2libc:

$ git log fb6701a73189 -1
commit fb6701a73189afca152ea1154650c315df4e6a93
Author: Jeremiah Orians jeremiah@pdp10.guru
Date: Sun Feb 4 20:52:23 2024 -0500

Move the utsname struct definition to the proper place so that we
don't have duplication

Ok, let’s inspect nixpkgs in a more recent state. I happen to have a nixpkgs clone handy, pointing at a 12sep2024 revision, let’s inspect its bootstrap-sources.nix

  name = "stage0-posix-${version}-source";
  version = "1.6.0";
  rev = "Release_${version}";
  outputHashAlgo = "sha256";
  outputHash = "sha256-epUaShjKiAd749ICvc6rS6WhUkS8R4heKuPdwUjEtsQ=";

Hold on, that’s looks like the same output hash as in 24.05 !?

Last commit (at least up to 12sep2024) in minimal-bootstrap.nix… was this one:

commit b7b6f8433755afd81572b65c90cc71d4a544b537
Author: Emily Trau <emily@downunderctf.com>
Date:   Thu Nov 2 23:27:07 2023 -0700

    minimal-bootstrap-sources: unstable-2023-05-02 -> 1.6.0

that commit consists of this change:

index 715d261eea4f..7f2e8ab81a39 100644
--- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/bootstrap-sources.nix
+++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/bootstrap-sources.nix
@@ -2,12 +2,11 @@
 }:
 
 rec {
-  name = "stage0-posix-${version}-${rev}-source";
-  # Pinned from https://github.com/oriansj/stage0-posix/commit/3189b5f325b7ef8b88e3edec7c1cde4fce73c76c
-  version = "unstable-2023-05-02";
-  rev = "3189b5f325b7ef8b88e3edec7c1cde4fce73c76c";
+  name = "stage0-posix-${version}-source";
+  version = "1.6.0";
+  rev = "Release_${version}";
   outputHashAlgo = "sha256";
-  outputHash = "sha256-7Y9+csTwZIQp0WGbagX+Q4f2zavN7AUk1TSBp/H5Xks=";
+  outputHash = "sha256-epUaShjKiAd749ICvc6rS6WhUkS8R4heKuPdwUjEtsQ=";
 
   /*
   Since `make-minimal-bootstrap-sources` requires nixpkgs and nix it

And… there’s the problem – the 1.6.0 tag in the upstream stage0-posix repo (as of 20oct2024) doesn’t reproduce the hash. Perhaps its been repointed? I’m not sure the best way to figure out which
revision in upstream repo is being used (skill issue), but probably one of them.

Best guess without more digging is the 3189b5f32 commit (from May 2023),