diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2023-10-04 01:35:06 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2023-10-04 02:11:48 +0200 |
commit | 1a64deeb894dc95e2645a75771732c6cc53a79ad (patch) | |
tree | 1b9df4838f894577a09b9b260151756272efeb53 /scripts/refresh_flakes | |
parent | fa25ffd4583cc362075cd5e1b4130f33306103f0 (diff) | |
download | Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.tar.gz Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.tar.zst Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.zip |
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
Diffstat (limited to 'scripts/refresh_flakes')
-rwxr-xr-x | scripts/refresh_flakes | 71 |
1 files changed, 71 insertions, 0 deletions
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 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | declare -A refreshed | ||
6 | |||
7 | while [ -n "$1" ]; do | ||
8 | case "$1" in | ||
9 | --no-new-inputs) | ||
10 | no_new_inputs="y" | ||
11 | shift;; | ||
12 | *) | ||
13 | flake_or_dir="$1" | ||
14 | shift;; | ||
15 | esac | ||
16 | done | ||
17 | |||
18 | refresh_deps() { | ||
19 | local flake | ||
20 | local inputs=() | ||
21 | local depname | ||
22 | local deppath | ||
23 | flake="$(realpath $1)" | ||
24 | if [ "${refreshed[$flake]}" = 1 ]; then | ||
25 | return | ||
26 | fi | ||
27 | pushd "$flake" 2>/dev/null >/dev/null | ||
28 | if [ -z "$no_new_inputs" ]; then | ||
29 | nix --no-warn-dirty flake lock | ||
30 | fi | ||
31 | if [ ! -e "$flake/flake.lock" ]; then | ||
32 | popd 2>/dev/null >/dev/null | ||
33 | refreshed[$flake]=1 | ||
34 | return | ||
35 | fi | ||
36 | |||
37 | 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) | ||
38 | if [ -n "$deps" ]; then | ||
39 | while read depname deppath; do | ||
40 | refresh_deps "$deppath" | ||
41 | inputs+=(--update-input "$depname") | ||
42 | done <<<"$deps" | ||
43 | fi | ||
44 | nix --no-warn-dirty flake lock "${inputs[@]}" | ||
45 | popd 2>/dev/null >/dev/null | ||
46 | refreshed[$flake]=1 | ||
47 | } | ||
48 | |||
49 | git_dir=$(git rev-parse --show-toplevel) | ||
50 | |||
51 | # If argument is given (flake.nix or directory containing), refresh that argument | ||
52 | # Otherwise, if we are in a subdirectory containing a flake.nix, refresh that | ||
53 | # Otherwise, refresh all | ||
54 | if [ -n "$flake_or_dir" ]; then | ||
55 | if [ -d "$flake_or_dir" -a -e "$1/flake.nix" ]; then | ||
56 | refresh_deps "$flake_or_dir" | ||
57 | elif [ -f "$flake_or_dir" -a -e "$(dirname $flake_or_dir)/flake.nix" ]; then | ||
58 | refresh_deps "$(dirname $flake_or_dir)" | ||
59 | else | ||
60 | echo "No flake.nix file in specified location" | ||
61 | exit 1 | ||
62 | fi | ||
63 | else | ||
64 | if [ "$(pwd)" != "$git_dir" -a -e "$(pwd)/flake.nix" ]; then | ||
65 | refresh_deps "$(pwd)" | ||
66 | else | ||
67 | find $git_dir -name "flake.lock" | while read flake; do | ||
68 | refresh_deps "$(dirname $flake)" | ||
69 | done | ||
70 | fi | ||
71 | fi | ||