Option Types
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
programs.ssh.settings and dconf.settings.
hm.types.dagOf-
Options of this type have attribute sets as values where each member is a node in a 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 home.activation.
A number of functions are provided to create DAG nodes. The functions are shown below with examples using an option
foo.barof typehm.types.dagOf types.int.hm.dag.entryAnywhere (value: T) : DagEntry<T>-
Indicates that
valuecan be placed anywhere within the DAG. This is also the default for plain attribute set entries, that isfoo.bar = { a = hm.dag.entryAnywhere 0; }and
foo.bar = { a = 0; }are equivalent.
hm.dag.entryAfter (afters: list string) (value: T) : DagEntry<T>-
Indicates that
valuemust be placed after each of the attribute names in the given list. For examplefoo.bar = { a = 0; b = hm.dag.entryAfter [ "a" ] 1; }would place
bafterain the graph. hm.dag.entryBefore (befores: list string) (value: T) : DagEntry<T>-
Indicates that
valuemust be placed before each of the attribute names in the given list. For examplefoo.bar = { b = hm.dag.entryBefore [ "a" ] 1; a = 0; }would place
bbeforeain the graph. hm.dag.entryBetween (befores: list string) (afters: list string) (value: T) : DagEntry<T>-
Indicates that
valuemust be placed before the attribute names in the first list and after the attribute names in the second list. For examplefoo.bar = { a = 0; c = hm.dag.entryBetween [ "b" ] [ "a" ] 2; b = 1; }would place
cbeforeband afterain the graph.
There are also a set of functions that generate a DAG from a list. These are convenient when you just want to have a linear list of DAG entries, without having to manually enter the relationship between each entry. Each of these functions take a
tagas argument and the DAG entries will be named${tag}-${index}.hm.dag.entriesAnywhere (tag: string) (values: [T]) : Dag<T>-
Creates a DAG with the given values with each entry labeled using the given tag. For example
foo.bar = hm.dag.entriesAnywhere "a" [ 0 1 ];is equivalent to
foo.bar = { a-0 = 0; a-1 = hm.dag.entryAfter [ "a-0" ] 1; } hm.dag.entriesAfter (tag: string) (afters: list string) (values: [T]) : Dag<T>-
Creates a DAG with the given values with each entry labeled using the given tag. The list of values are placed are placed after each of the attribute names in
afters. For examplefoo.bar = { b = 0; } // hm.dag.entriesAfter "a" [ "b" ] [ 1 2 ];is equivalent to
foo.bar = { b = 0; a-0 = hm.dag.entryAfter [ "b" ] 1; a-1 = hm.dag.entryAfter [ "a-0" ] 2; } hm.dag.entriesBefore (tag: string) (befores: list string) (values: [T]) : Dag<T>-
Creates a DAG with the given values with each entry labeled using the given tag. The list of values are placed before each of the attribute names in
befores. For examplefoo.bar = { b = 0; } // hm.dag.entriesBefore "a" [ "b" ] [ 1 2 ];is equivalent to
foo.bar = { b = 0; a-0 = 1; a-1 = hm.dag.entryBetween [ "b" ] [ "a-0" ] 2; } hm.dag.entriesBetween (tag: string) (befores: list string) (afters: list string) (values: [T]) : Dag<T>-
Creates a DAG with the given values with each entry labeled using the given tag. The list of values are placed before each of the attribute names in
beforesand after each of the attribute names inafters. For examplefoo.bar = { b = 0; c = 3; } // hm.dag.entriesBetween "a" [ "b" ] [ "c" ] [ 1 2 ];is equivalent to
foo.bar = { b = 0; c = 3; a-0 = hm.dag.entryAfter [ "c" ] 1; a-1 = hm.dag.entryBetween [ "b" ] [ "a-0" ] 2; }
hm.types.gvariant-
This type is useful for options representing GVariant values. The type accepts all primitive GVariant types as well as arrays, tuples, “maybe” types, and dictionaries.
Some Nix values are automatically coerced to matching GVariant value but the GVariant model is richer so you may need to use one of the provided constructor functions. Examples assume an option
foo.barof typehm.types.gvariant.hm.gvariant.mkBoolean (v: bool)-
Takes a Nix value
vto a GVariantbooleanvalue (GVariant format stringb). Note, Nix booleans are automatically coerced using this function. That is,foo.bar = hm.gvariant.mkBoolean true;is equivalent to
foo.bar = true; hm.gvariant.mkString (v: string)-
Takes a Nix value
vto a GVariantstringvalue (GVariant format strings). Note, Nix strings are automatically coerced using this function. That is,foo.bar = hm.gvariant.mkString "a string";is equivalent to
foo.bar = "a string"; hm.gvariant.mkObjectpath (v: string)-
Takes a Nix value
vto a GVariantobjectpathvalue (GVariant format stringo). hm.gvariant.mkUchar (v: string)-
Takes a Nix value
vto a GVariantucharvalue (GVariant format stringy). hm.gvariant.mkInt16 (v: int)-
Takes a Nix value
vto a GVariantint16value (GVariant format stringn). hm.gvariant.mkUint16 (v: int)-
Takes a Nix value
vto a GVariantuint16value (GVariant format stringq). hm.gvariant.mkInt32 (v: int)-
Takes a Nix value
vto a GVariantint32value (GVariant format stringi). Note, Nix integers are automatically coerced using this function. That is,foo.bar = hm.gvariant.mkInt32 7;is equivalent to
foo.bar = 7; hm.gvariant.mkUint32 (v: int)-
Takes a Nix value
vto a GVariantuint32value (GVariant format stringu). hm.gvariant.mkInt64 (v: int)-
Takes a Nix value
vto a GVariantint64value (GVariant format stringx). hm.gvariant.mkUint64 (v: int)-
Takes a Nix value
vto a GVariantuint64value (GVariant format stringt). hm.gvariant.mkDouble (v: double)-
Takes a Nix value
vto a GVariantdoublevalue (GVariant format stringd). Note, Nix floats are automatically coerced using this function. That is,foo.bar = hm.gvariant.mkDouble 3.14;is equivalent to
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 (GVariant format string
a${type}). Thetypevalue can be constructed using-
hm.gvariant.type.string(GVariant format strings) -
hm.gvariant.type.boolean(GVariant format stringb) -
hm.gvariant.type.uchar(GVariant format stringy) -
hm.gvariant.type.int16(GVariant format stringn) -
hm.gvariant.type.uint16(GVariant format stringq) -
hm.gvariant.type.int32(GVariant format stringi) -
hm.gvariant.type.uint32(GVariant format stringu) -
hm.gvariant.type.int64(GVariant format stringx) -
hm.gvariant.type.uint64(GVariant format stringt) -
hm.gvariant.type.double(GVariant format stringd) -
hm.gvariant.type.variant(GVariant format stringv) -
hm.gvariant.type.arrayOf type(GVariant format stringa${type}) -
hm.gvariant.type.maybeOf type(GVariant format stringm${type}) -
hm.gvariant.type.tupleOf types(GVariant format string(${lib.concatStrings types})) -
hm.gvariant.type.dictionaryEntryOf [keyType valueType](GVariant format string{${keyType}${valueType}})
where
typeandtypesare 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 (GVariant format string
m${type}) whose (non-existent) element is of the given type. Thetypevalue is constructed as described for themkArrayfunction above. hm.gvariant.mkJust element-
Builds a GVariant maybe value (GVariant format string
m${element.type}) 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.
hm.gvariant.mkVariant element-
Builds a GVariant variant (GVariant format string
v) which contains the value of a GVariant element. hm.gvariant.mkDictionaryEntry [key value]-
Builds a GVariant dictionary entry containing the given list of elements (GVariant format string
{${key.type}${value.type}}), where each element is a GVariant value.