aboutsummaryrefslogtreecommitdiff
path: root/modules/device/default.nix
blob: 114c68c03bedece357e09f19e2938b898e44bfa0 (plain)
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
{ config, pkgs, lib, ... }:
with builtins // lib;
let
  devices = import ../../data/devices.nix;

  hardware = mkOption {
    type = types.strMatching ''^kobo[0-9]+$'';
  };
  deviceID = mkOption {
    type = types.strMatching ''^00000000-0000-0000-0000-000000000[0-9][0-9][0-9]$'';
  };

  deviceInfo = types.submodule {
    options = {
      inherit hardware deviceID;
    };
  };
in {
  options = {
    _allDevices = mkOption {
      default = devices;
      readOnly = true;
      internal = true;
      type = types.attrsOf deviceInfo;
    };

    device = {
      name = mkOption {
        type = types.enum (attrNames devices);
      };

      affiliate = mkOption {
        type = types.enum (import ../../data/affiliates.nix);
        default = "kobo";
      };

      forceAffiliate = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Write the given affiliate to /mnt/onboard/.kobo/affiliate.conf
        '';
      };

      hardware = hardware // {
        default = config._allDevices.${config.device.name}.hardware;
      };

      deviceID = deviceID // {
        default = config._allDevices.${config.device.name}.deviceID;
      };

      serialNumber = mkOption {
        type = types.str;
        default = "N0";
      };
    };
  };

  config = {
    onboard.file = {
      ".kobo/affiliate.conf" = mkIf config.device.forceAffiliate {
        text = generators.toINI {} {
          General.affiliate = config.device.affiliate;
        };
      };
    };
  };
}