#nix #flake #watcher #nixos #nixpkgs

app flake-watcher

A simple tool to watch for changes in a nix flake and run a command when it changes

2 releases

0.1.1 Jan 16, 2023
0.1.0 Jan 16, 2023

#498 in Development tools

MIT license

152 lines


Build a local flake everytime its files change.

flake-watcher will print every new output path to stdout. Errors will be logged to stderr.


To run without installing you can use

nix run github:zebreus/flake-watcher

You can install the flake with nix profile install github:zebreus/flake-watcher . flake-watcher is also available on crates.io.


Run on the default installable of the flake in the current directory. This will build the default installable every time a file in the flake changes.

$ flake-watcher .#default

See all options:

$ flake-watcher --help
Usage: flake-watcher [OPTIONS] [INSTALLABLE] [-- <NIX_BUILD_OPTIONS>...]

  [INSTALLABLE]           The flake output that will get watched. Example: .#foo
  [NIX_BUILD_OPTIONS]...  Additional options passed to nix build

      --skip-initial-build  Usually the flake is build once after starting flake-watcher even if no changes were made. This option skips that initial build
  -h, --help                Print help
  -V, --version             Print version


I wanted to build a document with a nix flake and have it update every time I modify the sources. I also wanted to be able to use the same flake to build the document in CI. Originally I planned to integrate a reloading webserver in flake-watcher but I decided to keep it simple and just print the new output path to stdout. This way you can pipe the output to any other program you want. Also I wasted enough time doing this, maybe I'll add a webserver later.

# The flake output contains html files that get hosted with a reloading webserver
export TEMP_DIR=$(mktemp -d)
nix run nixpkgs#python39Packages.livereload $TEMP_DIR &
flake-watcher | xargs  -I {} cp -Trf {} $TEMP_DIR


~108K SLoC