nix-store-from-here() (
  paths=("$@")
  if [[ "${#paths[@]}" -le 0 ]]; then
    echo >&2 "ERROR: no paths provided!"
    return 0
  fi

  # nix_store=$(nix config show TODO)
  nix_store="/nix/store"
  store_paths=()
  # set -x

  for path in "${paths[@]}"; do
    if [[ ! -e "$path" ]]; then
      echo >&2 "WARNING: not found: '$path'"
      continue
    fi

    resolved="$( realpath --no-symlinks "$path" )" # we prefer the originally referenced file and not the path it points to if a in-store symlink
    if [[ ! "$resolved" =~ ^"$nix_store"/*/ ]]; then
      resolved="$( realpath "$path" )" # to resolve files in "result" symlinks
      if [[ ! "$resolved" =~ ^"$nix_store"/*/ ]]; then
        echo >&2 "WARNING: not in store: '$path'"
        continue
      fi
    fi

    # simple
    # store_paths+=("$resolved")

    # only reference top-level store path
    resolved_base="${resolved#"$nix_store/"}"
    resolved_base="${resolved_base%%+(/*)}"
    store_paths+=("$nix_store/$resolved_base")
  done

  if [[ "${#store_paths[@]}" -gt 0 ]]; then
    {
      for fqdn in $(printf "%q\n" $(hostname -f) $(hostname -A) | sort -u); do
        printf "nix copy --from ssh://%q %s  --out-link result\n" "${fqdn}" "$(printf " %q" "${store_paths[@]}")"
      done
    } | column -t -s' ' -o' '
  fi
)
