diff --git a/pkgs/diff-flake/diff-flake b/pkgs/diff-flake/diff-flake index 8b7f83e..ef03122 100755 --- a/pkgs/diff-flake/diff-flake +++ b/pkgs/diff-flake/diff-flake @@ -20,6 +20,21 @@ sanitize_output() { fi } +add_shell() { + local SYSTEM + if [ $# -gt 0 ] && [ -n "$1" ]; then + SYSTEM="$1" + else + SYSTEM="$(nix eval --raw --impure --expr 'builtins.currentSystem')" + fi + # Use 'inputDerivation' attribute to make sure that it is build-able + FLAKE_OUTPUTS+=("devShell.$SYSTEM.inputDerivation") +} + +add_host() { + FLAKE_OUTPUTS+=("nixosConfigurations.$1.config.system.build.toplevel") +} + usage() { print_err "Usage: $0 [option]... [-- [nix build option]...]" print_err "" @@ -37,11 +52,23 @@ usage() { print_err " -p, --previous-rev" print_err " which git revision should be considered the 'previous' state," print_err " defaults to HEAD~" + print_err " --host [name]" + print_err " specify the name of a NixOS output configuration whose" + print_err " closure should be diffed, can be used multiple times" + print_err " if no host name is given, defaults to current hostname" + print_err " --shell [system]" + print_err " specify a specific system's devShell output whose closure" + print_err " should be diffed, can be used multiple times" + print_err " if no system is given, defaults to current system" print_err "" print_err "when no flake outputs are specified, automatically queries for" print_err "all NixOS configurations, and devShell for current system" } +is_option() { + [ $# -gt 0 ] && [[ $1 =~ ^(-.|--.*)$ ]] +} + parse_args() { while [ $# -gt 0 ]; do opt="$1" @@ -68,6 +95,22 @@ parse_args() { PREVIOUS_REV="$(git rev-parse "$1")" shift ;; + --host) + if [ $# -gt 0 ] && ! is_option "$1"; then + add_host "$1" + shift + else + add_host "$(hostname)" + fi + ;; + --shell) + if [ $# -gt 0 ] && ! is_option "$1"; then + add_shell "$1" + shift + else + add_shell + fi + ;; --) NIX_BUILD_ARGS=("$@") break @@ -87,15 +130,6 @@ list_nixos_configurations() { --raw } -fill_default_outputs() { - for host in $(list_nixos_configurations); do - FLAKE_OUTPUTS+=("nixosConfigurations.$host.config.system.build.toplevel") - done - - # Use 'inputDerivation' attribute to make sure that it is build-able - FLAKE_OUTPUTS+=("devShell.$(nix eval --raw --impure --expr 'builtins.currentSystem').inputDerivation") -} - diff_output() { local PREV NEW; PREV="$(mktemp --dry-run)" @@ -115,7 +149,10 @@ diff_output() { parse_args "$@" if [ "${#FLAKE_OUTPUTS[@]}" -eq 0 ]; then - fill_default_outputs + for host in $(list_nixos_configurations); do + add_host "$host" + done + add_shell fi for out in "${FLAKE_OUTPUTS[@]}"; do