Asus Zenbook Duo (2024 / UX8406MA) & NixOS

I’ve made a service to set the screen brightnesses in the initrd. This is especially useful for encrypted setups, as the brightness defaults to the maximum until systemd restores it to the last setting, which can only happen after decryption.

Unfortunately, I can’t seem to find any way to disable the smooth brightness transition, or wait until it ends, meaning that there may be a bit of a flicker if the password prompt shows up early enough.

I’ve chosen 50 and 0 for the top and bottom displays respectively - feel free to change them as you like. Note that the maximum is defined by /sys/devices/pci0000:00/0000:00:02.0/drm/card1/card1-eDP-1/intel_backlight/max_brightness, which is 400 on my 2880x1800 model.

This implementation requires systemd and udev to be enabled in the initrd. A similar thing could probably be done for non-systemd configurations by using boot.initrd.postDeviceCommands.

See my previous post for additional early-boot display configuration as well.

{
  boot.initrd = {
    kernelModules = [ "i915" ]; # Early KMS
    systemd.services.initrd-brightness = {
      unitConfig.DefaultDependencies = false;
      wantedBy = [ "initrd.target" ];
      requires = [
        ''sys-devices-pci0000:00-0000:00:02.0-drm-card1-card1\x2deDP\x2d1-intel_backlight.device''
        ''sys-devices-pci0000:00-0000:00:02.0-drm-card1-card1\x2deDP\x2d2-card1\x2deDP\x2d2\x2dbacklight.device''
      ];
      before = [ "plymouth-start.service" ];
      after = [
        ''sys-devices-pci0000:00-0000:00:02.0-drm-card1-card1\x2deDP\x2d1-intel_backlight.device''
        ''sys-devices-pci0000:00-0000:00:02.0-drm-card1-card1\x2deDP\x2d2-card1\x2deDP\x2d2\x2dbacklight.device''
      ];
      script = ''
        echo 50 > '/sys/devices/pci0000:00/0000:00:02.0/drm/card1/card1-eDP-1/intel_backlight/brightness'
        echo  0 > '/sys/devices/pci0000:00/0000:00:02.0/drm/card1/card1-eDP-2/card1-eDP-2-backlight/brightness'
      '';
    };
  };
}