From e2accca5d7e77898cb3f5bcceea4af04be6d6f92 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 9 Mar 2024 15:46:31 +0200 Subject: (blog/yfno) Started explaining modules --- src/blog/your-first-nixos-config/index.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/blog/your-first-nixos-config/index.md b/src/blog/your-first-nixos-config/index.md index 3b41fcf..4e2f750 100644 --- a/src/blog/your-first-nixos-config/index.md +++ b/src/blog/your-first-nixos-config/index.md @@ -398,5 +398,34 @@ These are the "bigger" building blocks with which you would build a configuratio ## NixOS configurations +Since the Nix language allows for many different ways to represent data, NixOS has settled on the idea of [modules](https://nixos.wiki/wiki/NixOS_modules): attribute sets (or functions) with a set of properties: + +```nix +{ + imports = [ ]; + options = { }; + config = { }; +} +``` + +`imports` is a list of paths to files, containing other modules, which will be included in your system. +`options` is an attrset, containing names of external ways to configure this module. +`config` is another attrset, containing the definitions of those external configuration names. +The last two aren't really important for now and they can all be left out. + +For our purposes, the functional layout is more relevat. +A module could also be a simple function, returning the aforementioned attrset, but also taking another attribute set, with at least four values: + +```nix +{ config, options, pkgs, modulesPath, ... }: +{ + imports = [ ]; + options = { }; + config = { }; +} +``` + +NixOS takes all of your modules and then combines them. + [^grub]: In reality, if literally everything is different between those configurations, you would probably need to reboot and chose from your bootloader, but that's not significant now. [^attrset-values]: You could also have each element on a separate line, with leading (or trailing) spaces/tabs. -- cgit v1.3.1-23-gd82d