/nixos-configuration

Personal NixOS Configuration

Primary LanguageNixMIT LicenseMIT

NixOS Configuration

Setup

  • Create ./ident which contains your hostname, see ident.example. The hostname is used as an identifier in setup.sh load the rest of the configuration, ie ./hosts/your-hostname/default.nix.
  • Each user needs an entry in secrets.nix, a file which provides at a hashed password created with mkpasswd. See ./secrets.nix.example. Alternatively you can enable mutable users (users.mutableUsers = true; in ./users/default.nix) and set your password with passwd.
  • I have a seperate configuration for managing my user with home-manager.

Concept

The concept behind this configuration is a simple top-down approach. Each machine has a unique configuration folder structure based on hostname, for example ./hosts/nixos-workstation or ./hosts/nixos-laptop. Shared configuration is then imported from there. Here's a quick overview:

.
├── flake.lock                         // Shouldn't appear in git, ignored by default.
├── flake.nix                          // Simple flake, the future is now.
├── hosts                              // Machine configurations sorted by hostnames
│   ├── default.nix                    // Default configuration applied to all hosts
│   ├── nixos-laptop                   // Per-machine configuration for "nixos-laptop"
│   │   ├── default.nix                // Configuration for the machine named "nixos-laptop"
│   │   └── hardware-configuration.nix // Original autogenerated hardware configuration
│   └── nixos-workstation              // Per-machine configuration for "nixos-workstation"
│       ├── default.nix                // Configuration for the machine named "nixos-workstation"
│       └── hardware-configuration.nix // Original autogenerated hardware configuration
├── ident                              // Shouldn't appear in git, ignored by default.
├── ident.example                      // Example ident file, change to your hostname and rename.
├── modules                            // My modules
│   ├── default.nix                    // List of imports
│   ├── hardware                       // Modules relating to hardware
│   │   ├── bluetooth/default.nix      // Bluetooth hardware
│   │   ├── cpu                        // Modules for CPUs
│   │   │   ├── amd/default.nix        // AMD CPU, I don't own an Intel CPU yet.
│   │   │   └── default.nix            // Applies to all CPUs
│   │   ├── default.nix                // Imports for hardware types
│   │   └── gpu                        // Modules for certain GPUs
│   │       ├── amd/default.nix        // AMD GPU
│   │       ├── default.nix            // Applies to all GPUs
│   │       └── nvidia/default.nix     // Nvidia GPU (Desktop/Proprietary)
│   └── services                       // Modules relating to services
│       ├── default.nix                // Imports for service types
│       ├── flatpak/default.nix        // Flatpak module
│       └── pipewire/default.nix       // PipeWire module
├── pkgs                               // My packages
│   ├── default.nix                    // Configure nixpkgs with our overlay
│   ├── grub2                          // Grub themes
│   │   └── virtuaverse                // virtuaverse theme
│   │       └── default.nix            // Derivation
│   └── pkgs.nix                       // List of my packages to use
├── README.md                          // This file you're reading now
├── secrets.nix                        // Shouldn't appear in git, ignored by default.
├── secrets.nix.example                // Set your hashed passwords and rename.
├── setup.sh                           // Run ./setup.sh to apply your configuration.
└── users                              // User configuration
    ├── default.nix                    // Configuration that applies to every user.
    ├── guest/default.nix              // Per-user configuration for an optional guest user
    ├── jdf/default.nix                // Per-user configuration for "jdf"
    └── root/default.nix               // Per-user configuration for root

Opinionated Style Guide

Having a good style keeps your configurations readable and maintainable which is super important for NixOS.

  • Sort alphabetically to make locating everything a breeze.
  • Options and packages should be well commented, including descriptions.
  • The nixfmt package should be used as a guide to proper formating.
  • with should always be used when appropriate, for example: hardware.pulseaudio.package = with pkgs; pulseaudioFull;