nixos-x13s/module.nix

158 lines
4 KiB
Nix
Raw Normal View History

{ dtbName }:
2024-01-22 18:47:25 +01:00
{
config,
lib,
options,
2024-01-22 18:47:25 +01:00
pkgs,
...
}:
let
cfg = config.nixos-x13s;
x13sPackages = import ./packages/default.nix { inherit lib pkgs; };
2024-02-20 14:55:19 +01:00
linuxPackages_x13s =
if cfg.kernel == "mainline" then
2024-02-20 14:43:19 +01:00
pkgs.linuxPackages_latest
2024-02-20 14:55:19 +01:00
else
pkgs.linuxPackagesFor (
if cfg.kernel == "jhovold" then x13sPackages.linux_jhovold else throw "Unsupported kernel"
2024-02-20 14:55:19 +01:00
);
2024-01-22 18:47:25 +01:00
dtb = "${linuxPackages_x13s.kernel}/dtbs/qcom/${dtbName}";
2024-05-17 04:25:10 +02:00
dtbEfiPath = "dtbs/x13s.dtb";
modulesClosure = pkgs.makeModulesClosure {
rootModules = config.boot.initrd.availableKernelModules ++ config.boot.initrd.kernelModules;
kernel = config.system.modulesTree;
firmware = config.hardware.firmware;
allowMissing = false;
};
modulesWithExtra = pkgs.symlinkJoin {
name = "modules-closure";
paths = [
modulesClosure
x13sPackages.graphics-firmware
];
};
2024-01-22 18:47:25 +01:00
in
{
options.nixos-x13s = {
enable = lib.mkEnableOption "x13s hardware support";
bluetoothMac = lib.mkOption {
type = lib.types.str;
2024-05-14 21:33:45 +02:00
description = "Bluetooth MAC address to set on boot";
2024-01-22 18:47:25 +01:00
};
2024-02-20 14:43:19 +01:00
kernel = lib.mkOption {
type = lib.types.enum [
"jhovold"
"mainline"
];
2024-05-14 21:33:45 +02:00
description = "Which patched kernel to use. jhovold is the latest RC or release with some x13s specific patches, and mainline is nixos latest";
2024-02-20 14:43:19 +01:00
default = "jhovold";
};
2024-01-22 18:47:25 +01:00
};
config = lib.mkIf cfg.enable {
2024-07-30 04:33:01 +02:00
environment.systemPackages = [ pkgs.efibootmgr ];
2024-01-22 18:47:25 +01:00
hardware.enableAllFirmware = true;
hardware.firmware = lib.mkBefore [ x13sPackages.graphics-firmware ];
2024-01-22 18:47:25 +01:00
boot = {
initrd.systemd.enable = true;
initrd.systemd.contents = {
"/lib".source = lib.mkForce "${modulesWithExtra}/lib";
};
2024-01-22 18:47:25 +01:00
loader.efi.canTouchEfiVariables = true;
loader.systemd-boot.enable = lib.mkDefault true;
loader.systemd-boot.extraFiles = {
"${dtbEfiPath}" = dtb;
2024-01-22 18:47:25 +01:00
};
kernelPackages = linuxPackages_x13s;
kernelParams = [
2024-01-23 22:05:10 +01:00
# needed to boot
"dtb=${dtbEfiPath}"
2024-01-23 22:05:10 +01:00
2024-01-22 18:47:25 +01:00
# jhovold recommended
"efi=noruntime"
"clk_ignore_unused"
"pd_ignore_unused"
"arm64.nopauth"
# "regulator_ignore_unused" # allows for > 30 sec to load msm, at the potential cost of power
2024-01-22 18:47:25 +01:00
];
initrd = {
kernelModules = [
"nvme"
"phy-qcom-qmp-pcie"
"pcie-qcom"
"i2c-core"
"i2c-hid"
"i2c-hid-of"
"i2c-qcom-geni"
"leds_qcom_lpg"
"pwm_bl"
"qrtr"
"pmic_glink_altmode"
"gpio_sbu_mux"
"phy-qcom-qmp-combo"
"gpucc_sc8280xp"
"dispcc_sc8280xp"
"phy_qcom_edp"
"panel-edp"
"msm"
2024-01-22 18:47:25 +01:00
];
};
};
2024-05-30 17:52:04 +02:00
# https://github.com/jhovold/linux/wiki/X13s#modem
networking.networkmanager.fccUnlockScripts = [
{
id = "105b:e0c3";
path = "${pkgs.modemmanager}/share/ModemManager/fcc-unlock.available.d/105b";
}
];
nixpkgs.overlays = [
(_: super: {
# don't try and use zfs
zfs = super.zfs.overrideAttrs (_: {
meta.platforms = [ ];
});
# allow missing modules
makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; });
})
];
2024-01-22 18:47:25 +01:00
# default is performance
powerManagement.cpuFreqGovernor = "ondemand";
2024-05-30 17:52:04 +02:00
# https://github.com/jhovold/linux/wiki/X13s#camera
services.udev.extraRules = ''
2024-06-08 15:27:27 +02:00
ACTION=="add", SUBSYSTEM=="dma_heap", KERNEL=="linux,cma", GROUP="video", MODE="0660"
2024-05-30 17:52:04 +02:00
ACTION=="add", SUBSYSTEM=="dma_heap", KERNEL=="system", GROUP="video", MODE="0660"
'';
2024-05-14 21:33:45 +02:00
systemd.services.bluetooth-x13s-mac = {
wantedBy = [ "multi-user.target" ];
before = [ "bluetooth.service" ];
requiredBy = [ "bluetooth.service" ];
2024-01-22 18:47:25 +01:00
serviceConfig = {
2024-05-14 21:33:45 +02:00
Type = "oneshot";
RemainAfterExit = true;
2024-05-15 06:03:41 +02:00
ExecStart = "${pkgs.util-linux}/bin/script -q -c '${pkgs.bluez}/bin/btmgmt --index 0 public-addr ${cfg.bluetoothMac}'";
2024-01-22 18:47:25 +01:00
};
};
};
}