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

115 lines
3.6 KiB
Nix

{
pkgs,
lib,
...
}: {
imports = [
#
# builtin screen
#
{
me.extraGroups = ["video"];
programs.light.enable = true;
}
#
# external screen
#
{
me.extraGroups = ["i2c"];
hardware.i2c.enable = false;
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 12);
/**
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);
mkExtSwitch = {dpi}: {
"10_xrdb-dpi" = "xrdb -merge ${pkgs.writeText "xrdb-dpi-config" ''
Xcursor.size: 64
Xft.dpi: ${toString dpi}
''}";
};
# 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 = genAttrs' allExternDevices (name: {
inherit name;
value = {enable = false;};
});
enableBuiltin = primary: {
eDP-1 =
{
enable = true;
crtc = 0;
mode = "2256x1504";
rate = "60.00";
}
// lib.optionalAttrs primary {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 true;
hooks.postswitch = mkExtSwitch {dpi = 150;};
};
mkAsusProfile = name: withBuiltin: {
fingerprint = {
${name} = asus-monitor;
eDP-1 = built-in;
};
config = with configs;
allOff
// enableDevice name
// lib.optionalAttrs withBuiltin (enableBuiltin false);
hooks.postswitch = mkExtSwitch {dpi = 120;};
};
in
genAttrs' allExternDevices (name: {
name = "asus-${name}-builtin";
value = mkAsusProfile name true;
})
// genAttrs' allExternDevices (name: {
name = "asus-${name}-no-builtin";
value = mkAsusProfile name false;
})
// {
laptop = frameworkBuiltin;
};
};
}