This repository contains my personal Nix configuration for managing NixOS, nix-darwin, and Home Manager setups across multiple machines. It also includes various dotfiles and helper scripts to streamline my development and system management workflows.
Copy the provided .env.example
file to .env
and update the FLAKE_OUTPUT
variable to match the desired configuration defined in flake.nix
.
cp .env.example .env
vim .env # update FLAKE_OUTPUT accordingly
The included Makefile
simplifies common Nix operations. It automatically detects the system type and runs the appropriate command:
- NixOS:
sudo nixos-rebuild switch --flake .#<FLAKE_OUTPUT>
- macOS (nix-darwin):
darwin-rebuild switch --flake .#<FLAKE_OUTPUT>
- Other (Home Manager):
home-manager switch -b bak --flake .#<FLAKE_OUTPUT>
To apply the configuration, simply run:
make switch
-
dotfiles/: Contains configuration files unrelated directly to Nix. Many of these files are symlinked into place by the Nix configuration. Some files are stored purely for reference and may not be actively used.
-
hosts/: Each subdirectory corresponds to a physical machine or environment. Host-specific configurations such as
configuration.nix
,hardware-configuration.nix
, andhome.nix
(for Home Manager) are stored here. -
modules/: Contains reusable Nix modules that are not specific to any single host. Modules are organized based on their intended use (NixOS, nix-darwin, or Home Manager).
-
overlays/: Custom overlays for nixpkgs. For example, an overlay is provided to access stable nixpkgs packages via
pkgs.stable.<package-name>
. -
pkgs/: Custom Nix packages are defined here. These packages are typically added to overlays for easy reuse throughout the configuration.
-
scripts/: Helper scripts for common tasks. For instance, a script is included to update the
flake.lock
file in the root directory and within each template. -
templates/: Contains Nix flake templates for quickly bootstrapping new development environments. Each template includes boilerplate files and a
.envrc
file for automatic environment initialization via direnv.To initialize a new project from a template, run:
nix flake init -t nix-config#<template-name>
A local nix registry entry for
nix-config
is configured to simplify referencing these templates.
To clean up old Nix generations and free disk space, run:
make clean
This command will remove generations older than the configured threshold (GC_OLDER_THAN
, defaulting to 7 days).
To update all flake lock files, execute:
make update
If Nix is not yet installed on the system, the Determinate Nix Installer can be invoked by running:
make install_nix
To bootstrap a new macOS system with nix-darwin, run:
make bootstrap_darwin
To bootstrap Home Manager on a non-NixOS, non-macOS system, run:
make bootstrap_hm
- Ensure that the
.env
file is correctly configured before running any commands. - Regularly update the flake lock files to keep system configurations current and secure.