summaryrefslogtreecommitdiffstats
path: root/lib/tests/modules/add-check.nix
blob: 3bd993694994723bd6dee143780e540223d529de (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
(
  { lib, ... }:
  let
    inherit (lib) types mkOption;
    inherit (types) addCheck int attrsOf;

    # type with a v1 merge
    v1Type = addCheck int (v: v == 0);

    # type with a v2 merge
    v2Type = addCheck (attrsOf int) (v: v ? foo);
  in
  {
    options.v1CheckedPass = mkOption {
      type = v1Type;
      default = 0;
    };
    options.v1CheckedFail = mkOption {
      type = v1Type;
      default = 1;
    };
    options.v2checkedPass = mkOption {
      type = v2Type;
      default = {
        foo = 1;
      };
      # plug the value to make test script regex simple
      apply = v: v.foo == 1;
    };
    options.v2checkedFail = mkOption {
      type = v2Type;
      default = { };
      apply = v: lib.deepSeq v v;
    };
  }
)