{ git, jq, nix, openssh, writeShellApplication, }: writeShellApplication { name = "nixfiles"; runtimeInputs = [git jq nix openssh]; text = '' cmd="$1" shift case "$cmd" in update) if (( $# )); then args=() for input do args+=(--update-input "$input"); done exec nix flake lock "." "''${args[@]}" else exec nix flake update -v "." fi ;; rev) nix flake metadata --json nixfiles | if (( $# )); then jq -r --arg input "$1" '.locks.nodes[$input].locked.rev' else jq -r '.revision // "dirty"' fi ;; repl|eval|build) args=() for arg do case $arg in -w|--wip) args+=(--override-flake config ".") ;; *) args+=("$arg") esac done set -- "''${args[@]}" ;;& repl) exec nix repl ~/.nix-defexpr "$@" ;; eval) exec nix eval -f ~/.nix-defexpr --json "$@" | jq -r . ;; build) exec nix build -f ~/.nix-defexpr --json "$@" | jq -r . ;; home) attr="nixosConfigurations.$HOSTNAME.config.hm.home.activationPackage" export VERBOSE=1 exec nix shell --verbose ".#$attr" "$@" --command home-manager-generation ;; specialise) name="$1" shift exec sudo /run/current-system/specialisation/"$name"/bin/switch-to-configuration switch ;; revert) exec sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch ;; @*) host="''${cmd#@}" hostname="$(ssh -q "$host" 'echo "$HOSTNAME"')" exec nixos-rebuild -v --flake ".#$hostname" --target-host "$host" --use-remote-sudo "$@" ;; *) exec nixos-rebuild -v --flake . --use-remote-sudo "$cmd" "$@" ;; esac ''; }