From 776b8bf1511e73a8da1f3d684b908073a27bcbec Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sun, 12 Jan 2020 16:09:02 -0500 Subject: [PATCH] initrd-vendor: init module This is required for some devices, as some features only work when firmwares are loaded on some devices. Here, `google-walleye` `gsi.rndis` usb gadget requires the IPA firmware. --- modules/initrd-vendor.nix | 37 +++++++++++++++++++++++++++++++++++++ modules/module-list.nix | 1 + 2 files changed, 38 insertions(+) create mode 100644 modules/initrd-vendor.nix diff --git a/modules/initrd-vendor.nix b/modules/initrd-vendor.nix new file mode 100644 index 00000000..0b6855f5 --- /dev/null +++ b/modules/initrd-vendor.nix @@ -0,0 +1,37 @@ +# This module handles well-known "vendor" partitions. +# +# Relevant upstream documentation: +# * https://www.kernel.org/doc/html/v4.14/driver-api/firmware/fw_search_path.html +# +# Note that we'll be using `firmware_class.path=/vendor/firmware` on the +# command-line to make the firmware path known ASAP without requiring run-time +# configuration. The NixOS stage-2 will configure `/sys/module/firmware_class/parameters/path` +# as expected. +{ config, lib, ... }: + +let + device_info = config.mobile.device.info; + vendor_device = + if config.mobile.system.type == "android" then + if device_info ? ab_partitions && device_info.ab_partitions then + # Force slot "A" on A/B, we would recommend end-users to flash the most + # compatible vendor partition to both slots anyway. + "/dev/disk/by-partlabel/vendor_a" + else + # Assume "vendor" partlabel on other android devices. + "/dev/disk/by-partlabel/vendor" + else null + ; +in +lib.mkMerge [ + (lib.mkIf (vendor_device != null) { + # FIXME: add "firmware_class.path=/vendor/firmware" to kernel cmdline + boot.specialFileSystems = { + "/vendor" = { + device = vendor_device; + fsType = "ext4"; + options = [ "nosuid" "noexec" "nodev" ]; + }; + }; + }) +] diff --git a/modules/module-list.nix b/modules/module-list.nix index aa4e8fdc..b1411e3d 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -24,6 +24,7 @@ ./initrd-splash.nix ./initrd-ssh.nix ./initrd-usb.nix + ./initrd-vendor.nix ./initrd.nix ./mobile-device.nix ./nixpkgs.nix