5.3 KiB
dots
This repository contains my dotfiles and a Nix flake that supports multiple hosts (machines) with a shared base and per-host configuration.
- On NixOS: hosts are built via
nixosConfigurations. - On non-NixOS (e.g., Ubuntu): hosts are applied via Home Manager using
homeConfigurations.
Bootstrap
pip install pipx ansible
ansible-playbook --ask-become-pass ansible/main.yml
# Then apply dotfiles with dotter
dotter
NixOS: multi-host layout
- nix/base/packages.nix — packages installed on all hosts
- nix/hosts//
- configuration.nix — host-specific NixOS configuration
- hardware-configuration.nix — generated per-machine
- packages.nix — extra packages for this host
- nix/flake.nix — exposes each host under nixosConfigurations
Current hosts:
- limgrave — my main system
- carpates — scaffolded/minimal, ready to extend
Naming rule (important)
Your machine hostname must match the Nix flake host name. For example:
- networking.hostName = "limgrave" in the host configuration
- The flake exports nixosConfigurations.limgrave
- The system hostname (output of
hostname -s) is limgrave
This allows the upgrade function to pick the right configuration automatically.
Build or switch
From repo root:
# Limgrave (current system)
sudo nixos-rebuild switch --flake ./nix#limgrave
# carpates (on target machine)
sudo nixos-rebuild switch --flake ./nix#carpates
# Or during install:
# nixos-install --flake <repo-path>/nix#carpates
Upgrades: nix_upgrade
A convenience Fish function is provided in fish/conf.d/functions.fish: nix_upgrade.
It updates flake inputs and rebuilds the system using a host name that matches the machine hostname.
Usage:
# Automatic: uses (hostname -s) → must match a host in nix/flake.nix
nix_upgrade
# Override the host explicitly (useful for recovery or chroots)
nix_upgrade limgrave
What it does:
- sudo nix flake update --flake /home/catalin/.dotfiles/nix
- sudo nixos-rebuild switch --flake /home/catalin/.dotfiles/nix# --upgrade
Safety checks:
- Verifies nix/flake.nix exists
- Verifies the host is declared in nix/flake.nix
- Prints clear error if the hostname doesn’t map to a known host
Tip: ensure your system hostname matches one of the directories in nix/hosts/ and the entry under nixosConfigurations in nix/flake.nix.
Adding a new host
- Create a directory: nix/hosts//
- Add configuration files (start by copying limgrave and trimming, or use the minimal example from carpates)
- Generate hardware config on the new machine:
sudo nixos-generate-config
# Move merge the generated hardware-configuration.nix into nix/hosts/<newhost>/
- Add the host to nix/flake.nix under nixosConfigurations
- Make sure networking.hostName = "" in the host configuration
- Build or install:
sudo nixos-rebuild switch --flake ./nix#<newhost>
# or during install:
nixos-install --flake <repo-path>/nix#<newhost>
Notes
- Old single-host files nix/configuration.nix and nix/packages.nix are kept for reference but are not used by the flake. You can remove them once comfortable with the new layout.
- limgrave includes nix-snapd and Home Manager; carpates currently includes Home Manager only.
Nix on non-NixOS (Ubuntu, etc.)
You can also use this flake on non-NixOS systems (e.g., Ubuntu) via Home Manager. For that path, hosts are defined under homeConfigurations in nix/flake.nix and typically live next to their NixOS counterparts. In this repo, carpates is prepared for non-NixOS via Home Manager.
- Naming rule: your machine's hostname (output of
hostname -s) should match thehomeConfigurations.<host>entry. Example:carpates. - Packages: non-NixOS hosts usually install user-scoped packages via Home Manager, using the shared base set from
nix/base/packages.nix.
Prerequisites
- Install Nix (multi-user is recommended):
sh <(curl -L https://nixos.org/nix/install) --daemon - Enable flakes (if not already). On non-NixOS, set in
/etc/nix/nix.confor$XDG_CONFIG_HOME/nix/nix.conf:experimental-features = nix-command flakes - Install Home Manager (no separate channel needed when using flakes; we can run it via
nix runor install it on PATH):# Optional, to have `home-manager` on PATH: nix profile install github:nix-community/home-manager
Apply the configuration (non-NixOS)
From repo root:
# Use the prepared Home Manager host (example: carpates)
home-manager switch --flake ./nix#carpates
# If `home-manager` is not installed, you can run it via nix:
nix run github:nix-community/home-manager -- switch --flake ./nix#carpates
Upgrades (non-NixOS)
nix_upgrade also works on non-NixOS:
# Auto-detects host from (hostname -s) and runs Home Manager switch
nix_upgrade
# Or override explicitly
nix_upgrade carpates
What it does on non-NixOS:
nix flake update --flake /home/catalin/.dotfiles/nixhome-manager switch --flake /home/catalin/.dotfiles/nix#<host>(ornix run ... -- switchif HM is not on PATH)
NixOS vs. non-NixOS summary
- NixOS hosts are declared under
nixosConfigurationsand are applied withnixos-rebuild. - non-NixOS hosts are declared under
homeConfigurationsand are applied withhome-manager switch. - The
nix_upgradefunction detects the OS and selects the correct path automatically based on the hostname.