nix: Fix errors deleting from store in clean.sh
Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
parent
e3e8e218ad
commit
5ea8040c56
|
@ -12,7 +12,7 @@ function cleanup() {
|
||||||
# do the actual cleanup, ignore failure
|
# do the actual cleanup, ignore failure
|
||||||
if ./nix/clean.sh "${nixResultPath}"; then
|
if ./nix/clean.sh "${nixResultPath}"; then
|
||||||
echo "Successful cleanup!"
|
echo "Successful cleanup!"
|
||||||
elif [[ -n "${JENKINS_URL}" ]]; then
|
elif [[ -n "${IN_CI_ENVIRONMENT}" ]]; then
|
||||||
# in CI removing some paths can fail due to parallel builds
|
# in CI removing some paths can fail due to parallel builds
|
||||||
echo "Ignoring cleanup failure in CI."
|
echo "Ignoring cleanup failure in CI."
|
||||||
else
|
else
|
||||||
|
|
16
nix/clean.sh
16
nix/clean.sh
|
@ -9,6 +9,7 @@ function getSources() { nix-store --query --binding src "${1}"; }
|
||||||
function getOutputs() { nix-store --query --outputs "${1}"; }
|
function getOutputs() { nix-store --query --outputs "${1}"; }
|
||||||
function getDrvFiles() { nix-store --query --deriver "${1}"; }
|
function getDrvFiles() { nix-store --query --deriver "${1}"; }
|
||||||
function getReferrers() { nix-store --query --referrers "${1}"; }
|
function getReferrers() { nix-store --query --referrers "${1}"; }
|
||||||
|
function getRoots() { nix-store --query --roots ${1} }
|
||||||
|
|
||||||
function findRelated() {
|
function findRelated() {
|
||||||
path="${1}"
|
path="${1}"
|
||||||
|
@ -26,10 +27,12 @@ function findRelated() {
|
||||||
elif [[ -f "${drv}" ]]; then
|
elif [[ -f "${drv}" ]]; then
|
||||||
src=$(getSources "${drv}")
|
src=$(getSources "${drv}")
|
||||||
fi
|
fi
|
||||||
log " - Derivation: ${drv}"
|
if [ $(getRoots "${drv}" | wc -l) -eq 0 ]; then
|
||||||
log " - Source: ${src}"
|
log " - Derivation: ${drv}"
|
||||||
|
log " - Source: ${src}"
|
||||||
|
found+=("${drv}" "${src}")
|
||||||
|
fi
|
||||||
|
|
||||||
found+=("${drv}" "${src}")
|
|
||||||
printf '%s\n' "${found[@]}"
|
printf '%s\n' "${found[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +43,7 @@ function findByRegex() {
|
||||||
log "Searching by regex: '${regex}'"
|
log "Searching by regex: '${regex}'"
|
||||||
# search for matching entries in the store
|
# search for matching entries in the store
|
||||||
drvPaths=$(
|
drvPaths=$(
|
||||||
find /nix/store -maxdepth 1 -type d -regextype egrep -regex "${regex}"
|
nix-store --gc --print-dead 2> /dev/null | grep -E "${regex}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# list of store entries to delete
|
# list of store entries to delete
|
||||||
|
@ -73,6 +76,8 @@ if [[ -n "${nixResultPath}" ]]; then
|
||||||
else
|
else
|
||||||
# use regular expression that should match all status-react build artifacts
|
# use regular expression that should match all status-react build artifacts
|
||||||
toDelete=$(findByRegex '.*-status-react-(shell|source|build).*')
|
toDelete=$(findByRegex '.*-status-react-(shell|source|build).*')
|
||||||
|
# add Android Gradle and NPM derivations
|
||||||
|
toDelete+=$(findByRegex 'android-gradle-and-npm-modules(\.drv)?$')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove duplicates and return
|
# remove duplicates and return
|
||||||
|
@ -80,6 +85,3 @@ toDelete=$(printf '%s\n' "${toDelete[@]}" | sort | uniq)
|
||||||
|
|
||||||
log "Deleting..."
|
log "Deleting..."
|
||||||
nix-store --ignore-liveness --delete ${toDelete[@]}
|
nix-store --ignore-liveness --delete ${toDelete[@]}
|
||||||
|
|
||||||
log "Deleting dead Android Gradle and NPM derivations..."
|
|
||||||
nix-store --gc --print-dead | grep -E 'android-gradle-and-npm-modules(\.drv)?$' | xargs nix-store --delete
|
|
||||||
|
|
Loading…
Reference in New Issue