diff options
Diffstat (limited to 'configs')
| -rw-r--r-- | configs/x11/default.nix | 7 | ||||
| -rw-r--r-- | configs/x11/xserver.nix | 189 |
2 files changed, 196 insertions, 0 deletions
diff --git a/configs/x11/default.nix b/configs/x11/default.nix new file mode 100644 index 00000000..8ee40c22 --- /dev/null +++ b/configs/x11/default.nix @@ -0,0 +1,7 @@ +{ + imports = [ + ./xserver.nix + ]; + + hrm.xsession.enable = true; +} diff --git a/configs/x11/xserver.nix b/configs/x11/xserver.nix new file mode 100644 index 00000000..816ffbc8 --- /dev/null +++ b/configs/x11/xserver.nix @@ -0,0 +1,189 @@ +# The X server, started by the user on a virtual terminal: xinit on ttyN +# starts display :N. hrm.xsession then runs the session. +{ config, lib, pkgs, ... }: let + cfg = config.hrm.xserver; + + # Writes xorg.conf sections from attribute sets: + # Section.<name>.<Identifier> = { <entry> = <value>; Option.<name> = <value>; } + to.xorg = rec { + conf = content: + lib.concatStringsSep "\n" + (lib.concatLists + (lib.mapAttrsToList + (sectionName: lib.mapAttrsToList (toSection sectionName)) + content.Section)); + toSection = sectionName: Identifier: sectionEntries: let + requiresIdentifier = lib.elem sectionName [ + "Device" + "InputClass" + "Monitor" + "Screen" + "ServerLayout" + ]; + in /* xorg */ '' + Section ${toValue sectionName} + ${lib.concatMapStringsSep "\n" + (line: " " + line) + (lib.mapAttrsToList + (name: value: "${name} ${toValue value}") + (lib.filterAttrs (_: value: value != null) ( + # Sections that require an identifier get the attribute name as + # one, unless sectionEntries has an explicit Identifier. + lib.optionalAttrs requiresIdentifier { + inherit Identifier; + } + // + builtins.removeAttrs sectionEntries [ "Option" ] + // + lib.optionalAttrs (sectionEntries?Option) + (lib.mapAttrs' + (name: value: lib.nameValuePair "Option ${toValue name}" ( + if builtins.isBool value + then (if value then "on" else "off") + else toString value + )) + sectionEntries.Option) + ))) + } + EndSection + ''; + toValue = value: { + bool = builtins.toJSON (if value then "on" else "off"); + float = builtins.toJSON value; + int = builtins.toJSON value; + list = lib.concatMapStringsSep " " toValue value; + string = builtins.toJSON value; + }.${builtins.typeOf value}; + }; + + configdir = pkgs.runCommand "xorg.conf.d" { + fontPkgs = config.fonts.packages ++ [ + pkgs.fontadobe100dpi + pkgs.fontadobe75dpi + ]; + modulePkgs = config.services.xserver.modules ++ [ + pkgs.xorgserver.out + (pkgs.write "xorg-config" + (lib.mapAttrs' + (name: content: + lib.nameValuePair "/share/X11/xorg.conf.d/${name}" { + text = to.xorg.conf content; + }) + cfg.configs)) + ]; + } /* sh */ '' + mkdir $out + + ( + exec > $out/00-nix-module-paths.conf + echo 'Section "Files"' + for pkg in $fontPkgs; do + if test "''${pkg:0:''${#NIX_STORE}}" = "$NIX_STORE"; then + find "$pkg" \ + -name fonts.dir \ + -printf ' FontPath "%h"\n' + fi + done + for pkg in $modulePkgs; do + path=$pkg/lib/xorg/modules + if test -d "$path"; then + printf ' ModulePath "%s"\n' "$path" + fi + done + echo 'EndSection' + ) + + for pkg in $modulePkgs; do + for conf in "$pkg"/share/X11/xorg.conf.d/*; do + ln -sf "$conf" $out + done + done + ''; +in { + options.hrm.xserver.configs = lib.mkOption { + default = {}; + type = lib.types.attrsOf (lib.types.attrsOf lib.types.anything); + description = '' + Files in the X server's xorg.conf.d, by name, as attribute sets: + Section.<name>.<Identifier> = { <entry> = <value>; Option.<name> = <value>; } + ''; + }; + config = { + # The X server's OpenGL drivers, in /run/opengl-driver. + hardware.graphics.enable = true; + + environment.systemPackages = [ + (pkgs.writeDashBin "xinit" '' + set -efu + + tty=$(${pkgs.coreutils}/bin/tty) + i=''${tty#/dev/tty} + + logfile=$XDG_RUNTIME_DIR/Xorg.$i.log + + exec ${pkgs.xorgserver}/bin/X \ + :$i \ + vt$i \ + -configdir ${configdir} \ + -xkbdir ${config.services.xserver.xkb.dir} \ + -nolisten tcp \ + -nolisten local \ + -verbose 0 \ + -logverbose 1 \ + -logfile "$logfile" \ + -maxclients 512 \ + >/dev/null 2>&1 + '') + ]; + + services.xserver.modules = [ + pkgs.xf86inputlibinput + ]; + services.udev.packages = [ + pkgs.libinput + ]; + + hrm.xserver.configs = lib.optionalAttrs + (lib.any (pkg: pkg.pname == "xf86-video-amdgpu") config.services.xserver.modules) + { + # Naming the driver keeps the X server from probing all of them. + "10-gpu.conf" = { + Section.Device.GPU.Driver = "amdgpu"; + }; + } + // { + "10-base.conf" = { + Section.ServerFlags.default.Option.DontZap = true; + }; + + "80-libinput-config.conf" = { + Section.InputClass.libinputConfiguration = { + MatchIsTouchpad = true; + Driver = "libinput"; + Option.AccelProfile = "adaptive"; + Option.AccelSpeed = 0.35; + Option.LeftHanded = true; + Option.MiddleEmulation = true; + Option.NaturalScrolling = true; + Option.ScrollButton = 1; + Option.HorizontalScrolling = true; + Option.SendEventsMode = "enabled"; + Option.Tapping = true; + # TappingDrag or TappingDragLock breaks secondary buffer selection + # in alacritty. + Option.DisableWhileTyping = false; + }; + }; + + "80-keyboard.conf" = { + Section.InputClass."keyboard catchall" = { + MatchIsKeyboard = true; + Option.XkbModel = config.services.xserver.xkb.model; + Option.XkbLayout = config.services.xserver.xkb.layout; + Option.XkbOptions = config.services.xserver.xkb.options; + Option.XkbVariant = config.services.xserver.xkb.variant; + }; + }; + }; + }; +} |
