2023-08-16 10:10:42 +00:00
|
|
|
{ pkgs, ... }:
|
2023-08-26 19:49:51 +00:00
|
|
|
let
|
|
|
|
dmesg = "${pkgs.util-linux}/bin/dmesg";
|
|
|
|
grep = "${pkgs.gnugrep}/bin/grep";
|
|
|
|
modprobe = "${pkgs.kmod}/bin/modprobe";
|
|
|
|
ensureHWReady = ''
|
|
|
|
# common boot failure:
|
|
|
|
# blank screen (no backlight even), with the following log:
|
|
|
|
# ```syslog
|
|
|
|
# sun8i-dw-hdmi 1ee0000.hdmi: Couldn't get the HDMI PHY
|
|
|
|
# ...
|
|
|
|
# sun4i-drm display-engine: Couldn't bind all pipelines components
|
|
|
|
# ...
|
|
|
|
# sun8i-dw-hdmi: probe of 1ee0000.hdmi failed with error -17
|
|
|
|
# ```
|
|
|
|
#
|
|
|
|
# in particular, that `probe ... failed` occurs *only* on failed boots
|
|
|
|
# (the other messages might sometimes occur even on successful runs?)
|
|
|
|
#
|
|
|
|
# reloading the sun8i hdmi driver usually gets the screen on, showing boot text.
|
|
|
|
# then restarting display-manager.service gets us to the login.
|
|
|
|
#
|
|
|
|
# NB: the above log is default level. though less specific, there's a `err` level message that also signals this:
|
|
|
|
# sun4i-drm display-engine: failed to bind 1ee0000.hdmi (ops sun8i_dw_hdmi_ops [sun8i_drm_hdmi]): -17
|
|
|
|
# NB: this is the most common, but not the only, failure mode for `display-manager`.
|
|
|
|
# another error seems characterized by these dmesg logs, in which reprobing sun8i_drm_hdmi does not fix:
|
|
|
|
# ```syslog
|
|
|
|
# sun6i-mipi-dsi 1ca0000.dsi: Couldn't get the MIPI D-PHY
|
|
|
|
# sun4i-drm display-engine: Couldn't bind all pipelines components
|
|
|
|
# sun6i-mipi-dsi 1ca0000.dsi: Couldn't register our component
|
|
|
|
# ```
|
|
|
|
|
|
|
|
if (${dmesg} --kernel --level err --color=never --notime | ${grep} -q 'sun4i-drm display-engine: failed to bind 1ee0000.hdmi')
|
|
|
|
then
|
|
|
|
echo "reprobing sun8i_drm_hdmi"
|
|
|
|
# if a command here fails it errors the whole service, so prefer to log instead
|
|
|
|
${modprobe} -r sun8i_drm_hdmi || echo "failed to unload sun8i_drm_hdmi"
|
|
|
|
${modprobe} sun8i_drm_hdmi || echo "failed to load sub8i_drm_hdmi"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in
|
2022-08-09 22:26:41 +00:00
|
|
|
{
|
2023-08-16 10:59:58 +00:00
|
|
|
boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux-megous;
|
|
|
|
# boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux-manjaro;
|
2023-08-16 09:08:35 +00:00
|
|
|
# boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_latest;
|
2022-08-10 01:01:48 +00:00
|
|
|
|
2023-08-16 10:10:42 +00:00
|
|
|
# alternatively, apply patches directly to stock nixos kernel:
|
2022-08-10 01:01:48 +00:00
|
|
|
# boot.kernelPatches = manjaroPatches ++ [
|
|
|
|
# (patchDefconfig kernelConfig)
|
|
|
|
# ];
|
2023-05-12 06:49:59 +00:00
|
|
|
|
2023-08-16 09:08:35 +00:00
|
|
|
# configure nixos to build a compressed kernel image, since it doesn't usually do that for aarch64 target.
|
|
|
|
# without this i run out of /boot space in < 10 generations
|
2023-05-12 06:49:59 +00:00
|
|
|
nixpkgs.hostPlatform.linux-kernel = {
|
|
|
|
# defaults:
|
|
|
|
name = "aarch64-multiplatform";
|
|
|
|
baseConfig = "defconfig";
|
|
|
|
DTB = true;
|
|
|
|
autoModules = true;
|
|
|
|
preferBuiltin = true;
|
|
|
|
# extraConfig = ...
|
|
|
|
# ^-- raspberry pi stuff: we don't need it.
|
|
|
|
|
|
|
|
# target = "Image"; # <-- default
|
|
|
|
target = "Image.gz"; # <-- compress the kernel image
|
|
|
|
# target = "zImage"; # <-- confuses other parts of nixos :-(
|
|
|
|
};
|
2023-08-26 19:49:51 +00:00
|
|
|
|
|
|
|
services.xserver.displayManager.job.preStart = ensureHWReady;
|
|
|
|
systemd.services.greetd.preStart = ensureHWReady;
|
2022-08-09 22:26:41 +00:00
|
|
|
}
|