about summary refs log tree commit diff stats
path: root/modules/by-name/ha/hardware/module.nix
blob: 850416b783bb2233a9e53f9ada52804dc56f57d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
  config,
  lib,
  pkgs,
  ...
}: let
  cfg = config.soispha.hardware;
in {
  options.soispha.hardware = {
    enable = lib.mkEnableOption "the various hardware dependend things (and graphics drivers)";
    moonlander = {
      enableLiveTraining = lib.mkEnableOption "udev rules for live training";
      enableFlashing = lib.mkEnableOption "udev rules for firmware flashing";
    };

    cpuType = lib.mkOption {
      type = lib.types.enum ["amd" "intel"];
      description = ''
        The manuafacturer of the used cpu.

        This is used to enable, for example, the correct microcode updates.
      '';
    };
  };

  config = lib.mkIf cfg.enable {
    hardware = {
      cpu.amd.updateMicrocode = cfg.cpuType == "amd";
      cpu.intel.updateMicrocode = cfg.cpuType == "intel";

      # This is enabled manually to support older firmware.
      keyboard.zsa.enable = false;

      nitrokey.enable = true;
      onlykey.enable = false;

      graphics = {
        enable = true;
        extraPackages = builtins.attrValues {
          inherit
            (pkgs)
            vaapiVdpau
            libvdpau-va-gl
            ;
        };
      };
    };

    # TODO: Remove the support for the old keyboards <2024-05-16>
    services.udev.extraRules =
      lib.strings.optionalString cfg.moonlander.enableLiveTraining ''
        # Rules for Oryx web flashing and live training
        KERNEL=="hidraw*", ATTRS{idVendor}=="16c0", MODE="0664", GROUP="plugdev"
        KERNEL=="hidraw*", ATTRS{idVendor}=="3297", MODE="0664", GROUP="plugdev"

        # Legacy rules for live training over webusb (Not needed for firmware v21+)
          # Rule for all ZSA keyboards
          SUBSYSTEM=="usb", ATTR{idVendor}=="3297", GROUP="plugdev"
          # Rule for the Moonlander
          SUBSYSTEM=="usb", ATTR{idVendor}=="3297", ATTR{idProduct}=="1969", GROUP="plugdev"
          # Rule for the Ergodox EZ
          SUBSYSTEM=="usb", ATTR{idVendor}=="feed", ATTR{idProduct}=="1307", GROUP="plugdev"
          # Rule for the Planck EZ
          SUBSYSTEM=="usb", ATTR{idVendor}=="feed", ATTR{idProduct}=="6060", GROUP="plugdev"
      ''
      + lib.strings.optionalString cfg.moonlander.enableFlashing
      ''
        # Wally Flashing rules for the Ergodox EZ
        ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789B]?", ENV{ID_MM_DEVICE_IGNORE}="1"
        ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789A]?", ENV{MTP_NO_PROBE}="1"
        SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789ABCD]?", MODE:="0666"
        KERNEL=="ttyACM*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789B]?", MODE:="0666"

        # Wally Flashing rules for the Moonlander and Planck EZ
        SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", \
            MODE:="0666", \
            SYMLINK+="stm32_dfu"
      '';
  };
}