Skip to content

Commit c5b1ebf

Browse files
committed
refactor: use jq proviso filter files
1 parent f2c1b36 commit c5b1ebf

File tree

4 files changed

+47
-38
lines changed

4 files changed

+47
-38
lines changed

src/actions.nix

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,23 @@
1313
nix build ${contextFreeDrv target}
1414
'';
1515
targetDrv = target.drvPath;
16-
proviso =
16+
proviso = let
17+
filter = ./build-filter.jq;
18+
in
1719
l.toFile "build-proviso"
1820
# bash
1921
''
20-
# FIXME: merge upstream to avoid any need for runtime context
21-
command nix build github:divnix/nix-uncached?ref=refs/pull/2/head
22-
2322
local -a drvs
2423
eval "$(
25-
command jq --raw-output '
26-
"drvs=(\(map(.targetDrv|strings)|@sh))"
27-
' <<< "$1"
24+
command jq --raw-output '"drvs=(\(map(.targetDrv|strings)|@sh))"' <<< "$1"
2825
)"
2926
27+
# FIXME: merge upstream to avoid any need for runtime context
28+
command nix build github:divnix/nix-uncached?ref=refs/pull/2/head
29+
3030
command jq --raw-output \
3131
--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"
32+
--from-file ${filter} <<< "$1"
3933
4034
unset drvs
4135
'';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
. as $inputs
2+
3+
| $inputs | map( select(
4+
.meta.images[0] | inside($available) | not
5+
))

src/blocktypes/containers.nix

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,34 @@
7070
copy docker://${img}
7171
'';
7272
meta.images = map (tag: "${img}:${tag}") tags;
73-
proviso = l.toFile "container-proviso" ''
74-
function _scopeo_inspect() {
75-
if command &>/dev/null skopeo inspect --insecure-policy "docker://$image"; then
76-
echo "$image"
77-
fi
78-
}
79-
export -f _scopeo_inspect
73+
proviso = let
74+
filter = ./container-publish-filter.jq;
75+
in
76+
l.toFile "container-proviso" ''
77+
function _scopeo_inspect() {
78+
if command &>/dev/null skopeo inspect --insecure-policy "docker://$image"; then
79+
echo "$image"
80+
fi
81+
}
82+
export -f _scopeo_inspect
8083
81-
function scopeo_inspect() {
82-
echo "$@" | command xargs -n 1 -P 0 -I {} bash -c '_scopeo_inspect "$@"'
83-
}
84+
function scopeo_inspect() {
85+
echo "$@" | command xargs -n 1 -P 0 -I {} bash -c '_scopeo_inspect "$@"'
86+
}
8487
85-
declare -a images
86-
eval "$(
87-
command jq --raw-output '
88-
"images=(\(map(.meta.images[0]|strings)|@sh))"
89-
' <<< "$1"
90-
)"
88+
declare -a images
89+
eval "$(
90+
command jq --raw-output '
91+
"images=(\(map(.meta.images[0]|strings)|@sh))"
92+
' <<< "$1"
93+
)"
9194
92-
command jq --raw-output \
93-
--arg available "$(_scopeo_inspect ''${images[@]})" \
94-
' map(select(
95-
.meta.images[0] | inside($available) | not
96-
))
97-
' <<< "$1"
95+
command jq --raw-output \
96+
--arg available "$(_scopeo_inspect ''${images[@]})" \
97+
--from-file ${filter} <<< "$1"
9898
99-
unset images
100-
'';
99+
unset images
100+
'';
101101
})
102102
(mkCommand currentSystem {
103103
name = "load";

src/build-filter.jq

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
. as $inputs |
2+
3+
( $checked
4+
| with_entries(select(.value == []))
5+
| keys
6+
) as $cached
7+
8+
| $inputs | map( select(
9+
[.targetDrv] | IN($cached) | not
10+
))

0 commit comments

Comments
 (0)