Creating a bootable USB with custom firmware support

Hi all,

I’d like to create a bootable USB with some custom firmware enabled for my new laptop however I seem to be failing to grasp how to set this up…

I’m basically following the guide here: Building bootable ISO image — nix.dev documentation and I figured I wanted to enable “rtw89-firmware” and combine this with the definition from the nixos-hardware repo: nixos-hardware/default.nix at 0a8b8054c9920368a3c15e6d766188fdf04b736f · NixOS/nixos-hardware · GitHub

My current attempt:

{ pkgs, modulesPath, lib, config, ... }: {
  imports = [
    "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
  ];

  # use the latest Linux kernel
  boot = {
    kernelModules = [ "acpi_call" ];
    extraModulePackages = with config.boot.kernelPackages; [ acpi_call rtw89 ];
    kernelPackages = pkgs.linuxPackages_latest;
  };

  # Needed for https://github.com/NixOS/nixpkgs/issues/58959
  #boot.supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ];

  # For suspending to RAM, set Config -> Power -> Sleep State to "Linux" in EFI.

  # amdgpu.backlight=0 makes the backlight work
  # acpi_backlight=none allows the backlight save/load systemd service to work.
  boot.kernelParams = ["amdgpu.backlight=0" "acpi_backlight=none"];

  # Wifi support
  hardware.enableRedistributableFirmware = true;
}

I’m trying to build an ISO image with:

nix-shell -p nixos-generators -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/b5182c214fac1e6db9f28ed8a7cfc2d0c255c763.tar.gz --run "nixos-generate --format iso --configuration ./nixos-bootable-img.nix -o result"

But this fails with

error: undefined variable ‘rtw89’ at /home/user/tmp/nixos-bootable-img.nix:9:72

Can anyone point me in the right direction here? From my perspective (which is obviously wrong) I’d expect the firmware to exist in the pkgs.

Thanks!

Something funky is going on with the value of pkgs. I too get the same error as you, but if I use

    import
      (fetchTarball
         { url = "https://github.com/NixOS/nixpkgs/archive/b5182c214fac1e6db9f28ed8a7cfc2d0c255c763.tar.gz";
           sha256 = "1q5pphh16lq7pch0ihad1mr6fll0gf6d1rv9z1wdmlzqlgyq50ix";
         }
      )
      {};

instead of the pkgs given to me by the module argument, the error goes away.

1 Like

Thanks @ursi ! Not sure why but that seemed to do the trick! (I’m interested in the root cause though)

Full snippet used to create the iso in case someone runs into this issue:

{ pkgs, modulesPath, lib, config, ... }: 
 let tmpPkgs = import
      (fetchTarball
         { url = "https://github.com/NixOS/nixpkgs/archive/b5182c214fac1e6db9f28ed8a7cfc2d0c255c763.tar.gz";
           sha256 = "1q5pphh16lq7pch0ihad1mr6fll0gf6d1rv9z1wdmlzqlgyq50ix";
         }
      )
      {};
  in
{
  imports = [
    "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
  ];

  # use the latest Linux kernel
  boot = {
    kernelModules = [ "acpi_call" ];
    extraModulePackages = with config.boot.kernelPackages; [ acpi_call rtw89 ];
    kernelPackages = tmpPkgs.linuxPackages_latest;
  };

  # Needed for https://github.com/NixOS/nixpkgs/issues/58959
  #boot.supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ];

  # For suspending to RAM, set Config -> Power -> Sleep State to "Linux" in EFI.

  # amdgpu.backlight=0 makes the backlight work
  # acpi_backlight=none allows the backlight save/load systemd service to work.
  boot.kernelParams = ["amdgpu.backlight=0" "acpi_backlight=none"];

  # Wifi support
  hardware.enableRedistributableFirmware = true;
}

This is due to an old bug in Nix that I opened an issue in 2017 and forgot the bug exists when I wrote the tutorial.

1 Like

Fixed in iso: fix NIX_PATH propagation · nix-dot-dev/nix.dev@6b95160 · GitHub

Thanks for reporting this!

1 Like