- Nix 100%
| homes | ||
| systems | ||
| .gitignore | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
Basic NixOS flake starter
Reccommended reading: The NixOS & Flakes Book
How to build the config
nixos-rebuild boot --flake .#<hostname>
Important Note
If the nix file has the form {}: {}, make sure to add ... to the first {}
This is bad:
{config, pkgs}: {}
This is good:
{config, pkgs, ...}: {}
The reason is that if you don't add ... to the function parameters, nix will get very angry about extra arguments being passed.
The ... parameter tells nix to ignore any extra options.
This essentially just shows a way of setting up a simple NixOS and home-manager config that uses multiple files.
All system configurations are in the systems/<hostname> directories.
systems/common is a directory with files that define options that are the same (or similar) across all systems.
All home configurations (using home-manager) are in the homes/<username> directories.
homes/common is a directory with files that define options that are the same (or similar) across all users' homes.
How to add a new system
- Create a
systems/<hostname>directory similar tosystems/laptop - Add the following code to
flake.nix:
nixosConfigurations.<hostname> = nixpkgs.lib.nixosSystem {
modules = [
# Since ./systems/laptop/default.nix exists, we just use the directory
./systems/<hostname>
# Optionally, you can use home manager to manage specific users
home-manager.nixosModules.home-manager # Add home-manager to nixos
{
# Set some home-manager options
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.you = ./homes/you;
}
];
};
How to add a new home
- Create a
homes/<username>directory similar tohomes/you - For every system that you want the user on, add
home-manager.users.<username> = ./homes/<username>Example:
nixosConfigurations.laptop = nixpkgs.lib.nixosSystem {
modules = [
# Since ./systems/laptop/default.nix exists, we just use the directory
./systems/laptop
# Optionally, you can use home manager to manage specific users
home-manager.nixosModules.home-manager # Add home-manager to nixos
{
# Set some home-manager options
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.you = ./homes/you;
home-manager.users.beaver = ./homes/beaver;
}
];
};