This config structure for NixOS aims to be:
- self-explainatory
- minimal
- flake based
- multi-host compatible
- multi-user compatible
- easily universally extendable
It optionally includes home-manager.
Don't get discouraged by all the files in the root, they are optional development assisting tools.
What is important for the NixOS configuration, is only the src
directory.
Make this config structure your own
- (fork this repository)
git clone <repository-uri>
- create configuration for your host - (be sure to have set the hostname in configuration.nix)
mkdir src/host/$(hostname)
- copy over your host configuration.nix and hardware-configuration.nix
cp /etc/nixos/*configuration.nix src/host/$(hostname)
- create
src/host/$(hostname)/default.nix
, that acts as entrypoint
nano src/host/$(hostname)/default.nix
- paste the following boilerplate and customize to your needs
{ ... }:
{
imports = [
./hardware-configuration.nix
./configuration.nix
# import (or create) your locale - sets keyboard and timezone stuff
../../module/select/locale/de_DE.nix
# import (or create) hardware features
../../module/add/hardware/audio.nix
../../module/add/hardware/nvidia.nix
# (optional) import development module - enables everything to further develop this config
../../module/add/software/development.nix
];
}
- copy the
user/i
directory to a directory with your username - acts as entrypoint for user configurations
cp -r src/user/i src/user/$(whoami)
- in the files in it, replace all occurances of the user
i
with your username - in
src/flake.nix
add a new nixosConfigurations entry for your hostname and user combination (can be multiple)
...
nixosConfigurations.<HOSTNAME> = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = attrs;
modules = [
./host/<HOSTNAME>
./user/<USERNAME>
];
};
...
- Test, that everything is working
bin/switch
- Done! You now have a minimal multi-host, multi-user NixOS configuration
Update the system by running bin/update
and bin/switch
afterwards.
Simple. Run bin/collect-garbage
.
Info: This deletes older boot entries too.
If you enable the development module (optional) - your nix configuration will automatically be statically checked, formated, and you will get nix-lang language features.
If you'd like to enable development features in general, you'll need to add the module/add/software/development.nix
module to your hosts default.nix.
Then, the various tools to assist development with nix, will be loaded automatically when you enter the directory where you cloned this repository.
This repository is ever evolving, so if you have certain requests featurewise, don't hesitate to create issues. I try to keep it minimal, but i'm also using it for myself, in the future i'll create a second repository that acts as pure boilerplate and will be even more minimal than now.