|
| 1 | +{ lib, pkgs, ... }: |
| 2 | + |
| 3 | +let |
| 4 | + dtbName = "sc8280xp-lenovo-thinkpad-x13s.dtb"; |
| 5 | + dtb = "${pkgs.linux}/dtbs/qcom/${dtbName}"; |
| 6 | + # Version the dtb based on the kernel |
| 7 | + dtbEfiPath = "dtbs/x13s-${pkgs.linux.version}.dtb"; |
| 8 | + cfg = { |
| 9 | + wifiMac = "e4:65:38:52:22:a9"; |
| 10 | + bluetoothMac = "E4:25:18:22:44:AA"; |
| 11 | + }; |
| 12 | + inherit (lib) mkDefault; |
| 13 | +in |
| 14 | +{ |
| 15 | + imports = [ |
| 16 | + ../. |
| 17 | + ../../../common/pc/laptop |
| 18 | + ]; |
| 19 | + |
| 20 | + boot = { |
| 21 | + loader.systemd-boot.extraFiles = { |
| 22 | + "${dtbEfiPath}" = dtb; |
| 23 | + }; |
| 24 | + |
| 25 | + kernelParams = mkDefault [ |
| 26 | + # needed to boot |
| 27 | + "dtb=${dtbEfiPath}" |
| 28 | + |
| 29 | + # jhovold recommended |
| 30 | + "clk_ignore_unused" |
| 31 | + "pd_ignore_unused" |
| 32 | + "arm64.nopauth" |
| 33 | + ]; |
| 34 | + |
| 35 | + kernelModules = mkDefault [ |
| 36 | + "nvme" |
| 37 | + "phy-qcom-qmp-pcie" |
| 38 | + "pcie-qcom" |
| 39 | + |
| 40 | + "i2c-core" |
| 41 | + "i2c-hid" |
| 42 | + "i2c-hid-of" |
| 43 | + "i2c-qcom-geni" |
| 44 | + |
| 45 | + "leds_qcom_lpg" |
| 46 | + "pwm_bl" |
| 47 | + "qrtr" |
| 48 | + "pmic_glink_altmode" |
| 49 | + "gpio_sbu_mux" |
| 50 | + "phy-qcom-qmp-combo" |
| 51 | + "gpucc_sc8280xp" |
| 52 | + "dispcc_sc8280xp" |
| 53 | + "phy_qcom_edp" |
| 54 | + "panel-edp" |
| 55 | + "msm" |
| 56 | + ]; |
| 57 | + }; |
| 58 | + |
| 59 | + hardware.enableRedistributableFirmware = mkDefault true; |
| 60 | + |
| 61 | + systemd.services.bluetooth-x13s-mac = lib.mkIf (cfg.bluetoothMac != null) { |
| 62 | + wantedBy = [ "multi-user.target" ]; |
| 63 | + before = [ "bluetooth.service" ]; |
| 64 | + requiredBy = [ "bluetooth.service" ]; |
| 65 | + |
| 66 | + serviceConfig = { |
| 67 | + Type = "oneshot"; |
| 68 | + RemainAfterExit = true; |
| 69 | + ExecStart = "${pkgs.util-linux}/bin/script -q -c '${pkgs.bluez}/bin/btmgmt --index 0 public-addr ${cfg.bluetoothMac}'"; |
| 70 | + }; |
| 71 | + }; |
| 72 | + |
| 73 | + # https://github.com/jhovold/linux/wiki/X13s#modem |
| 74 | + networking.networkmanager.fccUnlockScripts = [ |
| 75 | + |
| 76 | + { |
| 77 | + id = "105b:e0c3"; |
| 78 | + path = "${pkgs.modemmanager}/share/ModemManager/fcc-unlock.available.d/105b"; |
| 79 | + } |
| 80 | + ]; |
| 81 | + |
| 82 | + # https://github.com/jhovold/linux/wiki/X13s#camera |
| 83 | + services.udev.extraRules = lib.strings.concatLines ( |
| 84 | + [ |
| 85 | + '' |
| 86 | + ACTION=="add", SUBSYSTEM=="dma_heap", KERNEL=="linux,cma", GROUP="video", MODE="0660" |
| 87 | + ACTION=="add", SUBSYSTEM=="dma_heap", KERNEL=="system", GROUP="video", MODE="0660" |
| 88 | + '' |
| 89 | + ] |
| 90 | + ++ ( |
| 91 | + if cfg.wifiMac != null then |
| 92 | + [ |
| 93 | + '' |
| 94 | + ACTION=="add", SUBSYSTEM=="net", KERNELS=="0006:01:00.0", RUN+="${pkgs.iproute2}/bin/ip link set dev $name address ${cfg.wifiMac}" |
| 95 | + '' |
| 96 | + ] |
| 97 | + else |
| 98 | + [ ] |
| 99 | + ) |
| 100 | + ); |
| 101 | +} |
0 commit comments