Repository navigation
Expand file tree
/
Copy pathmodule.nix
More file actions
206 lines (181 loc) · 6.95 KB
/
Copy pathmodule.nix
File metadata and controls
206 lines (181 loc) · 6.95 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
{ source }:
{
config,
lib,
pkgs,
...
}:
let
cfg = config.hardware.chuwi-minibook;
packages = import ./packages.nix {
inherit pkgs source;
linuxPackages = config.boot.kernelPackages;
};
generatedVbt =
if cfg.vbt.source == null || (cfg.vbt.refreshRate == null && cfg.vbt.rotation == null) then
null
else
import ./vbt-firmware.nix {
inherit pkgs;
inherit (cfg.vbt) refreshRate rotation;
sourceVbt = cfg.vbt.source;
vbtPatch = packages.vbtPatch;
};
vbtPackage = if cfg.vbt.package == null then generatedVbt else cfg.vbt.package;
mkEnabledOption =
description:
lib.mkOption {
type = lib.types.bool;
default = true;
inherit description;
};
boolToModuleParameter = value: if value then "1" else "0";
in
{
options.hardware.chuwi-minibook = {
enable = mkEnabledOption "Enable the CHUWI MiniBook X support stack.";
goodix = {
enable = mkEnabledOption "Enable the patched Goodix touchscreen driver and firmware.";
};
minibookEc.enable = mkEnabledOption "Enable the MiniBook embedded-controller driver.";
dptfEnabler = {
enable = mkEnabledOption "Enable the DPTF device-enabling driver.";
enableFans = lib.mkEnableOption "extra DPTF fan participants";
enableSensors = lib.mkEnableOption "extra DPTF sensor participants";
};
i2cDesignwareSpklen.enable = mkEnabledOption "Enable I2C DesignWare spike suppression.";
sensorProxy = {
enable = mkEnabledOption "Enable the MiniBook dual-accelerometer SensorProxy.";
setConvertibleChassis = mkEnabledOption "Identify the MiniBook X as a convertible through udev.";
};
thermald.enable = mkEnabledOption "Enable the MiniBook-patched thermald.";
kernelPanelOrientation = {
enable = lib.mkEnableOption "setting the built-in panel orientation through the kernel command line";
connector = lib.mkOption {
type = lib.types.str;
default = "DSI-1";
description = "DRM connector receiving the panel_orientation kernel parameter.";
};
orientation = lib.mkOption {
type = lib.types.enum [
"normal"
"upside_down"
"left_side_up"
"right_side_up"
];
default = "right_side_up";
description = "Panel orientation passed to the kernel.";
};
};
vbt = {
enable = lib.mkEnableOption "generation and loading of a configured VBT";
source = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
example = lib.literalExpression "./firmware/source-vbt.bin";
description = "Original VBT captured from this machine.";
};
refreshRate = lib.mkOption {
type = lib.types.nullOr lib.types.ints.positive;
default = null;
example = 90;
description = "Optional refresh rate passed to vbt_patch.";
};
rotation = lib.mkOption {
type = lib.types.nullOr (lib.types.ints.between 0 3);
default = null;
example = 1;
description = "Optional panel rotation passed to vbt_patch.";
};
package = lib.mkOption {
type = lib.types.nullOr lib.types.package;
default = null;
description = "Optional prebuilt firmware package used instead of generating a VBT.";
};
installPatcher = mkEnabledOption "Install the VBT inspection and patch utility.";
};
tools.enable = mkEnabledOption "Install the repository diagnostic tools.";
disablePanelSelfRefresh = mkEnabledOption "Disable i915 panel self refresh to reduce DSI corruption.";
mutter.enable = lib.mkEnableOption "the logical-normal built-in panel transform fix for Mutter";
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = !cfg.sensorProxy.enable || cfg.minibookEc.enable;
message = "The MiniBook sensor proxy requires hardware.chuwi-minibook.minibookEc.enable.";
}
{
assertion = !cfg.vbt.enable || vbtPackage != null;
message = ''
hardware.chuwi-minibook.vbt.enable requires either vbt.package, or
vbt.source plus at least one of vbt.refreshRate and vbt.rotation.
'';
}
];
nixpkgs.overlays = lib.optionals cfg.mutter.enable [
(_final: prev: {
mutter = prev.mutter.overrideAttrs (oldAttrs: {
patches = (oldAttrs.patches or [ ]) ++ [
(pkgs.fetchpatch {
url = "https://gitlab.gnome.org/GNOME/mutter/-/commit/ebcac7d67b35fb3cf8a9dd86a5efe35a741b90cb.patch";
hash = "sha256-NpEWqVNNIBHYY/UNzsLC35EK6ZlQgTxhDm4QYsyvd0k=";
})
];
});
})
];
boot.kernelParams =
lib.optionals cfg.disablePanelSelfRefresh [ "i915.enable_psr=0" ]
++ lib.optionals cfg.kernelPanelOrientation.enable [
"video=${cfg.kernelPanelOrientation.connector}:panel_orientation=${cfg.kernelPanelOrientation.orientation}"
]
++ lib.optionals cfg.vbt.enable [ "i915.vbt_firmware=vbt" ];
boot.initrd.extraFirmwarePaths = lib.optionals cfg.vbt.enable [ "vbt" ];
boot.extraModprobeConfig = lib.concatStringsSep "\n" (
lib.optionals cfg.sensorProxy.enable [
"options intel-hid enable_sw_tablet_mode=1"
]
++ lib.optionals cfg.dptfEnabler.enable [
"options dptf_enabler enable_fans=${boolToModuleParameter cfg.dptfEnabler.enableFans} enable_sensors=${boolToModuleParameter cfg.dptfEnabler.enableSensors}"
]
);
boot.extraModulePackages =
lib.optionals cfg.dptfEnabler.enable [ packages.dptfEnabler ]
++ lib.optionals cfg.minibookEc.enable [ packages.minibookEc ]
++ lib.optionals cfg.i2cDesignwareSpklen.enable [ packages.i2cDesignwareSpklen ]
++ lib.optionals cfg.goodix.enable [ packages.goodixTs ];
boot.kernelModules =
lib.optionals cfg.dptfEnabler.enable [ "dptf_enabler" ]
++ lib.optionals cfg.minibookEc.enable [ "minibook_ec" ]
++ lib.optionals cfg.i2cDesignwareSpklen.enable [ "i2c_designware_spklen" ]
++ lib.optionals cfg.goodix.enable [ "goodix_ts" ]
++ lib.optionals cfg.sensorProxy.enable [
"i2c-dev"
"uinput"
];
hardware.firmware =
lib.optionals cfg.goodix.enable [ packages.goodixFirmware ]
++ lib.optional (cfg.vbt.enable && vbtPackage != null) vbtPackage;
hardware.sensor.iio = lib.mkIf cfg.sensorProxy.enable {
enable = true;
package = packages.iioSensorProxy;
};
services.udev.extraHwdb = lib.mkIf cfg.sensorProxy.setConvertibleChassis (
lib.mkAfter ''
dmi:bvn*:bvr*:bd*:svnCHUWI*:pnMiniBookX*:*
CHASSIS_TYPE=31
''
);
services.thermald = lib.mkIf cfg.thermald.enable {
enable = true;
package = packages.thermald;
ignoreCpuidCheck = true;
};
environment.systemPackages =
lib.optionals cfg.tools.enable [
packages.captureVbt
packages.minibookTools
]
++ lib.optionals cfg.vbt.installPatcher [ packages.vbtPatch ];
};
}