First Steps After Installation
Learn how to customize and use your new Nix configuration.
Table of Contents
Section titled “Table of Contents”- Overview
- Understanding Your System
- Adding Packages
- Customizing Shell
- Working with Profiles
- Managing Secrets
- Setting Up Hardware Security
- Daily Workflow
- Next Steps
Overview
Section titled “Overview”You’ve successfully installed your Nix configuration! This guide covers:
- Understanding your system structure
- Adding and removing packages
- Customizing your environment
- Working with modules and profiles
- Daily usage patterns
Understanding Your System
Section titled “Understanding Your System”Key Directories
Section titled “Key Directories”~/Config/├── flake.nix # Main entry point├── flake.lock # Locked dependencies├── nix/│ ├── modules/ # System-level configuration│ ├── profiles/ # Feature bundles│ ├── packages/ # Custom packages│ └── overlays/ # Package customizations├── hosts/ # Host-specific configs│ └── your-mac.nix # Your machine└── home/ # User configs └── users/ └── yourname.nix # Your user settings
Configuration Layers
Section titled “Configuration Layers”-
Base Modules (
nix/modules/
)common.nix
- Shared across all platformsdarwin-base.nix
- macOS-specific settings
-
Feature Profiles (
nix/profiles/
)cloud-cli.nix
- AWS, GCP, Kubernetes toolsdeveloper.nix
- Development utilitieshardware-security.nix
- Ledger, GPG, SSH
-
Host Config (
hosts/your-mac.nix
)- Machine-specific settings
- User definitions
- System packages
-
User Config (
home/users/yourname.nix
)- Shell configuration
- Git settings
- User packages
Adding Packages
Section titled “Adding Packages”System-Wide Packages
Section titled “System-Wide Packages”Edit your host configuration (hosts/your-mac.nix
):
{ config, pkgs, ... }:{ environment.systemPackages = with pkgs; [ # Development python3 nodejs go
# Utilities htop ripgrep fd
# Your additions here ];}
User Packages
Section titled “User Packages”Edit your user configuration (home/users/yourname.nix
):
{ config, pkgs, ... }:{ home.packages = with pkgs; [ # User-specific tools fzf bat exa
# Your additions here ];}
Apply Changes
Section titled “Apply Changes”cd ~/Configdarwin-rebuild switch --flake .#your-hostname
Finding Packages
Section titled “Finding Packages”# Search nixpkgsnix search nixpkgs python
# Search with descriptionnix search nixpkgs --json python | jq '.[].description'
# Browse online# https://search.nixos.org/packages
Customizing Shell
Section titled “Customizing Shell”Zsh Configuration
Section titled “Zsh Configuration”Your shell is configured in home/users/yourname.nix
:
programs.zsh = { enable = true; enableCompletion = true;
# Add aliases shellAliases = { ll = "ls -la"; g = "git"; d = "docker"; };
# Add init content initContent = '' # Custom prompt export PS1="%F{blue}%n@%m%f %F{yellow}%~%f %# "
# Custom functions mkcd() { mkdir -p "$1" && cd "$1"; } '';};
Shell Aliases
Section titled “Shell Aliases”programs.zsh.shellAliases = { # Nix shortcuts nb = "darwin-rebuild switch --flake ~/Config"; nu = "nix flake update ~/Config";
# Git shortcuts gs = "git status"; gc = "git commit"; gp = "git push";
# Docker/Colima dc = "docker compose"; dps = "docker ps";};
Environment Variables
Section titled “Environment Variables”home.sessionVariables = { EDITOR = "vim"; BROWSER = "open"; LANG = "en_US.UTF-8";
# Custom paths MY_PROJECT = "$HOME/Projects";};
Working with Profiles
Section titled “Working with Profiles”Enable a Profile
Section titled “Enable a Profile”Profiles are composable feature bundles. Add to your host config:
# In hosts/your-mac.nix or flake.nix imports{ imports = [ ./nix/profiles/cloud-cli.nix # ✅ Already enabled ./nix/profiles/developer.nix # ✅ Already enabled ./nix/profiles/hardware-security.nix # Optional ];}
Create Custom Profile
Section titled “Create Custom Profile”Create nix/profiles/my-profile.nix
:
{ config, pkgs, ... }:{ # System packages environment.systemPackages = with pkgs; [ package1 package2 ];
# Home-manager config (if in user context) home.packages = with pkgs; [ user-package1 ];
# System settings programs.myapp.enable = true;}
Add to your host:
imports = [ ./nix/profiles/my-profile.nix];
Available Profiles
Section titled “Available Profiles”- cloud-cli - AWS, GCP, Kubernetes, Terraform
- developer - jq, yq, tree, just
- hardware-security - Ledger, GPG, SSH agents
Managing Secrets
Section titled “Managing Secrets”Set Up SOPS
Section titled “Set Up SOPS”-
Install Ledger (optional) - See Ledger Setup
-
Configure SOPS module:
# In flake.nix importsimports = [./nix/modules/secrets/sops.nix]; -
Create secret file:
Terminal window # Set GPG homeexport GNUPGHOME=~/.gnupg-ledger# Create encrypted secretsops nix/secrets/secrets.yaml -
Use secret in config:
# Declare secretsops.secrets."myapp/api-key" = {};# Reference in configenvironment.variables = {API_KEY_FILE = config.sops.secrets."myapp/api-key".path;};
See SOPS Guide for details.
Setting Up Hardware Security
Section titled “Setting Up Hardware Security”Ledger Configuration
Section titled “Ledger Configuration”For GPG signing and SSH authentication with Ledger:
-
Follow setup guide: Ledger Setup
-
Enable in your user config:
# In home/users/yourname.niximports = [../../nix/profiles/hardware-security.nix]; -
Rebuild:
Terminal window darwin-rebuild switch --flake .#your-hostname
Features Included
Section titled “Features Included”- ✅ GPG signing for git commits
- ✅ SSH authentication with hardware key
- ✅ SOPS secrets encrypted with Ledger GPG
- ✅ Physical confirmation for all operations
Daily Workflow
Section titled “Daily Workflow”Making Changes
Section titled “Making Changes”-
Edit configuration files
Terminal window cd ~/Confignano hosts/your-mac.nix # or home/users/yourname.nix -
Test build (dry run)
Terminal window darwin-rebuild build --flake .#your-hostname -
Apply changes
Terminal window darwin-rebuild switch --flake .#your-hostname -
Commit changes
Terminal window git add .git commit -m "Add package X"git push
Updating Dependencies
Section titled “Updating Dependencies”# Update all flake inputsnix flake update
# Update specific inputnix flake lock --update-input nixpkgs
# Apply updatesdarwin-rebuild switch --flake .#your-hostname
Cleaning Up
Section titled “Cleaning Up”# Remove old generations (30+ days)nix-collect-garbage --delete-older-than 30d
# Remove all old generationsnix-collect-garbage -d
# Optimize store (deduplicate)nix-store --optimise
Viewing System State
Section titled “Viewing System State”# List generationsdarwin-rebuild list-generations
# Show current generationls -l /run/current-system
# View generation diffdarwin-rebuild --list-generations | head -2 | \ xargs -n1 nix store diff-closures
Common Tasks
Section titled “Common Tasks”Add Homebrew Cask
Section titled “Add Homebrew Cask”# In nix/modules/darwin/homebrew.nixhomebrew.casks = [ "ledger-live" "visual-studio-code" # Add here];
Change System Settings
Section titled “Change System Settings”# In nix/modules/darwin-base.nixsystem.defaults = { dock = { autohide = true; orientation = "bottom"; show-recents = false; };
NSGlobalDomain = { AppleShowAllExtensions = true; InitialKeyRepeat = 15; KeyRepeat = 2; };};
Add Overlay
Section titled “Add Overlay”Create nix/overlays/my-overlay.nix
:
final: prev: { my-package = prev.my-package.overrideAttrs (old: { version = "1.2.3"; # ... customizations });}
Reference in flake.nix:
nixpkgs.overlays = [ (import ./nix/overlays/my-overlay.nix)];
Troubleshooting
Section titled “Troubleshooting”Build Errors
Section titled “Build Errors”# Check for syntax errorsnix flake check
# Verbose build outputdarwin-rebuild switch --flake .#your-hostname --show-trace
# Check recent changesgit diff HEAD~1
Package Conflicts
Section titled “Package Conflicts”# Find conflicting packagesnix-store --query --requisites /run/current-system | grep package-name
# Remove from both user and system configs
Rollback Changes
Section titled “Rollback Changes”# List generationsdarwin-rebuild list-generations
# Rollback to previousdarwin-rebuild switch --rollback
# Switch to specific generationdarwin-rebuild switch --switch-generation 42
Next Steps
Section titled “Next Steps”Learn More
Section titled “Learn More”- Structure Guide - Deep dive into architecture
- Development Guides - Extend your config
- Nix Fundamentals - Understand Nix internals
Advanced Topics
Section titled “Advanced Topics”- Creating Modules - Write custom modules
- Working with Overlays - Customize packages
- Cloud Deployment - Deploy to EC2/GCE
Examples
Section titled “Examples”- Adding New Host - Set up another machine
- Custom Profile - Build feature bundles
- Multi-User Setup - Configure for teams
Quick Reference
Section titled “Quick Reference”Essential Commands
Section titled “Essential Commands”# Apply changesdarwin-rebuild switch --flake .#hostname
# Test builddarwin-rebuild build --flake .#hostname
# Update flakenix flake update
# Clean upnix-collect-garbage -d
# Search packagesnix search nixpkgs package-name
# View package infonix eval nixpkgs#package-name.meta.description
File Locations
Section titled “File Locations”~/Config/hosts/your-mac.nix # System config~/Config/home/users/you.nix # User config~/.nix-profile # User profile/run/current-system # Active system
Happy configuring! 🚀
See CLI Commands Reference for more commands.