Jakub Sokołowski 0311983751
ci: upgrade Nix from 2.3.12 to 2.6.1
Due to changes in how Nix handles Git refs we need to specify
`refs/tags/` prefix in `package.json` to avoid the following error:
```
fatal: couldn't find remote ref refs/heads/v2.0.3-status-v6
error: program 'git' failed with exit code 128
```

I also had to rewrite some logic in `nix/scripts/source.sh` in order to
take account of single-user and multi-user installations.
We default to multi-user for Darwin, but not for any other OS due to
discovered issues with `nix-daemon` socket on Arch and open file limits.

I also rewrote `nix/scripts/setup.sh` and `/nix/scripts/purge.sh` to support
different types of installations. Both single-user and multi-user, as some
operating systems have issues with multi-user installations.

Resolves: https://github.com/status-im/status-react/issues/12832
Depends on: https://github.com/status-im/status-jenkins-lib/pull/37

Related changes:
* https://github.com/status-im/infra-ci/commit/84947b9f
* https://github.com/status-im/infra-ci/commit/bb98f5f3
* https://github.com/status-im/infra-ci/commit/f75d524d
* https://github.com/status-im/infra-ci/commit/d1fc92cd
* https://github.com/status-im/infra-ci/commit/87c4091e
* https://github.com/status-im/infra-ci/commit/8d6b6b3f
* https://github.com/status-im/infra-ci/commit/c4f13285
* https://github.com/status-im/infra-ci/commit/38ac698d

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2022-04-11 12:26:54 +02:00

100 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/nix/scripts/source.sh"
log() { echo "$@" 1>&2; }
# helpers for getting related paths in Nix store
getSources() { nix-store --query --binding src "${1}"; }
getOutputs() { nix-store --query --outputs "${1}"; }
getDrvFiles() { nix-store --query --deriver "${1}"; }
getReferrers() { nix-store --query --referrers "${1}"; }
getRoots() { nix-store --query --roots "${1}"; }
findRelated() {
path="${1}"
found+=("${path}")
if [[ "${path}" =~ .*.chroot ]]; then
log " ! Chroot: ${path}"
return
elif [[ "${path}" =~ .*.lock ]]; then
log " ! Lock: ${path}"
return
elif [[ "${path}" =~ .*status-react-shell.drv ]]; then
echo -n "${path}"
return
fi
log " ? Checking: ${path}"
drv=$(getDrvFiles "${path}")
# if drv is unknown-deriver then path is a source
if [[ "${drv}" == "unknown-deriver" ]]; then
drv=$(getReferrers "${path}" | head -n1)
src="${path}"
elif [[ -f "${drv}" ]]; then
src=$(getSources "${drv}")
fi
# empty paths means this is a source
if [[ -z "${drv}" ]]; then
echo -n "${src}"
return
fi
if [[ $(getRoots "${drv}" | wc -l) -eq 0 ]]; then
log " - Derivation: ${drv}"
log " - Source: ${src}"
found+=("${drv}" "${src}")
fi
printf '%s\n' "${found[@]}"
}
# used to find things to delete based on a regex
findByRegex() {
regex="${1}"
log "Searching by regex: '${regex}'"
# search for matching entries in the store
drvPaths=$(
nix-store --gc --print-dead 2> /dev/null | grep -E "${regex}"
)
# list of store entries to delete
declare -a found
# for each entry find the source and derivation
for mainPath in ${drvPaths}; do
findRelated "${mainPath}"
done
}
# used to find things to delete based on a given path
findByResult() {
mainPath="${1}"
log "Searching by result: '${mainPath}'"
# list of store entries to delete
declare -a found
findRelated "${mainPath}"
}
log "Cleanup of /nix/store..."
# This is an optional CLI argument
nixResultPath="${1}"
if [[ -n "${nixResultPath}" ]]; then
# if provided we can narrow down what to clean based on result path
toDelete=$(findByResult "${nixResultPath}")
else
# use regular expression that should match all status-react build artifacts
toDelete=$(findByRegex '.*-status-(react|go)-(shell|source|build|patched-npm-gradle-modules).*')
fi
# remove duplicates and return
toDelete=$(printf '%s\n' "${toDelete[@]}" | sort | uniq)
log "Deleting..."
nix-store --delete ${toDelete[@]}