What generic modules provide
These modules define the basic building blocks that all other modules rely on. They work across every platform and module type.Package management
Unified package installation API across all platforms
Profile system
Machine profiles for different use cases
Module structure
The generic modules directory contains only three files, but they’re crucial to how the entire framework operates:Module details
packages.nix - Universal package installation
packages.nix - Universal package installation
The How it works:The module detects which type of configuration you’re using (Why use an attribute set?Unlike the traditional list-based approach (
garden.packages option provides a consistent way to install packages across NixOS, Darwin, and Home Manager.modules/generic/packages.nix
_class variable) and automatically translates garden.packages to the appropriate platform-specific option:- NixOS:
environment.systemPackages - Darwin:
environment.systemPackages - Home Manager:
home.packages
[ git vim curl ]), the attribute set approach provides:- Named packages for better debugging
- Easy override of specific packages
- Better error messages (“duplicate key ‘git’” instead of silent duplication)
- Ability to reference packages by name elsewhere
profiles.nix - Machine profiles
profiles.nix - Machine profiles
Machine profiles group related configuration based on how you use the machine.Available profiles:How modules use profiles:Other modules check these profiles to decide whether to enable features:Combining profiles:You can enable multiple profiles simultaneously. For example, a laptop can be both
modules/generic/profiles.nix
- graphical: Enables GUI applications, window managers, and desktop environment features
- headless: Optimizes for servers without displays, disables GUI components
- workstation: Development machine with full tooling, IDEs, and development dependencies
- laptop: Laptop-specific settings like power management, battery optimization, and touchpad configuration
- server: Server-optimized settings for hosting services and applications
graphical and workstation:default.nix - Module imports
default.nix - Module imports
The default.nix file simply imports the other generic modules:This allows other modules to import the entire generic module set with a single import:
modules/generic/default.nix
Usage examples
Package installation
Generic modules make package installation consistent across all platforms: Before (platform-specific):Profile-based configuration
Use profiles to enable features based on machine type:Design philosophy
Minimal and focused
Generic modules provide only the absolute essentials needed by all other modules. They establish patterns without implementing specifics.Platform-agnostic
Everything in generic modules must work on NixOS, Darwin, and Home Manager. Platform-specific code belongs in base or specialized modules.Foundation for extension
Other modules build on generic modules:- Base modules add Nix configuration and user management
- NixOS modules add system services and hardware support
- Darwin modules add macOS system preferences
- Home Manager modules add user application configuration
Implementation details
The _class variable
Generic modules use the_class variable to detect which type of configuration is running:
modules/nixos/default.nix
modules/darwin/default.nix
modules/home/default.nix
Attribute set vs list
Thegarden.packages option uses an attribute set instead of a list:
- Named packages for clarity
- Prevention of duplicate packages
- Easy overriding by other modules
Module inheritance chain
Generic modules are at the bottom of the inheritance chain:garden.packages and garden.profiles available everywhere.
Key features
Universal package management
Install packages the same way on every platform:Profile system
Describe your machine’s purpose, let the framework configure it:Automatic platform detection
Modules automatically adapt to the platform they’re running on. You don’t need to write platform-specific code.Next steps
Base modules
See how base modules build on generic modules
NixOS modules
Explore NixOS-specific modules