-
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.
- Loading branch information
ibizaman
committed
Feb 9, 2024
1 parent
628ec75
commit 942a190
Showing
4 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
let | ||
pkgs = import <nixpkgs> {}; | ||
|
||
mymodule = { | ||
imports = [ | ||
]; | ||
options = { | ||
}; | ||
config = { | ||
}; | ||
}; | ||
in | ||
( | ||
pkgs.lib.evalModules { | ||
modules = [ | ||
mymodule | ||
]; | ||
} | ||
) | ||
.config |
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,39 @@ | ||
# A Module | ||
|
||
In this lesson, we will cover what a module is composed of. | ||
|
||
In the [eval][eval] file, we have declared an attrset called `mymodule` which is composed of 3 | ||
fields: `imports`, `options` and `config`. This is a module with default values for those fields. | ||
You can omit any of those fields and they will use those same default values. | ||
|
||
[//]: # (./eval.nix) | ||
|
||
If you execute the run file (`./run`), you will see printed the empty JSON object `{}`. | ||
|
||
[eval]: ./eval.nix | ||
|
||
## Module Fields | ||
|
||
The `options` field lets you define variables that can be used in the `config` section. | ||
|
||
The `config` field assigns values to options defined in other modules. We call this using an option. | ||
|
||
The `imports` field lets you import other modules from a module. | ||
|
||
We will see what goes in those fields in later lessons. | ||
|
||
## Evaluating Modules | ||
|
||
In the [eval][eval] file, we use a function called `evalModules`. This function takes an attrset as | ||
argument which can contain the field named `modules`. In there, we can put as many module as we | ||
want. | ||
|
||
`evalModules` will then merge all `imports`, `options` and `config` fields of all given modules | ||
following some rules we will see in the next lessons. It then produces an attrset whose only | ||
interesting field - the result of merging all modules - is found in the `config` field. This is the | ||
one we print when executing the `./run` file. | ||
|
||
## Nixpkgs | ||
|
||
The vast majority of nixpkgs is made out of modules, all merged together in the top-level | ||
`evalModules`. |
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 @@ | ||
nix eval -f eval.nix --json | nix run nixpkgs#jq -- . |
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