fix nix-clean for MacOS

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-11-19 12:17:39 +01:00
parent 89d09c4ba5
commit 7d1812cc94
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
3 changed files with 36 additions and 11 deletions

View File

@ -32,14 +32,24 @@ ifndef BUILD_TAG
export BUILD_TAG := $(shell git rev-parse --short HEAD) export BUILD_TAG := $(shell git rev-parse --short HEAD)
endif endif
# Defines which variables will be kept for Nix pure shell, use semicolon as divider
export _NIX_KEEP ?= TMPDIR,BUILD_ENV,STATUS_GO_SRC_OVERRIDE
export NIX_CONF_DIR = $(PWD)/nix
# We don't want to use /run/user/$UID because it runs out of space too easilly # We don't want to use /run/user/$UID because it runs out of space too easilly
export TMPDIR = /tmp/tmp-status-react-$(BUILD_TAG) export TMPDIR = /tmp/tmp-status-react-$(BUILD_TAG)
# this has to be specified for both the Node.JS server process and the Qt process # this has to be specified for both the Node.JS server process and the Qt process
export REACT_SERVER_PORT ?= 5001 export REACT_SERVER_PORT ?= 5001
# Our custom config is located in nix/nix.conf
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
export _NIX_ROOT = /nix
# MacOS root is read-only, read nix/README.md for details
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
export NIX_IGNORE_SYMLINK_STORE=1
export _NIX_ROOT = /opt/nix
endif
#---------------- #----------------
# Nix targets # Nix targets
#---------------- #----------------
@ -63,7 +73,7 @@ nix-clean: ##@nix Remove all status-react build artifacts from /nix/store
nix-purge: SHELL := /bin/sh nix-purge: SHELL := /bin/sh
nix-purge: ##@nix Completely remove the complete Nix setup nix-purge: ##@nix Completely remove the complete Nix setup
sudo rm -rf /nix ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.status .nix-gcroots sudo rm -rf $(_NIX_ROOT) ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.status .nix-gcroots
nix-add-gcroots: export TARGET_OS := none nix-add-gcroots: export TARGET_OS := none
nix-add-gcroots: ##@nix Add Nix GC roots to avoid status-react expressions being garbage collected nix-add-gcroots: ##@nix Add Nix GC roots to avoid status-react expressions being garbage collected
@ -253,6 +263,10 @@ endif
# Tests # Tests
#-------------- #--------------
lint: export _NIX_ATTR := targets.leiningen.shell
lint: ##@test Run code style checks
lein cljfmt check
test: export _NIX_ATTR := targets.leiningen.shell test: export _NIX_ATTR := targets.leiningen.shell
test: ##@test Run tests once in NodeJS test: ##@test Run tests once in NodeJS
lein with-profile test doo node test once lein with-profile test doo node test once

View File

@ -15,19 +15,30 @@ function findRelated() {
path="${1}" path="${1}"
found+=("${path}") found+=("${path}")
if [[ "${path}" =~ .*.chroot ]]; then if [[ "${path}" =~ .*.chroot ]]; then
log " ! Chroot: ${path}" log " ! Chroot: ${path}"
continue return
elif [[ "${path}" =~ .*.lock ]]; then
log " ! Lock: ${path}"
return
elif [[ "${path}" =~ .*status-react-shell.drv ]]; then
echo -n "${path}"
return
fi fi
log " ? Checking: ${path}" log " ? Checking: ${path}"
drv=$(getDrvFiles "${path}") drv=$(getDrvFiles "${path}")
# if drv is unknown-deriver then path is a source # if drv is unknown-deriver then path is a source
if [[ "${drv}" == "unknown-deriver" ]]; then if [[ "${drv}" == "unknown-deriver" ]]; then
drv=$(getReferrers "${path}") drv=$(getReferrers "${path}" | head -n1)
src="${path}" src="${path}"
elif [[ -f "${drv}" ]]; then elif [[ -f "${drv}" ]]; then
src=$(getSources "${drv}") src=$(getSources "${drv}")
fi fi
if [ $(getRoots "${drv}" | wc -l) -eq 0 ]; then # 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 " - Derivation: ${drv}"
log " - Source: ${src}" log " - Source: ${src}"
found+=("${drv}" "${src}") found+=("${drv}" "${src}")

View File

@ -41,7 +41,7 @@ shellArgs=(
if [[ -n "${TARGET_OS}" ]]; then if [[ -n "${TARGET_OS}" ]]; then
shellArgs+=("--argstr target-os ${TARGET_OS}") shellArgs+=("--argstr target-os ${TARGET_OS}")
else else
echo -e "${YELLOW}Env is missing TARGET_OS, assuming no target platform.${NC} See nix/README.md for more details." > /dev/stderr echo -e "${YELLOW}Env is missing TARGET_OS, assuming no target platform.${NC} See nix/README.md for more details." 1>&2
fi fi
if [[ "$TARGET_OS" =~ (linux|windows|darwin|macos) ]]; then if [[ "$TARGET_OS" =~ (linux|windows|darwin|macos) ]]; then
@ -65,7 +65,7 @@ fi
# ENTER_NIX_SHELL is the fake command used when `make shell` is run. # ENTER_NIX_SHELL is the fake command used when `make shell` is run.
# It is just a special string, not a variable, and a marker to not use `--run`. # It is just a special string, not a variable, and a marker to not use `--run`.
if [[ $@ == "ENTER_NIX_SHELL" ]]; then if [[ $@ == "ENTER_NIX_SHELL" ]]; then
echo -e "${GREEN}Configuring ${_NIX_ATTR:-default} Nix shell for target '${TARGET_OS:-none}'...${NC}" > /dev/stderr echo -e "${GREEN}Configuring ${_NIX_ATTR:-default} Nix shell for target '${TARGET_OS:-none}'...${NC}" 1>&2
exec nix-shell ${shellArgs[@]} ${entryPoint} exec nix-shell ${shellArgs[@]} ${entryPoint}
else else
# Not all builds are ready to be run in a pure environment # Not all builds are ready to be run in a pure environment
@ -78,6 +78,6 @@ else
if [[ -n "${_NIX_KEEP}" ]]; then if [[ -n "${_NIX_KEEP}" ]]; then
shellArgs+=("--keep ${_NIX_KEEP//;/ --keep }") shellArgs+=("--keep ${_NIX_KEEP//;/ --keep }")
fi fi
echo -e "${GREEN}Configuring ${pureDesc}${_NIX_ATTR:-default} Nix shell for target '${TARGET_OS}'...${NC}" > /dev/stderr echo -e "${GREEN}Configuring ${pureDesc}${_NIX_ATTR:-default} Nix shell for target '${TARGET_OS}'...${NC}" 1>&2
exec nix-shell ${shellArgs[@]} --run "$@" ${entryPoint} exec nix-shell ${shellArgs[@]} --run "$@" ${entryPoint}
fi fi