.files/nix/configurations/vanadium/nixos/display.nix

118 lines
3.8 KiB
Nix

{
pkgs,
lib,
...
}: {
imports = [
#
# builtin screen
#
{
me.extraGroups = ["video"];
programs.light.enable = true;
}
#
# external screen
#
{
me.extraGroups = ["i2c"];
hardware.i2c.enable = true;
environment.systemPackages = [pkgs.ddcutil];
boot.kernelModules = ["i2c-dev"];
}
];
#
# Auto setup external screen
#
services.autorandr = {
enable = true;
hooks.postswitch = {
"20_xmonad" = "xmonad --restart"; # make sure feh keeps up
};
profiles = let
built-in = "00ffffffffffff0009e5ca0b000000002f200104a51c137803de50a3544c99260f505400000001010101010101010101010101010101115cd01881e02d50302036001dbe1000001aa749d01881e02d50302036001dbe1000001a000000fe00424f452043510a202020202020000000fe004e4531333546424d2d4e34310a0073";
asus-monitor = "00ffffffffffff0006b35b27010101012c210103803c22782a29d5ad4f44a7240f5054bfef00714f81809500d1c0d1e8d1fc01010101565e00a0a0a029503020350055502100001a000000fd0030901edf3c000a202020202020000000fc005647323741514c33410a202020000000ff0052414c4d51533139373533370a0111020347f14a90030204014061603f1f230907078301000067030c002000384468d85dc401788003026d1a000002013090f00069096909e305ff01e6060701696900e2006ae20fc0eae70070a0a067500820980455502100001a6fc200a0a0a055503020350055502100001a5aa000a0a0a046503020350055502100001a0000bc";
allExternDevices =
map (portNumber: "DP-${toString portNumber}") (lib.range 1 8);
allDevices = ["eDP-1"] ++ allExternDevices;
# TODO: merge when upstream is merged
# https://github.com/NixOS/nixpkgs/pull/436434
#
# Generate an attribute set by mapping a function over a list of attribute names.
# It allows setting the name of the attribute.
genAttrs' = xs: func: builtins.listToAttrs (map func xs);
switches = {
setDPI = {dpi}: {
"10_xrdb-dpi" = "xrdb -merge ${pkgs.writeText "xrdb-dpi-config" ''
Xcursor.size: 64
Xft.dpi: ${toString dpi}
''}";
};
# Is scoped to an output device, no need to be called on built-in display
setSoftwareBrightness = {
device,
brightness,
}: {
"10_xrandr_brightness" = ''
xrandr --output ${device} --brightness ${toString brightness}
'';
};
};
# Note: the "position" field corresponds to the "pos" field outputted by autorandr
# To get the current config, run `xrandr --auto` and then `autorandr --config`
configs = {
allOff = lib.genAttrs allDevices (_: {enable = false;});
enableBuiltin = {
eDP-1 = {
enable = true;
crtc = 0;
mode = "2256x1504";
rate = "60.00";
primary = true;
};
};
enableDevice = name: {
${name} = {
enable = true;
primary = true;
crtc = 1;
mode = "2560x1440";
position = "2256x0"; # on the right of built-in
rate = "59.95";
};
};
};
frameworkBuiltin = {
fingerprint.eDP-1 = built-in;
config = with configs; allOff // enableBuiltin;
hooks.postswitch = with switches; setDPI {dpi = 150;};
};
mkAsusProfile = name: {
fingerprint = {
${name} = asus-monitor;
eDP-1 = built-in;
};
config = with configs; allOff // enableDevice name;
hooks.postswitch = with switches;
setDPI {dpi = 110;}
// setSoftwareBrightness {
device = name;
brightness = 0.7; # just a random sensible choice
};
};
in
{default = frameworkBuiltin;}
// genAttrs' allExternDevices (name: lib.nameValuePair "asus-${name}" (mkAsusProfile name));
};
}