git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #127157 from nh2/xserver-readable-config-indentation

xserver: Generate readable config indentation

commite85693afde878bb440fb11d4d9b145f7d93e29f1 authorNiklas Hambüchen <mail@nh2.me> dateWed 23 Jun 2021, 01:16 (5 years ago) parent98984d2685e8ff
3 files changed+52−48
nixos/modules/services/x11/hardware/libinput.nix+21−21 nixos/modules/services/x11/xserver.nix+26−23 nixos/modules/tasks/trackpoint.nix+5−4
nixos/modules/services/x11/hardware/libinput.nix+21−21
@@ -188,27 +188,27 @@ let cfg = config.services.xserver.libinput;
188188 };
189189
190190 mkX11ConfigForDevice = deviceType: matchIs: ''
191− Identifier "libinput ${deviceType} configuration"
192− MatchDriver "libinput"
193− MatchIs${matchIs} "${xorgBool true}"
194− ${optionalString (cfg.${deviceType}.dev != null) ''MatchDevicePath "${cfg.${deviceType}.dev}"''}
195− Option "AccelProfile" "${cfg.${deviceType}.accelProfile}"
196− ${optionalString (cfg.${deviceType}.accelSpeed != null) ''Option "AccelSpeed" "${cfg.${deviceType}.accelSpeed}"''}
197− ${optionalString (cfg.${deviceType}.buttonMapping != null) ''Option "ButtonMapping" "${cfg.${deviceType}.buttonMapping}"''}
198− ${optionalString (cfg.${deviceType}.calibrationMatrix != null) ''Option "CalibrationMatrix" "${cfg.${deviceType}.calibrationMatrix}"''}
199− ${optionalString (cfg.${deviceType}.clickMethod != null) ''Option "ClickMethod" "${cfg.${deviceType}.clickMethod}"''}
200− Option "LeftHanded" "${xorgBool cfg.${deviceType}.leftHanded}"
201− Option "MiddleEmulation" "${xorgBool cfg.${deviceType}.middleEmulation}"
202− Option "NaturalScrolling" "${xorgBool cfg.${deviceType}.naturalScrolling}"
203− ${optionalString (cfg.${deviceType}.scrollButton != null) ''Option "ScrollButton" "${toString cfg.${deviceType}.scrollButton}"''}
204− Option "ScrollMethod" "${cfg.${deviceType}.scrollMethod}"
205− Option "HorizontalScrolling" "${xorgBool cfg.${deviceType}.horizontalScrolling}"
206− Option "SendEventsMode" "${cfg.${deviceType}.sendEventsMode}"
207− Option "Tapping" "${xorgBool cfg.${deviceType}.tapping}"
208− Option "TappingDragLock" "${xorgBool cfg.${deviceType}.tappingDragLock}"
209− Option "DisableWhileTyping" "${xorgBool cfg.${deviceType}.disableWhileTyping}"
210− ${cfg.${deviceType}.additionalOptions}
211− '';
191+ Identifier "libinput ${deviceType} configuration"
192+ MatchDriver "libinput"
193+ MatchIs${matchIs} "${xorgBool true}"
194+ ${optionalString (cfg.${deviceType}.dev != null) ''MatchDevicePath "${cfg.${deviceType}.dev}"''}
195+ Option "AccelProfile" "${cfg.${deviceType}.accelProfile}"
196+ ${optionalString (cfg.${deviceType}.accelSpeed != null) ''Option "AccelSpeed" "${cfg.${deviceType}.accelSpeed}"''}
197+ ${optionalString (cfg.${deviceType}.buttonMapping != null) ''Option "ButtonMapping" "${cfg.${deviceType}.buttonMapping}"''}
198+ ${optionalString (cfg.${deviceType}.calibrationMatrix != null) ''Option "CalibrationMatrix" "${cfg.${deviceType}.calibrationMatrix}"''}
199+ ${optionalString (cfg.${deviceType}.clickMethod != null) ''Option "ClickMethod" "${cfg.${deviceType}.clickMethod}"''}
200+ Option "LeftHanded" "${xorgBool cfg.${deviceType}.leftHanded}"
201+ Option "MiddleEmulation" "${xorgBool cfg.${deviceType}.middleEmulation}"
202+ Option "NaturalScrolling" "${xorgBool cfg.${deviceType}.naturalScrolling}"
203+ ${optionalString (cfg.${deviceType}.scrollButton != null) ''Option "ScrollButton" "${toString cfg.${deviceType}.scrollButton}"''}
204+ Option "ScrollMethod" "${cfg.${deviceType}.scrollMethod}"
205+ Option "HorizontalScrolling" "${xorgBool cfg.${deviceType}.horizontalScrolling}"
206+ Option "SendEventsMode" "${cfg.${deviceType}.sendEventsMode}"
207+ Option "Tapping" "${xorgBool cfg.${deviceType}.tapping}"
208+ Option "TappingDragLock" "${xorgBool cfg.${deviceType}.tappingDragLock}"
209+ Option "DisableWhileTyping" "${xorgBool cfg.${deviceType}.disableWhileTyping}"
210+ ${cfg.${deviceType}.additionalOptions}
211+ '';
212212in {
213213
214214 imports =
nixos/modules/services/x11/xserver.nix+26−23
@@ -81,13 +81,7 @@ let
8181 monitors = forEach xrandrHeads (h: ''
8282 Option "monitor-${h.config.output}" "${h.name}"
8383 '');
84− # First option is indented through the space in the config but any
85− # subsequent options aren't so we need to apply indentation to
86− # them here
87− monitorsIndented = if length monitors > 1
88− then singleton (head monitors) ++ map (m: " " + m) (tail monitors)
89− else monitors;
90− in concatStrings monitorsIndented;
84+ in concatStrings monitors;
9185
9286 # Here we chain every monitor from the left to right, so we have:
9387 # m4 right of m3 right of m2 right of m1 .----.----.----.----.
@@ -138,10 +132,15 @@ let
138132
139133 echo '${cfg.filesSection}' >> $out
140134 echo 'EndSection' >> $out
135+ echo >> $out
141136
142137 echo "$config" >> $out
143138 ''; # */
144139
140+ prefixStringLines = prefix: str:
141+ concatMapStringsSep "\n" (line: prefix + line) (splitString "\n" str);
142+
143+ indent = prefixStringLines " ";
145144in
146145
147146{
@@ -736,29 +735,29 @@ in
736735 Section "ServerFlags"
737736 Option "AllowMouseOpenFail" "on"
738737 Option "DontZap" "${if cfg.enableCtrlAltBackspace then "off" else "on"}"
739− ${cfg.serverFlagsSection}
738+ ${indent cfg.serverFlagsSection}
740739 EndSection
741740
742741 Section "Module"
743− ${cfg.moduleSection}
742+ ${indent cfg.moduleSection}
744743 EndSection
745744
746745 Section "Monitor"
747746 Identifier "Monitor[0]"
748− ${cfg.monitorSection}
747+ ${indent cfg.monitorSection}
749748 EndSection
750749
751750 # Additional "InputClass" sections
752− ${flip concatMapStrings cfg.inputClassSections (inputClassSection: ''
753− Section "InputClass"
754− ${inputClassSection}
755− EndSection
751+ ${flip (concatMapStringsSep "\n") cfg.inputClassSections (inputClassSection: ''
752+ Section "InputClass"
753+ ${indent inputClassSection}
754+ EndSection
756755 '')}
757756
758757
759758 Section "ServerLayout"
760759 Identifier "Layout[all]"
761− ${cfg.serverLayoutSection}
760+ ${indent cfg.serverLayoutSection}
762761 # Reference the Screen sections for each driver. This will
763762 # cause the X server to try each in turn.
764763 ${flip concatMapStrings (filter (d: d.display) cfg.drivers) (d: ''
@@ -781,9 +780,9 @@ in
781780 Identifier "Device-${driver.name}[0]"
782781 Driver "${driver.driverName or driver.name}"
783782 ${if cfg.useGlamor then ''Option "AccelMethod" "glamor"'' else ""}
784− ${cfg.deviceSection}
785− ${driver.deviceSection or ""}
786− ${xrandrDeviceSection}
783+ ${indent cfg.deviceSection}
784+ ${indent (driver.deviceSection or "")}
785+ ${indent xrandrDeviceSection}
787786 EndSection
788787 ${optionalString driver.display ''
789788
@@ -794,18 +793,22 @@ in
794793 Monitor "Monitor[0]"
795794 ''}
796795
797− ${cfg.screenSection}
798− ${driver.screenSection or ""}
796+ ${indent cfg.screenSection}
797+ ${indent (driver.screenSection or "")}
799798
800799 ${optionalString (cfg.defaultDepth != 0) ''
801800 DefaultDepth ${toString cfg.defaultDepth}
802801 ''}
803802
804803 ${optionalString
805− (driver.name != "virtualbox" &&
804+ (
805+ driver.name != "virtualbox"
806+ &&
806807 (cfg.resolutions != [] ||
807808 cfg.extraDisplaySettings != "" ||
808− cfg.virtualScreen != null))
809+ cfg.virtualScreen != null
810+ )
811+ )
809812 (let
810813 f = depth:
811814 ''
@@ -813,7 +816,7 @@ in
813816 Depth ${toString depth}
814817 ${optionalString (cfg.resolutions != [])
815818 "Modes ${concatMapStrings (res: ''"${toString res.x}x${toString res.y}"'') cfg.resolutions}"}
816− ${cfg.extraDisplaySettings}
819+ ${indent cfg.extraDisplaySettings}
817820 ${optionalString (cfg.virtualScreen != null)
818821 "Virtual ${toString cfg.virtualScreen.x} ${toString cfg.virtualScreen.y}"}
819822 EndSubSection
nixos/modules/tasks/trackpoint.nix+5−4
@@ -87,9 +87,9 @@ with lib;
8787 })
8888
8989 (mkIf (cfg.emulateWheel) {
90− services.xserver.inputClassSections =
91− [''
92− Identifier "Trackpoint Wheel Emulation"
90+ services.xserver.inputClassSections = [
91+ ''
92+ Identifier "Trackpoint Wheel Emulation"
9393 MatchProduct "${if cfg.fakeButtons then "PS/2 Generic Mouse" else "ETPS/2 Elantech TrackPoint|Elantech PS/2 TrackPoint|TPPS/2 IBM TrackPoint|DualPoint Stick|Synaptics Inc. Composite TouchPad / TrackPoint|ThinkPad USB Keyboard with TrackPoint|USB Trackpoint pointing device|Composite TouchPad / TrackPoint|${cfg.device}"}"
9494 MatchDevicePath "/dev/input/event*"
9595 Option "EmulateWheel" "true"
@@ -97,7 +97,8 @@ with lib;
9797 Option "Emulate3Buttons" "false"
9898 Option "XAxisMapping" "6 7"
9999 Option "YAxisMapping" "4 5"
100− ''];
100+ ''
101+ ];
101102 })
102103
103104 (mkIf cfg.fakeButtons {