Structure
This section uses the variables myconfigName
, isHomeManager
, and homeManagerUser
, so it's recommended to first review the corresponding subsection: delib.configurations Function Arguments.
Function Arguments
name
: string. It is recommended that it matches the parent path of the module'senable
option, such as"programs.example"
, since thecfg
argument depends on this path.options
: attrset or a lambda that returns an attrset (see Options).[myconfig|nixos|home].[ifEnabled|ifDisabled|always]
: attrset or a lambda that returns an attrset.myconfig.*
: sets values inconfig.${myconfigName}
.nixos.*
: sets values inconfig
ifisHomeManager
isfalse
; otherwise, it does nothing.home.*
: sets values inconfig
ifisHomeManager
istrue
; otherwise, inconfig.home-manager.users.${homeManagerUser}
.[myconfig|nixos|home].ifEnabled
: executed only if thecfg.enable
option (see Passed Arguments - cfg) exists and istrue
.[myconfig|nixos|home].ifDisabled
: executed only if thecfg.enable
option exists and isfalse
.[myconfig|nixos|home].always
: always executed, even if thecfg.enable
option doesn't exist.
Passed Arguments
A list of arguments passed to options
and [myconfig|nixos|home].[ifEnabled|ifDisabled|always]
, if their type is a lambda
:
name
: the same name from thedelib.module
arguments.myconfig
: equalsconfig.${myConfigName}
.cfg
: equals the result of the expressiondelib.getAttrByStrPath name config.${myConfigName} {}
, wherename
is the argument fromdelib.module
, and{}
is the value returned if the attribute is not found.
Pseudocode
nix
delib.module {
name = "";
# options.${myConfigName} = ...
options = {name, cfg, myconfig, ...}: {};
# config.${myConfigName} = ...
myconfig.ifEnabled = {name, cfg, myconfig, ...}: {};
myconfig.ifDisabled = {name, cfg, myconfig, ...}: {};
myconfig.always = {name, cfg, myconfig, ...}: {};
# if isHomeManager
# then {}
# else {config = ...;}
nixos.ifEnabled = {name, cfg, myconfig, ...}: {};
nixos.ifDisabled = {name, cfg, myconfig, ...}: {};
nixos.always = {name, cfg, myconfig, ...}: {};
# if isHomeManager
# then {config = ...;}
# else {config.home-manager.users.${homeManagerUser} = ...;}
home.ifEnabled = {name, cfg, myconfig, ...}: {};
home.ifDisabled = {name, cfg, myconfig, ...}: {};
home.always = {name, cfg, myconfig, ...}: {};
}