aboutsummaryrefslogtreecommitdiff
path: root/home-manager/doc/writing-modules.adoc
blob: 0f3336ff2c069bd175f4d16f3bbea99f2d269499 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
[[ch-writing-modules]]
== Writing Home Manager Modules
:writing-nixos-modules: https://nixos.org/nixos/manual/index.html#sec-writing-modules

The module system in Home Manager is based entirely on the NixOS module system so we will here only highlight aspects that are specific for Home Manager. For information about the module system as such please refer to the {writing-nixos-modules}[Writing NixOS Modules] chapter of the NixOS manual.

[[sec-option-types]]
=== Option Types
:wikipedia-dag: https://en.wikipedia.org/w/index.php?title=Directed_acyclic_graph&oldid=939656095
:gvariant-description: https://developer.gnome.org/glib/stable/glib-GVariant.html#glib-GVariant.description

Overall the basic option types are the same in Home Manager as NixOS. A few Home Manager options, however, make use of custom types that are worth describing in more detail. These are the option types `dagOf` and `gvariant` that are used, for example, by <<opt-programs.ssh.matchBlocks>> and <<opt-dconf.settings>>.

`hm.types.dagOf`::
Options of this type have attribute sets as values where each member is a node in a {wikipedia-dag}[directed acyclic graph] (DAG). This allows the attribute set entries to express dependency relations among themselves. This can, for example, be used to control the order of match blocks in a OpenSSH client configuration or the order of activation script blocks in <<opt-home.activation>>.
+
A number of functions are provided to create DAG nodes. The functions are shown below with examples using an option `foo.bar`  of type `hm.types.dagOf types.int`.
+
`hm.dag.entryAnywhere (value: T)`:::
Indicates that `value` can be placed anywhere within the DAG. This is also the default for plain attribute set entries, that is
+
[source,nix]
----
foo.bar = {
  a = hm.dag.entryAnywhere 0;
}
----
+
and
+
[source,nix]
----
foo.bar = {
  a = 0;
}
----
+
are equivalent.
+
`hm.dag.entryAfter (afters: list string) (value: T)`:::
Indicates that `value` must be placed _after_ each of the attribute names in the given list. For example
+
[source,nix]
----
foo.bar = {
  a = 0;
  b = hm.dag.entryAfter [ "a" ] 1;
}
----
+
would place `b` after `a` in the graph.
+
`hm.dag.entryBefore (befores: list string) (value: T)`:::
Indicates that `value` must be placed _before_ each of the attribute names in the given list. For example
+
[source,nix]
----
foo.bar = {
  b = hm.dag.entryBefore [ "a" ] 1;
  a = 0;
}
----
+
would place `b` before `a` in the graph.
+
`hm.dag.entryBetween (befores: list string) (afters: list string) (value: T)`:::
Indicates that `value` must be placed _before_ the attribute names in the first list and _after_ the attribute names in the second list. For example
+
[source,nix]
----
foo.bar = {
  a = 0;
  c = hm.dag.entryBetween [ "b" ] [ "a" ] 2;
  b = 1;
}
----
+
would place `c` before `b` and after `a` in the graph.

`hm.types.gvariant`::
This type is useful for options representing {gvariant-description}[GVariant] values. The type accepts all primitive GVariant types as well as arrays and tuples. Dictionaries are not currently supported.
+
To create a GVariant value you can use a number of provided functions. Examples assume an option `foo.bar`  of type `hm.types.gvariant`.
+
`hm.gvariant.mkBoolean (v: bool)`:::
Takes a Nix value `v` to a GVariant `boolean` value. Note, Nix booleans are automatically coerced using this function. That is,
+
[source,nix]
----
foo.bar = hm.gvariant.mkBoolean true;
----
+
is equivalent to
+
[source,nix]
----
foo.bar = true;
----
`hm.gvariant.mkString (v: string)`:::
Takes a Nix value `v` to a GVariant `string` value. Note, Nix strings are automatically coerced using this function. That is,
+
[source,nix]
----
foo.bar = hm.gvariant.mkString "a string";
----
+
is equivalent to
+
[source,nix]
----
foo.bar = "a string";
----
`hm.gvariant.mkObjectpath (v: string)`:::
Takes a Nix value `v` to a GVariant `objectpath` value.
`hm.gvariant.mkUchar (v: string)`:::
Takes a Nix value `v` to a GVariant `uchar` value.
`hm.gvariant.mkInt16 (v: int)`:::
Takes a Nix value `v` to a GVariant `int16` value.
`hm.gvariant.mkUint16 (v: int)`:::
Takes a Nix value `v` to a GVariant `uint16` value.
`hm.gvariant.mkInt32 (v: int)`:::
Takes a Nix value `v` to a GVariant `int32` value. Note, Nix integers are automatically coerced using this function. That is,
+
[source,nix]
----
foo.bar = hm.gvariant.mkInt32 7;
----
+
is equivalent to
+
[source,nix]
----
foo.bar = 7;
----
`hm.gvariant.mkUint32 (v: int)`:::
Takes a Nix value `v` to a GVariant `uint32` value.
`hm.gvariant.mkInt64 (v: int)`:::
Takes a Nix value `v` to a GVariant `int64` value.
`hm.gvariant.mkUint64 (v: int)`:::
Takes a Nix value `v` to a GVariant `uint64` value.
`hm.gvariant.mkDouble (v: double)`:::
Takes a Nix value `v` to a GVariant `double` value. Note, Nix floats are automatically coerced using this function. That is,
+
[source,nix]
----
foo.bar = hm.gvariant.mkDouble 3.14;
----
+
is equivalent to
+
[source,nix]
----
foo.bar = 3.14;
----
+
`hm.gvariant.mkArray type elements`:::
Builds a GVariant array containing the given list of elements, where each element is a GVariant value of the given type. The `type` value can be constructed using
+
--
- `hm.gvariant.type.string`
- `hm.gvariant.type.boolean`
- `hm.gvariant.type.uchar`
- `hm.gvariant.type.int16`
- `hm.gvariant.type.uint16`
- `hm.gvariant.type.int32`
- `hm.gvariant.type.uint32`
- `hm.gvariant.type.int64`
- `hm.gvariant.type.uint64`
- `hm.gvariant.type.double`
- `hm.gvariant.type.arrayOf type`
- `hm.gvariant.type.maybeOf type`
- `hm.gvariant.type.tupleOf types`
--
+
where `type` and `types` are themselves a type and list of types, respectively.
+
`hm.gvariant.mkEmptyArray type`:::
An alias of `hm.gvariant.mkArray type []`.
+
`hm.gvariant.mkNothing type`:::
Builds a GVariant maybe value whose (non-existent) element is of the given type. The `type` value is constructed as described for the `mkArray` function above.
+
`hm.gvariant.mkJust element`:::
Builds a GVariant maybe value containing the given GVariant element.
+
`hm.gvariant.mkTuple elements`:::
Builds a GVariant tuple containing the given list of elements, where each element is a GVariant value.