Flake-based NixOS and Home Manager configurations for multiple personal machines.
flake.nix: Declares inputs (nixpkgs, home-manager, nixos-hardware) and outputs for NixOS and Home Manager configurationshostnames/: Per-host NixOS configurationshostnames/modules/: Reusable NixOS modules (networking, locales, desktop environments, etc.)hostnames/<hostname>/: Host-specific configuration and hardware profiles
home/: Home Manager configurationshome/modules/: Reusable user-space modules (git, bash, ssh, tmux, etc.)home/joonas/: Per-host Home Manager configs for the joonas user
nix rebuild switch --flake .#<HOSTNAME>Replace <HOSTNAME> with your target machine (e.g., joonas-linux).
home-manager switch --flake .#joonas@<HOSTNAME>nix flake updateReview the flake.lock diff before committing.
-
Generate hardware configuration:
nixos-generate-config --root /mnt --show-hardware-config > hostnames/<new-host>/hardware-configuration.nix
-
Create
hostnames/<new-host>/configuration.niximporting desired modules fromhostnames/modules/ -
Add entries to
flake.nix:nixosConfigurations.<new-host>usingnixosSystemForhomeConfigurations."joonas@<new-host>"usinghomeManagerConfigurationFor
-
Set appropriate
system.stateVersionandhome.stateVersion
common.nix: Base system packages, fonts, sudo, and nix daemon settingslocales.nix: Timezone and locale configurationnetworking.nix: NetworkManager and firewall defaultscosmic.nix,gnome.nix,kde.nix,hyprland.nix: Desktop environment stacks
Focused modules for individual tools:
git.nix: Git identity and aliasesbash.nix,zsh.nix: Shell configurationssh.nix: SSH client settingstmux.nix: Terminal multiplexer config
- Keep secrets out of the repository; use environment variables or external secret management
- Enable unfree packages explicitly per host with
nixpkgs.config.allowUnfree = true - Import only the modules you need in each host configuration
- Comment optional feature imports in host configs for documentation
- Use
nixos-hardwareprofiles for tested hardware configurations - Test configuration changes in a VM before deploying to production machines
If Home Manager is not yet available:
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update
export NIX_PATH=$HOME/.nix-defexpr/channels${NIX_PATH:+:}$NIX_PATH
nix-shell '<home-manager>' -A install
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"Then apply your configuration:
home-manager switch --flake .#joonas@<HOSTNAME>