This repository contains NixOS and nix-darwin configurations for my machines, managed through Nix Flakes.
It is structured to easily accommodate multiple machines and user configurations, leveraging nixpkgs, home-manager, nix-darwin, and various other community contributions for a seamless experience across NixOS and macOS.
flake.nix
: The flake itself, defining inputs and outputs for NixOS, nix-darwin, and Home Manager configurations.hosts/
: NixOS and nix-darwin configurations for each machinehome/
: Home Manager configurations for each machinefiles/
: Miscellaneous configuration files and scripts used across various applications and servicesmodules/
: Reusable platform-specific modulesnixos/
: NixOS-specific modulesdarwin/
: macOS-specific moduleshome-manager/
: User-space configuration modules
flake.lock
: Lock file ensuring reproducible builds by pinning input versionsoverlays/
: Custom Nix overlays for package modifications or additions
- nixpkgs: Points to the
nixos-unstable
channel for access to the latest packages - nixpkgs-stable: Points to the
nixos-24.11
channel, providing stable NixOS packages - home-manager: Manages user-specific configurations, following the
nixpkgs
input (release-24.11) - hardware: Optimizes settings for different hardware configurations
- catppuccin: Provides global Catppuccin theme integration
- spicetify-nix: Enhances Spotify client customization
- darwin: Enables nix-darwin for macOS system configuration
- nix-homebrew: Integrates Homebrew package management with nix-darwin
To add a new machine with a new user to your NixOS or nix-darwin configuration, follow these steps:
-
Update
flake.nix
:a. Add the new user to the
users
attribute set:users = { # Existing users... newuser = { avatar = ./files/avatar/face; email = "[email protected]"; fullName = "New User"; gitKey = "YOUR_GIT_KEY"; name = "newuser"; }; };
b. Add the new machine to the appropriate configuration set:
For NixOS:
nixosConfigurations = { # Existing configurations... newmachine = mkNixosConfiguration "newmachine" "newuser"; };
For nix-darwin:
darwinConfigurations = { # Existing configurations... newmachine = mkDarwinConfiguration "newmachine" "newuser"; };
c. Add the new home configuration:
homeConfigurations = { # Existing configurations... "newuser@newmachine" = mkHomeConfiguration "x86_64-linux" "newuser" "newmachine"; };
-
Create System Configuration:
a. Create a new directory under
hosts/
for your machine:mkdir -p hosts/newmachine
b. Create
default.nix
in this directory:touch hosts/newmachine/default.nix
c. Add the basic configuration to
default.nix
:For NixOS:
{ inputs, hostname, nixosModules, ... }: { imports = [ inputs.hardware.nixosModules.common-cpu-amd ./hardware-configuration.nix "${nixosModules}/common" "${nixosModules}/programs/hyprland" ]; networking.hostName = hostname; }
For nix-darwin:
{ config, pkgs, ... }: { # Add machine-specific configurations here }
d. For NixOS, generate
hardware-configuration.nix
:sudo nixos-generate-config --show-hardware-config > hosts/newmachine/hardware-configuration.nix
-
Create Home Manager Configuration:
a. Create a new directory for the user's host-specific configuration:
mkdir -p home/newuser/newmachine touch home/newuser/newmachine/default.nix
b. Add basic home configuration:
{ nhModules, ... }: { imports = [ "${nhModules}/common" "${nhModules}/programs/neovim" "${nhModules}/services/waybar" ]; }
-
Building and Applying Configurations:
a. Commit new files to git:
git add .
b. Build and switch to the new system configuration:
For NixOS:
sudo nixos-rebuild switch --flake .#newmachine
For nix-darwin (requires Nix and nix-darwin installation first):
darwin-rebuild switch --flake .#newmachine
c. Build and switch to the new Home Manager configuration:
Important
On fresh systems, bootstrap Home Manager first:
nix-shell -p home-manager
home-manager switch --flake .#newuser@newmachine
After this initial setup, you can rebuild configurations separately and home-manager will be available without additional steps
To update all flake inputs to their latest versions:
nix flake update
common/
: Common system configurationsprograms/corectrl.nix
: CoreCtrl for AMD GPU managementprograms/hyprland.nix
: Hyprland window managerprograms/steam.nix
: Steam gaming platformservices/gnome.nix
: GNOME desktop environmentservices/tlp.nix
: Laptop power management
-
Core Utilities:
common/
: Cross-platform base configurationprograms/git.nix
: Git version controlprograms/neovim.nix
: Neovim text editorprograms/zsh.nix
: Zsh shell configuration
-
Desktop Environment:
programs/hyprland/
: Hyprland window manager setupservices/waybar/
: Custom status bar configurationservices/swaync/
: Notification center setup
-
Development:
programs/go.nix
: Go development environmentprograms/krew.nix
: Kubernetes plugin managerscripts/
: Collection of development utilities
-
macOS Specific:
programs/aerospace.nix
: macOS window management
Contributions are welcome! If you have improvements or suggestions, please open an issue or submit a pull request.
This repository is licensed under MIT License. Feel free to use, modify, and distribute according to the license terms.