Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

filesystem

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
=> [ ]

importOverlays

Compose the overlays of a directory in the order of their names, found like getModules does. Each one holds an overlay final: prev: { ... } that sees the preceding ones in its prev, so numeric prefixes such as 10-inputs.nix and 90-hotfixes.nix control the precedence.

Inputs

dir
The directory containing the overlays.

Type

importOverlays :: Path -> Overlay

Examples

import nixpkgs {
  overlays = [ (importOverlays ./overlays) ];
}