From 1a64deeb894dc95e2645a75771732c6cc53a79ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 4 Oct 2023 01:35:06 +0200 Subject: Squash changes containing private information There were a lot of changes since the previous commit, but a lot of them contained personnal information about users. All thos changes got stashed into a single commit (history is kept in a different place) and private information was moved in a separate private repository --- scripts/refresh_flakes | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 scripts/refresh_flakes (limited to 'scripts/refresh_flakes') diff --git a/scripts/refresh_flakes b/scripts/refresh_flakes new file mode 100755 index 0000000..2bbcad6 --- /dev/null +++ b/scripts/refresh_flakes @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +set -e + +declare -A refreshed + +while [ -n "$1" ]; do + case "$1" in + --no-new-inputs) + no_new_inputs="y" + shift;; + *) + flake_or_dir="$1" + shift;; + esac +done + +refresh_deps() { + local flake + local inputs=() + local depname + local deppath + flake="$(realpath $1)" + if [ "${refreshed[$flake]}" = 1 ]; then + return + fi + pushd "$flake" 2>/dev/null >/dev/null + if [ -z "$no_new_inputs" ]; then + nix --no-warn-dirty flake lock + fi + if [ ! -e "$flake/flake.lock" ]; then + popd 2>/dev/null >/dev/null + refreshed[$flake]=1 + return + fi + + deps=$(jq -r '. as $root | .nodes[.root].inputs|values|to_entries|map({ key: .key, value: $root.nodes[.value].original.path })[]|select(.value != null)|.key + " " + .value' < flake.lock) + if [ -n "$deps" ]; then + while read depname deppath; do + refresh_deps "$deppath" + inputs+=(--update-input "$depname") + done <<<"$deps" + fi + nix --no-warn-dirty flake lock "${inputs[@]}" + popd 2>/dev/null >/dev/null + refreshed[$flake]=1 +} + +git_dir=$(git rev-parse --show-toplevel) + +# If argument is given (flake.nix or directory containing), refresh that argument +# Otherwise, if we are in a subdirectory containing a flake.nix, refresh that +# Otherwise, refresh all +if [ -n "$flake_or_dir" ]; then + if [ -d "$flake_or_dir" -a -e "$1/flake.nix" ]; then + refresh_deps "$flake_or_dir" + elif [ -f "$flake_or_dir" -a -e "$(dirname $flake_or_dir)/flake.nix" ]; then + refresh_deps "$(dirname $flake_or_dir)" + else + echo "No flake.nix file in specified location" + exit 1 + fi +else + if [ "$(pwd)" != "$git_dir" -a -e "$(pwd)/flake.nix" ]; then + refresh_deps "$(pwd)" + else + find $git_dir -name "flake.lock" | while read flake; do + refresh_deps "$(dirname $flake)" + done + fi +fi -- cgit v1.2.3