Skip to content

Commit 47da388

Browse files
committed
refactor: simplify proviso
1 parent a455fa7 commit 47da388

File tree

4 files changed

+46
-61
lines changed

4 files changed

+46
-61
lines changed

src/actions.nix

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,27 @@
1717
l.toFile "build-proviso"
1818
# bash
1919
''
20-
function proviso() {
21-
local -n input=$1
22-
local -n output=$2
23-
24-
local drvs
25-
local -a uncached
26-
27-
# FIXME: merge upstream to avoid any need for runtime context
28-
command nix build github:divnix/nix-uncached/v2.13.1
29-
30-
drvs=$(command jq -r '.targetDrv | select(. != "null")' <<< "''${input[@]}")
31-
32-
uncached_json=$(result/bin/nix-uncached $drvs)
33-
34-
mapfile -t uncached < <(command jq -r 'to_entries[]|select(.value != [])|.key' <<< "$uncached_json")
35-
36-
if [[ -n ''${uncached[*]} ]]; then
37-
local list filtered
38-
39-
list=$(command jq -ncR '[inputs]' <<< "''${uncached[@]}")
40-
filtered=$(command jq -c 'select([.targetDrv] | inside($p))' --argjson p "$list" <<< "''${input[@]}")
41-
42-
output=$(command jq -cs '. += $p' --argjson p "$output" <<< "$filtered")
43-
fi
44-
}
20+
# FIXME: merge upstream to avoid any need for runtime context
21+
command nix build github:divnix/nix-uncached/v2.13.1
22+
23+
local -a drvs
24+
eval "$(
25+
command jq --raw-output '
26+
"drvs=(\(map(.targetDrv|strings)|@sh))"
27+
' <<< "$1"
28+
)"
29+
30+
command jq --raw-output \
31+
--argjson checked "$(./result/bin/nix-uncached ''${drvs[@]})" \
32+
' (
33+
$checked | with_entries(select(.value == [])) | keys
34+
) as $cached
35+
| map(select(
36+
[.targetDrv] | IN($cached) | not
37+
))
38+
' <<< "$1"
39+
40+
unset drvs
4541
'';
4642
};
4743

src/blocktypes/containers.nix

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,33 @@
6969
${copyFn}
7070
copy docker://${img}
7171
'';
72+
meta.images = map (tag: "${img}:${tag}") tags;
7273
proviso = l.toFile "container-proviso" ''
73-
SKOPEO_INSPECT=${./proviso/skopeo-inspect.sh}
74-
${builtins.readFile ./proviso/publish.sh}
74+
function scopeo_inspect() {
75+
local images=("$@")
76+
for image in ''${images[@]}; do
77+
if command &>/dev/null skopeo inspect --insecure-policy "docker://$image"; then
78+
echo "$image"
79+
fi
80+
done
81+
}
82+
83+
declare -a images
84+
eval "$(
85+
command jq --raw-output '
86+
"images=(\(map(.meta.images[0]|strings)|@sh))"
87+
' <<< "$1"
88+
)"
89+
90+
command jq --raw-output \
91+
--arg available "$(scopeo_inspect ''${images[@]})" \
92+
' map(select(
93+
.meta.images[0] | inside($available) | not
94+
))
95+
' <<< "$1"
96+
97+
unset images
7598
'';
76-
meta.images = map (tag: "${img}:${tag}") tags;
7799
})
78100
(mkCommand currentSystem {
79101
name = "load";

src/blocktypes/proviso/publish.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/blocktypes/proviso/skopeo-inspect.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)