summaryrefslogtreecommitdiff
path: root/manifests/config.pp
blob: 3657a66d48e0f2374869db99c26e6497d5ade165 (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
# @summary Configures specific Xorg section
# https://www.x.org/releases/current/doc/man/man5/xorg.conf.5.xhtml
#
# @param section
#   Which section, such as Montior, ...
# @param identifier
#   Item used for the Identifier key in the section bolck
# @param no_identifier
#   Set to true if the output shouldn't contain an identifier entry.
# @param filename
#   What the output file should be called.
#   TODO validate that this is a local part of a filename. Mostly that
#   / is forbidden.
# @param options
#   Option directives to xorg. A list of tuples instead of a hash
#   until I figure out if the same option can be given multiple times.
# @param entries
#   Xorg entries.
# @param priority
#   Priority of this file compared to all other configuration files.
define xorg::config (
  String $section,
  String $identifier = $name,
  Boolean $no_identifier = false,
  String $filename = xorg::normalize_filename($name),
  Array[Tuple[String, Xorg::Value]] $options = [],
  Hash[String, Xorg::Value] $entries = {},
  Variant[String[2, 2], Integer[0, 99]] $priority = '20',
) {
  include xorg

  # Convert priority to 0-padded string of length 2
  $priority_ = $priority ? {
    String  => $priority,
    Integer => if $priority < 10 {
      "0${priority}"
    } else {
      $priority
    }
  }

  # TODO possibly allow multiple entries to share files.
  # For example, all monitor settings could go in a single file
  file { "${xorg::conf_dir}/${priority_}-${filename}.conf":
    ensure  => file,
    content => epp("${module_name}/xorg.conf.epp", {
        'identifier' => if $no_identifier { undef } else { $identifier },
        'options'    => $options,
        'entries'    => $entries,
    }),
  }
}