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