From 2a6bfdd5f1cef4c5e5b47ae06d95e81a904ca9ca Mon Sep 17 00:00:00 2001 From: chfour Date: Tue, 16 Sep 2025 18:15:19 +0000 Subject: [PATCH] add autorebuild script --- flake.nix | 23 +++++++++++++++++++++++ 1 file(s) changed, 23 insertion(s)(+), 0 deletion(s)(-) diff --git a/flake.nix b/flake.nix --- a/flake.nix +++ b/flake.nix @@ -85,6 +85,29 @@ runtimeInputs = with pkgs; [ jq pandoc ]; text = builtins.readFile ./buildblog.sh; # eh? }; + packages.autorebuild = pkgs.writeShellApplication { + name = "autorebuild"; + runtimeInputs = with pkgs; [ selfPkgs.buildblog pkgs.inotify-tools ]; + text = '' + [ -z "''${1+x}" ] && echo "usage: $0 blog-dir" && exit 1 + + rebuild() { + time buildblog "$1" + } + rebuild "$@" + last=$(date +%s) + inotifywait -r -m "$1" \ + -e modify -e create -e delete -e moved_to \ + --excludei '/index.html|highlighting.css' \ + | while read -r mod; do + echo "$mod" + now=$(date +%s) + [ $((now - last)) -ge 1 ] && rebuild "$@" || echo '< 2s, skipping' + last=$now + done + ''; + }; + packages.website = pkgs.stdenvNoCC.mkDerivation { name = "chfour-website"; -- tangled.sh