|
1 | 1 | { config, pkgs, lib, ... }: |
2 | 2 | { |
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; |
6 | 14 | 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. |
9 | 17 | ''; |
10 | 18 | } |
11 | 19 | ]; |
12 | 20 |
|
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 | + ]; |
20 | 37 |
|
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} |
22 | 41 |
|
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 |
26 | 45 |
|
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 | + ''; |
33 | 53 | }; |
34 | 54 |
|
35 | 55 | options.hardware.asahi = { |
36 | | - extractPeripheralFirmware = lib.mkOption { |
| 56 | + usePeripheralFirmwareFromNixStore = lib.mkOption { |
37 | 57 | type = lib.types.bool; |
38 | | - default = true; |
| 58 | + default = false; |
39 | 59 | 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. |
42 | 69 | ''; |
43 | 70 | }; |
44 | 71 |
|
|
0 commit comments