getModules
Get all modules in a directory.
Can for instance be used to automatically import all modules in a directory.
Directories containing a default.nix
file are considered modules.
Paths starting with _
are ignored.
Inputs
dir
: The directory to search for modules in.
Type
getModules :: Path -> [ Path ]
Examples
getModules ./.
=> [
./module1
./module2
]
optionalPath
Get a path as a list if it exists. Returns an empty list if the path does not exist. Useful for adding optional paths to import statements.
Inputs
path
: The path to check for existence.
Type
optionalPath :: Path -> [ Path ]
Examples
optionalPath ./module.nix
=> [ ./module.nix ]
optionalPath ./non-existing-module.nix
=> [ ]
isEmpty
Check if a value of arbitrary type is empty.
Inputs
value
: The value to check for emptiness.
Type
isEmpty :: Any -> Bool
Examples
isEmpty ""
=> true
isEmpty null
=> true
isEmpty [ ]
=> true
isEmpty { }
=> true
isEmpty "foo"
=> false
isEmpty [ "foo" ]
=> false
isEmpty { foo = "bar"; }
=> false
isNotEmpty
Check if a value of arbitrary type is non-empty.
Opposite of isEmpty
.
Inputs
value
: The value to check for non-emptiness.
Type
isNotEmpty :: Any -> Bool
Examples
isNotEmpty ""
=> false
isEnabled
Checks if an attrset has a key with the name enable
set to true
.
Inputs
x
: The attrset to check.
Type
isEnabled :: { enable ? Bool } -> Bool
Examples
isEnabled { enable = true; }
=> true
isEnabled { enable = false; }
=> false
isEnabled { }
=> false
githubSshKeys
Returns a list of GitHub SSH keys for a user.
Inputs
user
: The GitHub username to get the SSH keys for.
sha256
: The sha256 hash of the file.
Type
githubSshKeys :: { user: String, sha256: String } -> [ String ]
Examples
githubSshKeys {
user = "mirkolenz";
sha256 = lib.fakeSha256;
}
=> [
"ssh-rsa AAAA..."
"ssh-rsa AAAA..."
]
getLeaves
Get all leaves of an attrset.
Inputs
attrs
: The attrset to get the leaves of.
Type
getLeaves :: AttrSet -> AttrSet
Examples
getLeaves {
foo = {
bar = "baz";
};
}
=> {
"foo.bar" = "baz";
}
attrByDottedPath
Return an attribute from nested attribute sets.
Inputs
path
: The path to the attribute.
default
: The default value to return if the attribute does not exist.
set
: The attribute set to get the attribute from.
Type
attrByPath :: String -> Any -> AttrSet -> Any
Examples
attrByPath "foo.bar" "default" { foo = { bar = "baz"; }; }
=> "baz"
getAttrFromDottedPath
Like attrByDottedPath
, but without a default value.
If it doesn’t find the path it will throw an error.
Inputs
path
: The path to the attribute.
set
: The attribute set to get the attribute from.
Type
getAttrFromDottedPath :: String -> AttrSet -> Any
Examples
getAttrFromDottedPath "foo.bar" { foo = { bar = "baz"; }; }
=> "baz"
setAttrByDottedPath
Create a new attribute set with value set at the nested attribute location specified in PATH.
Inputs
path
: The path to the attribute.
value
: The value to set.
Type
setAttrByDottedPath :: String -> Any -> AttrSet
Examples
setAttrByDottedPath "foo.bar" "baz"
=> { foo = { bar = "baz"; }; }