Skip to content

Commit 7df41aa

Browse files
committed
peripheral-firmware: extract on boot by default
This improves the situation for flake users, as previously they had to either add the non-redistributable firmware to their repositories or go without the firmware. This change also brings the ISO into line with the regular NixOS modules as storing the peripheral firmware in the Nix Store is no longer a requirement.
1 parent 3d1c6c2 commit 7df41aa

File tree

3 files changed

+60
-62
lines changed

3 files changed

+60
-62
lines changed

apple-silicon-support/modules/peripheral-firmware/default.nix

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,71 @@
11
{ config, pkgs, lib, ... }:
22
{
3-
config = lib.mkIf config.hardware.asahi.enable {
4-
assertions = lib.mkIf config.hardware.asahi.extractPeripheralFirmware [
5-
{ assertion = config.hardware.asahi.peripheralFirmwareDirectory != null;
3+
imports = [
4+
(lib.mkRemovedOptionModule [ "hardware" "asahi" "extractPeripheralFirmware" ] "This option is no longer necessary as the peripheral firmware will be extracted every boot automatically.")
5+
];
6+
7+
config = let
8+
inherit (lib) mkIf;
9+
cfg = config.hardware.asahi;
10+
pkgs' = cfg.pkgs;
11+
in mkIf config.hardware.asahi.enable {
12+
assertions = mkIf cfg.usePeripheralFirmwareFromNixStore [
13+
{ assertion = cfg.peripheralFirmwareDirectory != null;
614
message = ''
7-
Asahi peripheral firmware extraction is enabled but the firmware
8-
location appears incorrect.
15+
Managing the peripheral firmware in the Nix Store is enabled
16+
but the firmware location appears incorrect.
917
'';
1018
}
1119
];
1220

13-
hardware.firmware = let
14-
pkgs' = config.hardware.asahi.pkgs;
15-
in
16-
lib.mkIf ((config.hardware.asahi.peripheralFirmwareDirectory != null)
17-
&& config.hardware.asahi.extractPeripheralFirmware) [
18-
(pkgs.stdenv.mkDerivation {
19-
name = "asahi-peripheral-firmware";
21+
hardware.firmware = mkIf (cfg.peripheralFirmwareDirectory != null && cfg.usePeripheralFirmwareFromNixStore) [
22+
(pkgs.stdenv.mkDerivation {
23+
name = "asahi-peripheral-firmware";
24+
25+
nativeBuildInputs = [ pkgs'.asahi-fwextract pkgs.cpio ];
26+
27+
buildCommand = ''
28+
mkdir extracted
29+
asahi-fwextract ${cfg.peripheralFirmwareDirectory} extracted
30+
31+
mkdir -p $out/lib/firmware
32+
cat extracted/firmware.cpio | cpio -id --quiet --no-absolute-filenames
33+
mv vendorfw/* $out/lib/firmware
34+
'';
35+
})
36+
];
2037

21-
nativeBuildInputs = [ pkgs'.asahi-fwextract pkgs.cpio ];
38+
boot.postBootCommands = mkIf (!cfg.usePeripheralFirmwareFromNixStore) ''
39+
echo Extracting Asahi firmware...
40+
mkdir -p /tmp/.fwsetup/{esp,extracted}
2241
23-
buildCommand = ''
24-
mkdir extracted
25-
asahi-fwextract ${config.hardware.asahi.peripheralFirmwareDirectory} extracted
42+
mount /dev/disk/by-partuuid/`cat /proc/device-tree/chosen/asahi,efi-system-partition` /tmp/.fwsetup/esp
43+
${pkgs'.asahi-fwextract}/bin/asahi-fwextract /tmp/.fwsetup/esp/asahi /tmp/.fwsetup/extracted
44+
umount /tmp/.fwsetup/esp
2645
27-
mkdir -p $out/lib/firmware
28-
cat extracted/firmware.cpio | cpio -id --quiet --no-absolute-filenames
29-
mv vendorfw/* $out/lib/firmware
30-
'';
31-
})
32-
];
46+
pushd /tmp/.fwsetup/
47+
cat /tmp/.fwsetup/extracted/firmware.cpio | ${pkgs.cpio}/bin/cpio -id --quiet --no-absolute-filenames
48+
mkdir -p /lib/firmware
49+
mv vendorfw/* /lib/firmware
50+
popd
51+
rm -rf /tmp/.fwsetup
52+
'';
3353
};
3454

3555
options.hardware.asahi = {
36-
extractPeripheralFirmware = lib.mkOption {
56+
usePeripheralFirmwareFromNixStore = lib.mkOption {
3757
type = lib.types.bool;
38-
default = true;
58+
default = false;
3959
description = ''
40-
Automatically extract the non-free non-redistributable peripheral
41-
firmware necessary for features like Wi-Fi.
60+
By default, the non-free non-redistributable peripheral firmware is
61+
automatically extracted every boot. If you want more purity,
62+
this option will add the firmware to the Nix Store and manage it
63+
like all other firmware in NixOS.
64+
65+
The firmware is necessary for features like Wi-Fi.
66+
67+
It is not recommended for flake users to enable this option as the
68+
firmware is non-redistributable.
4269
'';
4370
};
4471

docs/uefi-standalone.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Start the Mac, and U-Boot should start booting from the USB drive automatically.
137137

138138
<details>
139139
<summary>If "mounting `/dev/root` on `/mnt-root/iso` failed: No such file or directory" during boot…</summary>
140-
140+
141141
1. Was the ISO transferred to your flash drive correctly as described above? `dd` is the only correct way to do this. The ISO must be transferred to the drive block device itself, not a partition on the drive.
142142
2. There is sometimes a [race condition](https://github.com/tpwrules/nixos-apple-silicon/issues/60) which causes booting to fail. Reboot the machine and try again.
143143
3. Some flash drives have quirks. Try a different drive, or use the following steps:
@@ -168,7 +168,7 @@ Identify the number of the new root partition (type code 8300, typically second
168168
```
169169
nixos# sgdisk /dev/nvme0n1 -p
170170
Disk /dev/nvme0n1: 244276265 sectors, 931.8 GiB
171-
Model: APPLE SSD AP1024Q
171+
Model: APPLE SSD AP1024Q
172172
Sector size (logical/physical): 4096/4096 bytes
173173
Disk identifier (GUID): 27054D2E-307A-41AA-9A8C-3864D56FAF6B
174174
Partition table holds up to 128 entries
@@ -180,9 +180,9 @@ Total free space is 0 sectors (0 bytes)
180180
Number Start (sector) End (sector) Size Code Name
181181
1 6 128005 500.0 MiB FFFF iBootSystemContainer
182182
2 128006 219854567 838.2 GiB AF0A Container
183-
3 219854568 220465127 2.3 GiB AF0A
184-
4 220465128 220590311 489.0 MiB EF00
185-
5 220590312 242965550 85.4 GiB 8300
183+
3 219854568 220465127 2.3 GiB AF0A
184+
4 220465128 220590311 489.0 MiB EF00
185+
5 220590312 242965550 85.4 GiB 8300
186186
6 242965551 244276259 5.0 GiB FFFF RecoveryOSContainer
187187
```
188188

@@ -230,15 +230,7 @@ Add the `./apple-silicon-support` directory to the imports list and switch off t
230230

231231
The configuration above is the minimum required to produce a bootable system, but you can further edit the file as desired to perform additional configuration. Uncomment the relevant options and change their values as explained in the file. Note that some advertised features may not work properly at this time. Refer to the [NixOS installation manual](https://nixos.org/manual/nixos/stable/index.html#ch-configuration) for further guidance.
232232

233-
Various non-free non-redistributable peripheral firmware files are required to use system hardware like Wi-Fi. The Asahi Linux installer grabs these from macOS and stores them on the EFI system partition when it is created. The NixOS installer loads them from there while booting so that all hardware is available during installation. By default, the Apple Silicon support module will automatically reference the files in the EFI system partition and incorporate them into your configuration to be managed by the normal NixOS mechanisms.
234-
235-
Currently, the only supported way to update the peripheral firmware files is to destroy and re-create the EFI system partition, so they will not change unexpectedly. If you do not want the impurity of referencing them (or are using flakes where this is prohibited), copy them off the EFI system partition (e.g. on the installation ISO `mkdir -p /mnt/etc/nixos/firmware && cp /mnt/boot/asahi/{all_firmware.tar.gz,kernelcache*} /mnt/etc/nixos/firmware`) and specify this path in your configuration:
236-
```
237-
# Specify path to peripheral firmware files.
238-
hardware.asahi.peripheralFirmwareDirectory = ./firmware;
239-
# Or disable extraction and management of them completely.
240-
# hardware.asahi.extractPeripheralFirmware = false;
241-
```
233+
Various non-free non-redistributable peripheral firmware files are required to use system hardware like Wi-Fi. The Asahi Linux installer grabs these from macOS and stores them on the EFI system partition when it is created. The NixOS installer loads them from there while booting so that all hardware is available during installation. By default, the Apple Silicon support module will also load the firmware from EFI system partition rather than being managed by the normal NixOS mechanisms.
242234

243235
If you want to install a desktop environment, you will have to uncomment the option to enable X11 and NetworkManager, then add an option to include your favorite desktop environment. You may also wish to include graphical packages such as `firefox` in `environment.systemPackages`. For example, to install Xfce:
244236
```

iso-configuration/installer-configuration.nix

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
swapDevices = lib.mkOverride 60 [ ];
2929
fileSystems = lib.mkOverride 60 config.lib.isoFileSystems;
3030

31-
boot.postBootCommands = let
32-
inherit (config.hardware.asahi.pkgs) asahi-fwextract;
33-
in ''
31+
boot.postBootCommands = ''
3432
for o in $(</proc/cmdline); do
3533
case "$o" in
3634
live.nixos.passwd=*)
@@ -39,26 +37,8 @@
3937
;;
4038
esac
4139
done
42-
43-
echo Extracting Asahi firmware...
44-
mkdir -p /tmp/.fwsetup/{esp,extracted}
45-
46-
mount /dev/disk/by-partuuid/`cat /proc/device-tree/chosen/asahi,efi-system-partition` /tmp/.fwsetup/esp
47-
${asahi-fwextract}/bin/asahi-fwextract /tmp/.fwsetup/esp/asahi /tmp/.fwsetup/extracted
48-
umount /tmp/.fwsetup/esp
49-
50-
pushd /tmp/.fwsetup/
51-
cat /tmp/.fwsetup/extracted/firmware.cpio | ${pkgs.cpio}/bin/cpio -id --quiet --no-absolute-filenames
52-
mkdir -p /lib/firmware
53-
mv vendorfw/* /lib/firmware
54-
popd
55-
rm -rf /tmp/.fwsetup
5640
'';
5741

58-
# can't legally be incorporated into the installer image
59-
# (and is automatically extracted at boot above)
60-
hardware.asahi.extractPeripheralFirmware = false;
61-
6242
isoImage.squashfsCompression = "zstd -Xcompression-level 6";
6343

6444
environment.systemPackages = with pkgs; [
@@ -88,7 +68,6 @@
8868
enable = true;
8969
settings.General.EnableNetworkConfiguration = true;
9070
};
91-
9271

9372
nixpkgs.overlays = [
9473
(final: prev: {

0 commit comments

Comments
 (0)