nix incantations to build libreboot

... along with a tale of a broken SeaBIOS commit

i tend to like using Libreboot on the computers of mine that support it - which is many of them, because i have far too many ThinkPads.

while setting up Libreboot on a ThinkPad T420, i ran into a SeaBIOS bug - the AHCI initialization code had been recently updated, and it seemed to have broken things…

<irys> ooh this is fun. seabios commit 8863cbbd15a73b03153553c562f5b1fb939ad4d7 (ahci: add controller reset) breaks ahci entirely on t420
<irys> cbmem console on that seabios commit has a timeout then "AHCI/0: device not ready"
<irys> AHCI works fine if i change config/seabios/default/target.cfg to use the immediate previous seabios commit (df9dd418b3b0e586cb208125094620fc7f90f23d)
<irys> works in grub payload either way though
<irys> here, `cbmem -c` after booting the broken rev: https://0x0.st/84oQ.log
<irys> compared to the working one https://0x0.st/84o1.log

the SeaBIOS version in Libreboot was rolled back while we debugged the issue, a patch was written to hopefully restore functionality, which i tested and confirmed it did, and then that patch, with a revert of the SeaBIOS version rollback, went into Libreboot.

skipping back, though - actually getting to the point of figuring out the above was… slightly problematic…

i use NixOS on most of my machines, because declarative system configs are fun. however, some parts of the Libreboot build scripts; and some of the build processes for the individual components built in Libreboot (looking at you, GRUB2…) assume they’re running on a system that conforms to the Filesystem Hierarchy Standard, which NixOS does not.

thankfully, nixpkgs has the buildFHSEnv family of helpers - so here’s a shell.nix that sets up a FHS environment suitable for building Libreboot.

let
  nixpkgs = builtins.fetchTarball {
    name = "source";
    url = "https://github.com/NixOS/nixpkgs/archive/3e362ce63e16b9572d8c2297c04f7c19ab6725a5.tar.gz";
    sha256 = "sha256:03csxn73wxlqffp3sscjg2mf4a4xl62yawhaxm6dhgwchjnq1nnx";
  };

  pkgs = import nixpkgs {};
  fhsenv = pkgs.buildFHSUserEnv {
    name = "lbmk-deps";
    targetPkgs = _: (with pkgs; [
      bashInteractive
      gnat
      ccache
      pkg-config-unwrapped
      cmake
      autoconf
      automake
      libtool
      bc
      m4
      flex
      bison
      zlib
      gettext
      ncurses
      freetype
      p7zip
      unzip
      innoextract
      openssl
      gnutls
      libuuid
      swig

      (python3.withPackages (py: with py; [
        setuptools
      ]))
    ]);

    extraOutputsToInstall = [ "dev" ];
    extraBuildCommands = ''
      # grub2 source expects unifont to be in /usr/share/fonts/unifont, but adding unifont
      # to targetPkgs above will put it in /usr/share/fonts directly, so symlink it in place
      mkdir -p $out/usr/share/fonts
      ln -s ${pkgs.unifont}/share/fonts $out/usr/share/fonts/unifont
    '';

    runScript = "bash";
    profile = ''
      export XBMK_THREADS=`nproc`
      export LIBRARY_PATH=/usr/lib
      export C_INCLUDE_PATH=/usr/include
      export CPLUS_INCLUDE_PATH=/usr/include
    '';
  };

in fhsenv.env

(here’s a link to a file of the above, so you don’t have to copy/paste)

we got there in the end though!