about summary refs log tree commit diff
path: root/lib/tests/modules/types-attrTag.nix
blob: 08854ca73f56650dc6826838b27acc2eb6fc92ad (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
{ lib, config, ... }:
let
  inherit (lib) mkOption types;
  forceDeep = x: builtins.deepSeq x x;
in
{
  options = {
    intStrings = mkOption {
      type = types.attrsOf
        (types.attrTag {
          left = types.int;
          right = types.str;
        });
    };
    nested = mkOption {
      type = types.attrTag {
        left = types.int;
        right = types.attrTag {
          left = types.int;
          right = types.str;
        };
      };
    };
    merged = mkOption {
      type = types.attrsOf (
        types.attrTag {
          yay = types.int;
        }
      );
    };
    okChecks = mkOption {};
  };
  imports = [
    {
      options.merged = mkOption {
        type = types.attrsOf (
          types.attrTag {
            nay = types.bool;
          }
        );
      };
    }
  ];
  config = {
    intStrings.syntaxError = 1;
    intStrings.syntaxError2 = {};
    intStrings.syntaxError3 = { a = true; b = true; };
    intStrings.syntaxError4 = lib.mkMerge [ { a = true; } { b = true; } ];
    intStrings.mergeError = lib.mkMerge [ { int = throw "do not eval"; } { string = throw "do not eval"; } ];
    intStrings.badTagError.rite = throw "do not eval";
    intStrings.badTagTypeError.left = "bad";
    intStrings.numberOne.left = 1;
    intStrings.hello.right = "hello world";
    nested.right.left = "not a number";
    merged.negative.nay = false;
    merged.positive.yay = 100;
    okChecks =
      assert config.intStrings.hello.right == "hello world";
      assert config.intStrings.numberOne.left == 1;
      assert config.merged.negative.nay == false;
      assert config.merged.positive.yay == 100;
      true;
  };
}