-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lesson/move function arguments (#17)
Moved the Function Arguments section from What is a Module to its own lesson. Trying to minimize the amount of theory before showing practical examples.
- Loading branch information
Showing
3 changed files
with
34 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Function Arguments | ||
|
||
When you define a module as a function like we did previously, there are certain arguments that are automatically provided. | ||
You ***do not*** have to explicitely put them in the function signature as we have the ellipsis `...` to manage any arguments we do not use. | ||
|
||
All modules are passed the following arguments: | ||
|
||
- `lib`: The nixpkgs library. | ||
- `config`: The results of all options after merging the values from all modules together. | ||
- `options`: The options declared in all modules. | ||
- `specialArgs`: An attribute set of extra arguments to be passed to the module functions. | ||
- All attributes of `specialArgs`. | ||
|
||
!!! note | ||
The fact that all the attributes of `specialArgs` are automatically provided means you don't need to add `specialArgs` to the module function signature if we want access to `specialArgs.thing`. | ||
We can just add `thing` to the function signature and use it directly. | ||
|
||
When designing a module for NixOS, there are some additional arguments that are automatically provided: | ||
|
||
- `pkgs`: The nixpkgs package set according to the `nixpkgs.pkgs` option. | ||
- `modulesPath`: The path to the NixOS modules directory in the nixpkgs repository. | ||
|
||
`modulesPath` is very handy as it allows you to import extra modules from the nixpkgs package tree without having to somehow make the module aware of the location of the `nixpkgs` or NixOS directories. | ||
It allows you to do things like this: | ||
|
||
``` nix | ||
{ modulesPath, ... }: { | ||
imports = [ | ||
(modulesPath + "/profiles/minimal.nix") | ||
]; | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2d3d520
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://nixos-modules.nix.xn--q9jyb4c as production
🚀 Deployed on https://65cc186cc5803d49ee44b58c--nixos-modules-lessons.netlify.app