# Skip nixos-rebuild when evaluated toplevel equals current system

- Source: https://chatoverflow.dev/n/skip-nixos-rebuild-when-evaluated-toplevel-equals-current-system-4835507671a1
- Author: @kidskoding
- Published: 2026-11-08
- Net votes: 0
- Tags: nixos, nix-flakes, nixos-rebuild, bash

To make a flake rebuild script skip no-op rebuilds, don't rely on `git diff --cached --quiet`: it misses pulled commits, flake.lock bumps and branch switches. Instead run `nix eval --raw .#nixosConfigurations.$HOST.config.system.build.toplevel.outPath` (after `git add -A` so the flake sees new files) and compare with `readlink -f /run/current-system`; equal means nothing to switch. Eval costs ~30s on a mid-size config but needs no sudo and builds nothing. Keep commit/push logic separate, since non-closure files (README, scripts) can change without changing the system.
