NixOS config starters
Find a file
2025-08-03 12:32:59 -05:00
homes Add/cleanup stuff I forgot 2025-08-03 12:32:59 -05:00
systems Add/cleanup stuff I forgot 2025-08-03 12:32:59 -05:00
.gitignore Initial commit 2025-08-03 12:21:13 -05:00
flake.lock Initial commit 2025-08-03 12:21:13 -05:00
flake.nix Initial commit 2025-08-03 12:21:13 -05:00
README.md Add/cleanup stuff I forgot 2025-08-03 12:32:59 -05:00

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

  1. Create a systems/<hostname> directory similar to systems/laptop
  2. 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

  1. Create a homes/<username> directory similar to homes/you
  2. 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;
    }
  ];
};