diff options
Diffstat (limited to 'modules/hardware')
-rw-r--r-- | modules/hardware/gamecontroller.nix | 109 | ||||
-rw-r--r-- | modules/hardware/t100ha/default.nix | 20 |
2 files changed, 129 insertions, 0 deletions
diff --git a/modules/hardware/gamecontroller.nix b/modules/hardware/gamecontroller.nix new file mode 100644 index 00000000..5cfe9d16 --- /dev/null +++ b/modules/hardware/gamecontroller.nix @@ -0,0 +1,109 @@ +{ config, lib, ... }: + +with lib; + +let + mappingType = (types.addCheck types.str (val: let + pattern = "[ab][0-9]+|h[0-9]+\.[0-9]+"; + in builtins.match pattern val == [])) // { + name = "aI (axis), bI (button) or hI.M (hat) where I=index, M=mask"; + }; + + mkAssignmentOption = example: name: description: mkOption { + type = types.nullOr mappingType; + default = null; + inherit example; + description = "Assignment for ${description}."; + }; + + mkAxisOption = mkAssignmentOption "a0"; + mkButtonOption = mkAssignmentOption "b0"; + + axes = { + leftx = "left stick X axis"; + lefty = "left stick Y axis"; + rightx = "right stick X axis"; + righty = "right stick Y axis"; + lefttrigger = "left trigger"; + righttrigger = "right trigger"; + }; + + buttons = { + a = "A button (down)"; + b = "B button (right)"; + x = "X button (left)"; + y = "Y button (up)"; + back = "XBox <literal>back</literal> button"; + guide = "XBox <literal>guide</literal> button"; + start = "<literal>start</literal> button"; + leftstick = "pressing the left stick"; + rightstick = "pressing the right stick"; + leftshoulder = "left shoulder/bumper button"; + rightshoulder = "right shoulder/bumper button"; + dpup = "directional pad up"; + dpdown = "directional pad down"; + dpleft = "directional pad left"; + dpright = "directional pad right"; + }; + + gcSubModule = { name, ... }: { + options = { + name = mkOption { + type = types.str; + default = name; + description = '' + The name of this controller, doesn't have special meaning and is only + there to make it easier to dinguish various mappings. + ''; + }; + + guid = mkOption { + type = types.uniq types.str; + default = name; + description = '' + The SDL2 GUID to uniquely identify this controller. + + Use <literal>vuizvui.list-gamecontrollers</literal> to list them. + ''; + }; + + mapping = mapAttrs mkAxisOption axes // mapAttrs mkButtonOption buttons; + }; + }; + + mkGCLine = const (cfg: let + validMappings = attrNames axes ++ attrNames buttons; + mkMappingVal = name: let + val = cfg.mapping.${name} or null; + in if val == null then null else "${name}:${val}"; + attrs = [ cfg.guid cfg.name "platform:Linux" ] + ++ remove null (map mkMappingVal validMappings); + in concatStringsSep "," attrs); + + controllers = mapAttrsToList mkGCLine config.vuizvui.hardware.gameController; + controllerConfig = concatStringsSep "\n" controllers; + +in { + options.vuizvui.hardware.gameController = mkOption { + type = types.attrsOf (types.submodule gcSubModule); + default = {}; + description = let + url = + "https://upload.wikimedia.org/wikipedia/commons/2/2c/360_controller.svg"; + in '' + A mapping of the game controllers to use with SDL2 games. + + The mapping is always based on the XBox reference controller, so even if + you don't use an XBox controller, you still have to map your keys + according to this layout: + + <link xlink:href="${ + "https://upload.wikimedia.org/wikipedia/commons/2/2c/360_controller.svg" + }"/> + ''; + }; + + config = mkIf (config.vuizvui.hardware.gameController != {}) { + environment.sessionVariables.SDL_GAMECONTROLLERCONFIG = controllerConfig; + }; +} diff --git a/modules/hardware/t100ha/default.nix b/modules/hardware/t100ha/default.nix new file mode 100644 index 00000000..d5f2138e --- /dev/null +++ b/modules/hardware/t100ha/default.nix @@ -0,0 +1,20 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.vuizvui.hardware.t100ha; + desc = "hardware support for the ASUS T100HA convertible"; + +in { + options.vuizvui.hardware.t100ha.enable = lib.mkEnableOption desc; + + config = lib.mkIf cfg.enable { + # Needed for booting from MMC: + boot.initrd.availableKernelModules = [ + "xhci_pci" "sdhci_acpi" "mmc_block" + ]; + # It's a CherryTrail SoC, so we want to have the latest and greatest: + boot.kernelPackages = pkgs.linuxPackages_latest; + # By default the console is rotated by 90 degrees to the right. + boot.kernelParams = [ "fbcon=rotate:3" ]; + }; +} |