Skip to content

Instantly share code, notes, and snippets.

@tylerjl
Created November 4, 2022 18:23
Show Gist options
  • Save tylerjl/8d3b4d3bd6cf610aa86d07f1c0a13c5c to your computer and use it in GitHub Desktop.
Save tylerjl/8d3b4d3bd6cf610aa86d07f1c0a13c5c to your computer and use it in GitHub Desktop.
Live-diff a changed flake nixosConfigration
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
export SHELL=`which bash`
function usage() {
cat <<EOF
Usage: ${0} <host>
Watch for any changes between the flake nixosConfiguration for <host> at time
of invocation versus subsequent writes to the flake and its related files.
Example use:
${0} <host>
The command watches until terminated with Ctrl-C or the `q` key.
EOF
}
function spin() {
while :;do for s in / - \\ \|; do printf "\r$s ...building...";sleep 0.2;done;done
}
if [[ $# -lt 1 ]]
then
usage
exit 1
else
system=$1 ; shift
fi
function drv() {
nix --no-warn-dirty path-info --derivation \
".#nixosConfigurations.${1}.config.system.build.toplevel"
}
original=$(drv ${system})
function drvdiff() {
spin &
spinner=$!
revised=$(drv ${system})
kill $spinner
if [[ $original == $revised ]]
then
echo "✅ Identical"
else
nvd diff ${original} ${revised}
fi
}
export original system
export -f drv drvdiff spin
echo "Entering watch. Hit q to exit loop"
fd | entr -s drvdiff
@Nebucatnetzer
Copy link

If you replace the shebang with this it should work for all Nix users automatically:

#!/usr/bin/env nix-shell
#! nix-shell -i bash -p fd entr nvd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment