mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 03:26:31 +00:00
Jakub Sokołowski
aca703a011
Changes: - Adds a new `nix-gc` Makefile target for removing old packages - Moves all `nix/*.sh` files to `nix/scripts/*.sh` to make things more tidy - Renames `TARGET_OS` into `TARGET` and makes it effective only with `nix/scripts/shell.sh` - Renames `target-os` Nix argument to just `target` and makes it effective only with `shell.nix` - Drops `IN_CI_ENVIRONMENT` env variable which was useless - Drops use of `target-os` argument outside of `shell.nix` (with few exceptions, but just in naming) - `nix/platform.nix` has been made obsolete and removed - Moves the definition of all major targets to `nix/targets.nix` - Moves the definition of all major shells to `nix/shells.nix` - Makes `default.nix` and `shell.nix` just thin wrappers around `nix/default.nix` - `nix/nixpkgs-bootstrap.nix` has been moved to `nix/pkgs.nix` - All package and tool overrides have been moved to `nix/pkgs.nix` - Explicit passing of contents of `pkgs` has been removed in favor of `callPackage` doing it for us - `nix/bootstrapped-shell.nix` has been moved to `nix/tools/mkShell.nix` - A new `mergeSh` tool has been added to `pkgs` from `nix/tools/mergeSh.nix` - This tool is used to merge shells created using `mkShell` - `mobile/targets/jsbundle.nix` has been moved to `mobile/android/jsbundle/default.nix` - Moves `status-go` version sanitization to `nix/status-go/utils.nix` - Renames version to rawVersion and versionName to cleanVersion in status-go derivation - Ports nix/mobile/ios/install-pods-and-status-go.sh to Nix sub-shells - Moves adjustment of `inotify/max_user_watches` out into `scripts/inotify_fix.sh` - Makes iOS builds use the Nix version of Fastlane Signed-off-by: Jakub Sokołowski <jakub@status.im>
97 lines
2.7 KiB
Bash
Executable File
97 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
function log() { echo "$@" 1>&2; }
|
|
|
|
# helpers for getting related paths in Nix store
|
|
function getSources() { nix-store --query --binding src "${1}"; }
|
|
function getOutputs() { nix-store --query --outputs "${1}"; }
|
|
function getDrvFiles() { nix-store --query --deriver "${1}"; }
|
|
function getReferrers() { nix-store --query --referrers "${1}"; }
|
|
function getRoots() { nix-store --query --roots "${1}"; }
|
|
|
|
function 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
|
|
function 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
|
|
function 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-(shell|source|build|patched-npm-gradle-modules).*')
|
|
fi
|
|
|
|
# remove duplicates and return
|
|
toDelete=$(printf '%s\n' "${toDelete[@]}" | sort | uniq)
|
|
|
|
log "Deleting..."
|
|
nix-store --ignore-liveness --delete ${toDelete[@]}
|