You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.2 KiB

  1. # This is a custom file for a surface.
  2. { config, lib, pkgs, modulesPath, ... }:
  3. {
  4. environment.systemPackages = with pkgs; [
  5. obs-studio
  6. rnote
  7. xournalpp
  8. ];
  9. # Set an usable key configuration: Ctrl at capslock, Win at Alt, Alt at Ctrl
  10. services.xserver.displayManager.sessionCommands =''
  11. ${pkgs.xorg.xmodmap}/bin/xmodmap "${pkgs.writeText "xkb-layout" ''
  12. !
  13. ! Swap Caps_Lock and Control_L
  14. !
  15. remove Lock = Caps_Lock
  16. remove Control = Control_L
  17. ! keysym Control_L = Caps_Lock
  18. keysym Control_L = Mode_switch
  19. keysym Caps_Lock = Control_L
  20. add Lock = Caps_Lock
  21. add Control = Control_L
  22. ! map arrows to more ergonomic position
  23. keycode 43 = h H Left
  24. keycode 44 = j J Down
  25. keycode 45 = k K Up
  26. keycode 46 = l L Right
  27. ''}"
  28. '';
  29. # add pulseaudio support to manage audio
  30. hardware.pulseaudio.enable = true;
  31. # next sleep & wake is code from: https://github.com/hpfr/system/blob/2e5b3b967b0436203d7add6adbd6b6f55e87cf3c/hosts/linux-surface.nix
  32. systemd.services = {
  33. surface-sleep = {
  34. enable = lib.versionOlder config.boot.kernelPackages.kernel.version "5.4";
  35. before = [ "suspend.target" ];
  36. wantedBy = [ "suspend.target" ];
  37. serviceConfig.Type = "oneshot";
  38. path = with pkgs; [ procps kmod bluez ];
  39. script = ''
  40. # Disable bluetooth if no device is connected
  41. if ps cax | grep bluetoothd && ! bluetoothctl info; then
  42. bluetoothctl power off
  43. fi
  44. ## Disable bluetooth regardless if devices are connected (see notes below)
  45. # if ps cax | grep bluetoothd; then
  46. # bluetoothctl power off
  47. # fi
  48. ## > Remove IPTS from ME side
  49. modprobe -r ipts_surface
  50. modprobe -r intel_ipts
  51. # modprobe -r mei_hdcp
  52. modprobe -r mei_me
  53. modprobe -r mei
  54. ## > Remove IPTS from i915 side
  55. for i in $(find /sys/kernel/debug/dri -name i915_ipts_cleanup); do
  56. echo 1 > $i
  57. done
  58. '';
  59. };
  60. surface-wake = {
  61. enable = lib.versionOlder config.boot.kernelPackages.kernel.version "5.4";
  62. after = [ "post-resume.target" ];
  63. wantedBy = [ "post-resume.target" ];
  64. serviceConfig.Type = "oneshot";
  65. path = with pkgs; [ procps kmod bluez ];
  66. script = ''
  67. ## > Load IPTS from i915 side
  68. for i in $(find /sys/kernel/debug/dri -name i915_ipts_init); do
  69. echo 1 > $i
  70. done
  71. ## > Load IPTS from ME side
  72. modprobe mei
  73. modprobe mei_me
  74. # modprobe mei_hdcp
  75. modprobe intel_ipts
  76. modprobe ipts_surface
  77. # Restart bluetooth
  78. if ps cax | grep bluetoothd; then
  79. bluetoothctl power on
  80. fi
  81. '';
  82. };
  83. };
  84. ## NOTES:
  85. # Susspend issue:
  86. # https://github.com/linux-surface/linux-surface/wiki/Known-Issues-and-FAQ#suspend-aka-sleep-vs-lid-closingopening-events
  87. # run:
  88. # > sudo modprobe -r surface_gpe
  89. # and:
  90. # > sudo bash -c 'echo -e "\n# Blacklisting lid vs. suspend issue module\nblacklist surface_gpe" >> /etc/modprobe.d/blacklist.conf'
  91. #
  92. # Now folding the keyboard to the screen will not suspend and brick the
  93. # session, but you will need to manually suspend the session if saving battery
  94. # is desired.
  95. }