summaryrefslogtreecommitdiffstats
path: root/lib/tests/modules/mkDefinition.nix
blob: 0a807090fa28ec4dff3d2b11b386d88755be475f (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
70
71
{ lib, ... }:
let
  inherit (lib)
    mkOption
    mkDefinition
    mkOptionDefault
    ;
in
{
  imports = [
    {
      _file = "file";
      options.conflict = mkOption {
        default = 1;
      };
      config.conflict = mkDefinition {
        file = "other";
        value = mkOptionDefault 42;
      };
    }
    {
      # Check that mkDefinition works within 'config'
      options.viaConfig = mkOption { };
      config.viaConfig = mkDefinition {
        file = "other";
        value = true;
      };
    }
    {
      # Check mkMerge can wrap mkDefinitions
      # Not the other way around
      options.mkMerge = mkOption {
        type = lib.types.bool;
      };
      config.mkMerge = lib.mkMerge [
        (mkDefinition {
          file = "a.nix";
          value = true;
        })
        (mkDefinition {
          file = "b.nix";
          value = true;
        })
      ];
    }
    {
      # Check mkDefinition can use mkForce on the value
      # Not the other way around
      options.mkForce = mkOption {
        type = lib.types.bool;
        default = false;
      };
      config.mkForce = mkDefinition {
        file = "other";
        value = lib.mkForce true;
      };
    }
    {
      # Currently expects an error
      # mkDefinition doesn't work on option default
      # This is a limitation and might be resolved in the future
      options.viaOptionDefault = mkOption {
        type = lib.types.bool;
        default = mkDefinition {
          file = "other";
          value = true;
        };
      };
    }
  ];
}