about summary refs log tree commit diff
path: root/apple-silicon-support/modules/peripheral-firmware/default.nix
blob: e10632ff2a5e43d1121ac5cfb95e5db378249f5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{ config, pkgs, lib, ... }:
{
  config = lib.mkIf config.hardware.asahi.enable {
    assertions = lib.mkIf config.hardware.asahi.extractPeripheralFirmware [
      { assertion = config.hardware.asahi.peripheralFirmwareDirectory != null;
        message = ''
          Asahi peripheral firmware extraction is enabled but the firmware
          location appears incorrect.
        '';
      }
    ];

    hardware.firmware = let
      pkgs' = config.hardware.asahi.pkgs;
    in
      lib.mkIf ((config.hardware.asahi.peripheralFirmwareDirectory != null)
          && config.hardware.asahi.extractPeripheralFirmware) [
        (pkgs.stdenv.mkDerivation {
          name = "asahi-peripheral-firmware";

          nativeBuildInputs = [ pkgs'.asahi-fwextract pkgs.cpio ];

          buildCommand = ''
            mkdir extracted
            asahi-fwextract ${config.hardware.asahi.peripheralFirmwareDirectory} extracted

            mkdir -p $out/lib/firmware
            cat extracted/firmware.cpio | cpio -id --quiet --no-absolute-filenames
            mv vendorfw/* $out/lib/firmware
          '';
        })
      ];
  };

  options.hardware.asahi = {
    extractPeripheralFirmware = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = ''
        Automatically extract the non-free non-redistributable peripheral
        firmware necessary for features like Wi-Fi.
      '';
    };

    peripheralFirmwareDirectory = lib.mkOption {
      type = lib.types.nullOr lib.types.path;

      default = lib.findFirst (path: builtins.pathExists (path + "/all_firmware.tar.gz")) null
        [
          # path when the system is operating normally
          /boot/asahi
          # path when the system is mounted in the installer
          /mnt/boot/asahi
        ];

      description = ''
        Path to the directory containing the non-free non-redistributable
        peripheral firmware necessary for features like Wi-Fi. Ordinarily, this
        will automatically point to the appropriate location on the ESP. Flake
        users and those interested in maximum purity will want to copy those
        files elsewhere and specify this manually.

        Currently, this consists of the files `all-firmware.tar.gz` and
        `kernelcache*`. The official Asahi Linux installer places these files
        in the `asahi` directory of the EFI system partition when creating it.
      '';
    };
  };
}