nix: move nix-purge code to nix/scripts/purge.sh

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-04-21 12:29:54 +02:00
parent 4670ae7549
commit 918b03d459
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
3 changed files with 31 additions and 14 deletions

View File

@ -41,15 +41,11 @@ export REACT_SERVER_PORT ?= 5001
export NIX_CONF_DIR = $(PWD)/nix
# Defines which variables will be kept for Nix pure shell, use semicolon as divider
export _NIX_KEEP ?= TMPDIR,BUILD_ENV,STATUS_GO_SRC_OVERRIDE,NIMBUS_SRC_OVERRIDE
export _NIX_ROOT = /nix
# legacy TARGET_OS variable support
ifdef TARGET_OS
export TARGET ?= $(TARGET_OS)
endif
# Useful for checking if we are on NixOS
OS_NAME := $(shell [ -f /etc/os-release ] && awk -F= '/^NAME/{print $2}' /etc/os-release)
# Useful for Andoird release builds
TMP_BUILD_NUMBER := $(shell ./scripts/version/gen_build_no.sh | cut -c1-10)
@ -57,7 +53,6 @@ TMP_BUILD_NUMBER := $(shell ./scripts/version/gen_build_no.sh | cut -c1-10)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
export NIX_IGNORE_SYMLINK_STORE=1
export _NIX_ROOT = /opt/nix
endif
#----------------
@ -78,19 +73,17 @@ else
@echo "${YELLOW}Nix shell is already active$(RESET)"
endif
nix-gc: export TARGET := default
nix-gc: ##@nix Garbage collect all packages older than 20 days from /nix/store
nix-collect-garbage --delete-old --delete-older-than 20d
nix-clean: export TARGET := default
nix-clean: ##@nix Remove all status-react build artifacts from /nix/store
nix/scripts/clean.sh
nix-purge: SHELL := /bin/sh
nix-purge: ##@nix Completely remove the complete Nix setup
ifeq ($(OS_NAME), NixOS)
$(error $(RED)You should not purge Nix files on NixOS!$(RESET))
else
sudo rm -rf $(_NIX_ROOT)/* ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.status .nix-gcroots
endif
nix-purge: ##@nix Completely remove Nix setup, including /nix directory
nix/scripts/purge.sh
nix-add-gcroots: export TARGET := default
nix-add-gcroots: ##@nix Add Nix GC roots to avoid status-react expressions being garbage collected

24
nix/scripts/purge.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/scripts/colors.sh"
# Purging /nix on NixOS would be disasterous
if [[ -f "/etc/os-release" ]]; then
OS_NAME=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
if [[ "$OS_NAME" == "NixOS" ]]; then
echo -e "${RED}You should not purge Nix files on NixOS!${RST}" >&2
exit
fi
fi
NIX_ROOT="/nix"
if [[ $(uname -s) == "Darwin" ]]; then
# Special case due to read-only root on MacOS Catalina
NIX_ROOT="/opt/nix"
fi
sudo rm -rf ${NIX_ROOT}/* ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.status .nix-gcroots
echo -e "${GRN}Purged all Nix files from your system.${RST}" >&2

View File

@ -15,14 +15,14 @@ function install_nix() {
if [ $? -eq 0 ]; then
echo -e "${GRN}The Nix package manager was successfully installed.${RST}"
else
echo -e "${RED}Failed to install Nix package manager!${RST}" > /dev/stderr
echo "Please see: https://nixos.org/nix/manual/#chap-installation" > /dev/stderr
echo -e "${RED}Failed to install Nix package manager!${RST}" >&2
echo "Please see: https://nixos.org/nix/manual/#chap-installation" >&2
exit 1
fi
}
if [[ ! -x "$(command -v git)" ]]; then
echo -e "${RED}The 'curl' utility is required for Nix installation.${RST}" > /dev/stderr
echo -e "${RED}The 'curl' utility is required for Nix installation.${RST}" >&2
exit 1
fi