Skip to content

khuedoan/dotfiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2,209 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dotfiles

Minimal, performance-focused configuration using Nix. Extremely snappy without sacrificing convenience.

Screenshot

My dotfiles are optimized for Linux, but since they are POSIX compliant, they should work on macOS or BSD as well (as long as the necessary packages are available).

Please feel free to copy bits and pieces that you like ;)

Overview

Repository layout:

  • flake.nix: entrypoint
  • hosts/: one per machine, each host sets hostname, username, and imports the modules it needs.
  • base/: shared baseline
  • modules/ composable modules that hosts can mix and match:
    • cli: shared command-line tools and development packages
    • gui: graphical apps and desktop settings for non-headless machines
    • dotfiles: configuration for nvim, tmux, zsh, fzf, sway, and more!
    • personal: personal-machine configuration
    • work: work-specific packages and configuration
  • Modules follow this pattern:
    • default.nix: entrypoint (Nix convention)
    • darwin.nix: Darwin override
    • linux.nix: Linux override

Customize the configuration

Fork this repo, then:

  • Add a new host to hosts/${HOSTNAME}.nix (or update an existing one) to match your machine and it to flake.nix
  • Customize the host's composable modules
  • Set your username and hostname
  • Replace the SSH public keys and dotfiles repository URLs (if you don't want to use my dotfiles)
  • Replace any host-specific hardware settings
  • Follow installation and usage instruction below
  • Customize the rest of the repo for your needs and clean up things that you don't use

Installation

Review the base, hosts, and modules directories and adjust the configuration to match your machines before installing.

NixOS

Boot into the NixOS live ISO, then install the tools needed for the initial bootstrap:

nix-shell -p git gnumake neovim disko

Clone the repository and run the installer:

git clone https://github.com/khuedoan/nix-setup
cd nix-setup
make install host=HOSTNAME disk=/dev/DISK

Replace HOSTNAME with the host module you want to install and /dev/DISK with the target disk device.

macOS

Before the first run:

  • Update the hostname and primaryUser.username values in hosts/
  • Go to Settings > Privacy & Security > Full Disk Access and allow Terminal

Clone the repository and apply the configuration:

git clone https://github.com/khuedoan/nix-setup
cd nix-setup
make switch host=HOSTNAME

Replace HOSTNAME with the matching entry in flake.nix. The rebuild script installs Nix and Homebrew automatically on a fresh macOS system if they are not already present.

Then reboot.

Usage

Diff the new configuration against the current system profile:

make diff

Apply changes on an installed machine:

make switch

Update packages:

make update

Build a specific host without switching:

make build host=HOSTNAME

Clean up Nix store:

make clean

Testing

GitHub Actions builds all NixOS and Darwin hosts, then applies the test hosts.

You can also test this locally in VMs:

NixOS:

  1. make test

macOS:

  1. Install UTM
  2. Download macOS IPSW recovery file
  3. Create a macOS VM in UTM using the downloaded IPSW file
  4. Run xcode-select --install in the new VM
  5. (Optional) Clone the VM to a new one for easy rollback (UTM doesn't support snapshot yet)
  6. Follow the above steps

Performance

I always try to lazy load where possible. This section attempts to demonstrate how snappy it is.

  • Last updated: December 7, 2023
  • Hardware: Ryzen 5 5600X, 32GB of RAM, running NixOS 23.11

Opening Zsh:

time zsh -i -c exit (47ms)

zsh -i -c exit  0.04s user 0.01s system 100% cpu 0.047 total

Opening the terminal (including waiting for the shell):

time foot zsh -i -c exit (67ms)

foot zsh -i -c exit  0.05s user 0.02s system 103% cpu 0.067 total

Opening Neovim with 14 plugins:

time nvim --headless +qa (47ms)

nvim --headless +qa  0.03s user 0.01s system 83% cpu 0.047 total

Acknowledgements