summary refs log tree commit diff
path: root/lib/tests/modules/alias-with-priority.nix
blob: a35a06fc6974931ffee770d742afd2d1be2f8ee1 (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
# This is a test to show that mkAliasOptionModule sets the priority correctly
# for aliased options.
#
# This test shows that an alias with a low priority is able to be overridden
# with a non-aliased option.

{ config, lib, ... }:

with lib;

{
  options = {
    # A simple boolean option that can be enabled or disabled.
    enable = lib.mkOption {
      type = types.nullOr types.bool;
      default = null;
      example = true;
      description = ''
        Some descriptive text
      '';
    };

    # mkAliasOptionModule sets warnings, so this has to be defined.
    warnings = mkOption {
      internal = true;
      default = [];
      type = types.listOf types.str;
      example = [ "The `foo' service is deprecated and will go away soon!" ];
      description = ''
        This option allows modules to show warnings to users during
        the evaluation of the system configuration.
      '';
    };
  };

  imports = [
    # Create an alias for the "enable" option.
    (mkAliasOptionModule [ "enableAlias" ] [ "enable" ])

    # Disable the aliased option, but with a default (low) priority so it
    # should be able to be overridden by the next import.
    ( { config, lib, ... }:
      {
        enableAlias = lib.mkDefault false;
      }
    )

    # Enable the normal (non-aliased) option.
    ( { config, lib, ... }:
      {
        enable = true;
      }
    )
  ];
}