diff --git a/lessons/010-basic-types/config.nix b/lessons/010-basic-types/config.nix new file mode 100644 index 0000000..91233a9 --- /dev/null +++ b/lessons/010-basic-types/config.nix @@ -0,0 +1,8 @@ +{...}: { + config = { + exBool = true; + exInt = 42; + exEnum = "left"; + exStr = "hello"; + }; +} diff --git a/lessons/010-basic-types/eval.nix b/lessons/010-basic-types/eval.nix new file mode 100644 index 0000000..c625a86 --- /dev/null +++ b/lessons/010-basic-types/eval.nix @@ -0,0 +1,15 @@ +let + pkgs = import {}; + inherit (pkgs) lib; +in + #lib.generators.toPretty + #{} + ( + pkgs.lib.evalModules { + modules = [ + ./options.nix + ./config.nix + ]; + } + ) + .config diff --git a/lessons/010-basic-types/lesson.md b/lessons/010-basic-types/lesson.md new file mode 100644 index 0000000..1ba849d --- /dev/null +++ b/lessons/010-basic-types/lesson.md @@ -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 diff --git a/lessons/010-basic-types/options.nix b/lessons/010-basic-types/options.nix new file mode 100644 index 0000000..c09b944 --- /dev/null +++ b/lessons/010-basic-types/options.nix @@ -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."; + }; + }; +} diff --git a/lessons/010-basic-types/run b/lessons/010-basic-types/run new file mode 100755 index 0000000..586fc86 --- /dev/null +++ b/lessons/010-basic-types/run @@ -0,0 +1 @@ +nix eval -f eval.nix --json | nix run nixpkgs#jq -- .