2023-08-16 10:10:42 +00:00
{ pkgs , . . . }:
2023-08-26 19:49:51 +00:00
let
dmesg = " ${ pkgs . util-linux } / b i n / d m e s g " ;
grep = " ${ pkgs . gnugrep } / b i n / g r e p " ;
modprobe = " ${ pkgs . kmod } / b i n / m o d p r o b e " ;
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 1 ee0000 . hdmi' )
then
echo " r e p r o b i n g s u n 8 i _ d r m _ h d m i "
# if a command here fails it errors the whole service, so prefer to log instead
$ { modprobe } - r sun8i_drm_hdmi || echo " f a i l e d t o u n l o a d s u n 8 i _ d r m _ h d m i "
$ { modprobe } sun8i_drm_hdmi || echo " f a i l e d t o l o a d s u b 8 i _ d r m _ h d m i "
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 = " a a r c h 6 4 - m u l t i p l a t f o r m " ;
baseConfig = " d e f c o n f i g " ;
DTB = true ;
autoModules = true ;
preferBuiltin = true ;
# extraConfig = ...
# ^-- raspberry pi stuff: we don't need it.
# target = "Image"; # <-- default
target = " I m a g e . g z " ; # <-- compress the kernel image
# target = "zImage"; # <-- confuses other parts of nixos :-(
} ;
2023-08-26 19:49:51 +00:00
2023-10-21 08:11:23 +00:00
# disable proximity sensor.
# the filtering/calibration is bad that it causes the screen to go fully dark at times.
boot . blacklistedKernelModules = [ " s t k 3 3 1 0 " ] ;
2023-10-21 08:13:34 +00:00
boot . kernelParams = [
# without this some GUI apps fail: `DRM_IOCTL_MODE_CREATE_DUMB failed: Cannot allocate memory`
# this is because they can't allocate enough video ram.
2023-10-24 00:15:13 +00:00
# see related nixpkgs issue: <https://github.com/NixOS/nixpkgs/issues/260222>
2023-12-04 11:07:59 +00:00
# TODO(2023/12/03): remove once mesa 23.3.1 lands: <https://github.com/NixOS/nixpkgs/pull/265740>
2023-10-24 00:15:13 +00:00
#
2023-10-21 08:13:34 +00:00
# the default CMA seems to be 32M.
2023-10-24 00:15:13 +00:00
# i was running fine with 256MB from 2022/07-ish through 2022/12-ish, but then the phone quit reliably coming back from sleep (phosh): maybe a memory leak?
2023-10-21 08:13:34 +00:00
# `cat /proc/meminfo` to see CmaTotal/CmaFree if interested in tuning this.
" c m a = 5 1 2 M "
# 2023/10/20: potential fix for the lima (GPU) timeout bugs:
# - <https://gitlab.com/postmarketOS/pmaports/-/issues/805#note_890467824>
" l i m a . s c h e d _ t i m e o u t _ m s = 2 0 0 0 "
] ;
2023-10-21 08:11:23 +00:00
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
}