Skip to content

Commit

Permalink
Merge pull request #2 from djacu/lesson/intro-to-types
Browse files Browse the repository at this point in the history
Added a lesson on basic nixos module option types.
  • Loading branch information
djacu authored Feb 8, 2024
2 parents 8c128b8 + f8db517 commit 45e9069
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lessons/010-basic-types/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{...}: {
config = {
exBool = true;
exInt = 42;
exEnum = "left";
exStr = "hello";
};
}
15 changes: 15 additions & 0 deletions lessons/010-basic-types/eval.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let
pkgs = import <nixpkgs> {};
inherit (pkgs) lib;
in
#lib.generators.toPretty
#{}
(
pkgs.lib.evalModules {
modules = [
./options.nix
./config.nix
];
}
)
.config
18 changes: 18 additions & 0 deletions lessons/010-basic-types/lesson.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Basic Types

In this lesson, we will cover some basic types.
There are certainly [many more types][nixos-manual-basic-types], but for this lesson, we will focus on just a few.

Notice in the [options][options] file, we have declared boolean, enumeration, integer, and string options.

[//]: # (./options.nix)

Notice in the [config][config] file, we have declared values for all these options.

[//]: # (./config.nix)

If you execute the run file (`./run`), you should see an output that matches what we have configured.

[nixos-manual-basic-types]: https://nixos.org/manual/nixos/stable/#sec-option-types
[options]: ./options.nix
[config]: ./config.nix
22 changes: 22 additions & 0 deletions lessons/010-basic-types/options.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{lib, ...}: let
inherit (lib) types;
in {
options = {
exBool = lib.mkOption {
type = types.bool;
description = "My example boolean.";
};
exEnum = lib.mkOption {
type = types.enum ["left" "right"];
description = "My example enumeration.";
};
exInt = lib.mkOption {
type = types.int;
description = "My example integer.";
};
exStr = lib.mkOption {
type = types.str;
description = "My example string.";
};
};
}
1 change: 1 addition & 0 deletions lessons/010-basic-types/run
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nix eval -f eval.nix --json | nix run nixpkgs#jq -- .

0 comments on commit 45e9069

Please sign in to comment.