diff --git a/nix/configurations/vanadium/nixos/display.nix b/nix/configurations/vanadium/nixos/display.nix index 52202b71..e1967567 100644 --- a/nix/configurations/vanadium/nixos/display.nix +++ b/nix/configurations/vanadium/nixos/display.nix @@ -1,4 +1,8 @@ -{pkgs, ...}: { +{ + pkgs, + lib, + ... +}: { imports = [ # # builtin screen @@ -15,6 +19,7 @@ me.extraGroups = ["i2c"]; hardware.i2c.enable = false; environment.systemPackages = [pkgs.ddcutil]; + boot.kernelModules = ["i2c-dev"]; } ]; @@ -22,100 +27,89 @@ # Auto setup external screen # services.autorandr = { - enable = false; + enable = true; hooks.postswitch = { "20_xmonad" = "xmonad --restart"; # make sure feh keeps up }; profiles = let - lg-monitor = "00ffffffffffff001e6d0677dd6a0100041f0103803c2278ea3e31ae5047ac270c50542108007140818081c0a9c0d1c0810001010101b8ce0050f0705a8018108a0058542100001e04740030f2705a80b0588a0058542100001a000000fd00383d1e873c000a202020202020000000fc004c472048445220344b0a20202001bf02033b714d9022201f1203040161605d5e5f230907076d030c001000983c20006001020367d85dc401788001e30f0003e305c000e6060501605550023a801871382d40582c450058542100001e565e00a0a0a029503020350058542100001a000000ff003130344e544b4632513839330a0000000000000000000000000000ff"; built-in = "00ffffffffffff0009e5ca0b000000002f200104a51c137803de50a3544c99260f505400000001010101010101010101010101010101115cd01881e02d50302036001dbe1000001aa749d01881e02d50302036001dbe1000001a000000fe00424f452043510a202020202020000000fe004e4531333546424d2d4e34310a0073"; + asus-monitor = "00ffffffffffff0006b35b27010101012c210103803c22782a29d5ad4f44a7240f5054bfef00714f81809500d1c0d1e8d1fc01010101565e00a0a0a029503020350055502100001a000000fd0030901edf3c000a202020202020000000fc005647323741514c33410a202020000000ff0052414c4d51533139373533370a0111020347f14a90030204014061603f1f230907078301000067030c002000384468d85dc401788003026d1a000002013090f00069096909e305ff01e6060701696900e2006ae20fc0eae70070a0a067500820980455502100001a6fc200a0a0a055503020350055502100001a5aa000a0a0a046503020350055502100001a0000bc"; - allOff = { - eDP-1.enable = false; - DP-1.enable = false; - DP-2.enable = false; - DP-3.enable = false; - DP-4.enable = false; - DP-5.enable = false; - DP-6.enable = false; - DP-7.enable = false; - DP-8.enable = false; - DP-9.enable = false; - DP-10.enable = false; - DP-11.enable = false; - DP-12.enable = false; - }; + allExternDevices = + map (portNumber: "DP-${toString portNumber}") (lib.range 1 12); - home-switch = { - "10_xrdb-dpi" = "xrdb -merge ${pkgs.writeText "xrdb-dpi-config" '' - Xcursor.size: 84 - Xft.dpi: 150 - ''}"; + /** + 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); - "30_xkbcapswap" = '' - setxkbmap -option - ''; - }; - - laptop-switch = { + mkExtSwitch = {dpi}: { "10_xrdb-dpi" = "xrdb -merge ${pkgs.writeText "xrdb-dpi-config" '' Xcursor.size: 64 - Xft.dpi: 150 + Xft.dpi: ${toString dpi} ''}"; - - "30_xkbcapswap" = '' - setxkbmap -option caps:swapescape - ''; }; - mkHomeProfile = dev: { - fingerprint = { - ${dev} = lg-monitor; - eDP-1 = built-in; - }; - config = - allOff - // { - ${dev} = { - enable = true; - crtc = 1; - mode = "3840x2160"; - rate = "60.00"; - primary = true; - }; - }; - hooks.postswitch = home-switch; - }; - in { - home-DP-1 = mkHomeProfile "DP-1"; - home-DP-2 = mkHomeProfile "DP-2"; - home-DP-3 = mkHomeProfile "DP-3"; - home-DP-4 = mkHomeProfile "DP-4"; - home-DP-5 = mkHomeProfile "DP-5"; - home-DP-6 = mkHomeProfile "DP-6"; - home-DP-7 = mkHomeProfile "DP-7"; - home-DP-8 = mkHomeProfile "DP-8"; - home-DP-9 = mkHomeProfile "DP-9"; - home-DP-10 = mkHomeProfile "DP-10"; - home-DP-11 = mkHomeProfile "DP-11"; - home-DP-12 = mkHomeProfile "DP-12"; - - laptop = { - fingerprint.eDP-1 = built-in; - config = - allOff - // { - eDP-1 = { + # 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"; - primary = true; 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"; }; - hooks.postswitch = laptop-switch; + }; + }; + + 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; }; - }; }; }