-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodule.nix
194 lines (170 loc) · 5.16 KB
/
module.nix
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
{
config,
lib,
pkgs,
...
}:
let
dtbName = "sc8280xp-lenovo-thinkpad-x13s.dtb";
cfg = config.nixos-x13s;
linuxPackages =
if lib.isDerivation cfg.kernel then
pkgs.linuxPackagesFor cfg.kernel
else if lib.isString cfg.kernel then
if cfg.kernel == "mainline" then
pkgs.linuxPackages_latest
else if cfg.kernel == "jhovold" then
pkgs.linuxPackagesFor pkgs.x13s.linux_jhovold
else
throw "unsupported enum value for kernel. use a kernel package instead. eg: pkgs.linux_latest"
else
throw "unsupported type for kernel!";
dtb = "${linuxPackages.kernel}/dtbs/qcom/${dtbName}";
dtbEfiPath = "dtbs/x13s-${linuxPackages.kernel.version}.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
pkgs.x13s.firmware.graphics
];
};
in
{
options.nixos-x13s = {
enable = lib.mkEnableOption "x13s hardware support";
wifiMac = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "WiFi MAC address to set on boot";
default = null;
};
bluetoothMac = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "Bluetooth MAC address to set on boot";
default = null;
};
kernel = lib.mkOption {
type = lib.types.oneOf [
lib.types.package
(lib.types.enum [
"jhovold"
"mainline"
])
];
description = "'jhovold', 'mainline', or a linux package";
default = pkgs.x13s.linux_jhovold;
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ pkgs.efibootmgr ];
hardware.enableAllFirmware = true;
hardware.firmware = lib.mkBefore [ pkgs.x13s.firmware.graphics ];
boot = {
initrd.systemd.enable = true;
initrd.systemd.contents = {
"/lib".source = lib.mkForce "${modulesWithExtra}/lib";
};
loader.efi.canTouchEfiVariables = true;
loader.systemd-boot.enable = lib.mkDefault true;
loader.systemd-boot.extraFiles = {
"${dtbEfiPath}" = dtb;
};
kernelPackages = lib.mkForce linuxPackages;
kernelParams = [
# needed to boot
"dtb=${dtbEfiPath}"
# jhovold recommended
"efi=noruntime" # No longer needed if "Linux Boot" is enabled a recent version of the UEFI
"clk_ignore_unused"
"pd_ignore_unused"
"arm64.nopauth"
# "regulator_ignore_unused" # allows for > 30 sec to load msm, at the potential cost of power
];
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"
];
};
};
# 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; });
}
# add our custom x13s packages
// (lib.packagesFromDirectoryRecursive {
callPackage = pkgs.callPackage;
directory = ./packages;
})
)
)
];
# default is performance
powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand";
# https://github.com/jhovold/linux/wiki/X13s#camera
services.udev.extraRules = lib.strings.concatLines (
[
''
ACTION=="add", SUBSYSTEM=="dma_heap", KERNEL=="linux,cma", GROUP="video", MODE="0660"
ACTION=="add", SUBSYSTEM=="dma_heap", KERNEL=="system", GROUP="video", MODE="0660"
''
]
++ (
if cfg.wifiMac != null then
[
''
ACTION=="add", SUBSYSTEM=="net", KERNELS=="0006:01:00.0", RUN+="${pkgs.iproute2}/bin/ip link set dev $name address ${cfg.wifiMac}"
''
]
else
[ ]
)
);
systemd.services.bluetooth-x13s-mac = lib.mkIf (cfg.bluetoothMac != null) {
wantedBy = [ "multi-user.target" ];
before = [ "bluetooth.service" ];
requiredBy = [ "bluetooth.service" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.util-linux}/bin/script -q -c '${pkgs.bluez}/bin/btmgmt --index 0 public-addr ${cfg.bluetoothMac}'";
};
};
};
}