From 7d1812cc9482a415577d659a4f6849dd52d953a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 19 Nov 2019 12:17:39 +0100 Subject: [PATCH] fix nix-clean for MacOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- Makefile | 22 ++++++++++++++++++---- nix/clean.sh | 19 +++++++++++++++---- nix/shell.sh | 6 +++--- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index faca0da84a..da6a315234 100644 --- a/Makefile +++ b/Makefile @@ -32,14 +32,24 @@ ifndef BUILD_TAG export BUILD_TAG := $(shell git rev-parse --short HEAD) 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 export TMPDIR = /tmp/tmp-status-react-$(BUILD_TAG) # this has to be specified for both the Node.JS server process and the Qt process 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 #---------------- @@ -63,7 +73,7 @@ nix-clean: ##@nix Remove all status-react build artifacts from /nix/store nix-purge: SHELL := /bin/sh 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: ##@nix Add Nix GC roots to avoid status-react expressions being garbage collected @@ -253,6 +263,10 @@ endif # 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: ##@test Run tests once in NodeJS lein with-profile test doo node test once diff --git a/nix/clean.sh b/nix/clean.sh index eea2635a1a..f8f0cce05c 100755 --- a/nix/clean.sh +++ b/nix/clean.sh @@ -15,19 +15,30 @@ function findRelated() { path="${1}" found+=("${path}") if [[ "${path}" =~ .*.chroot ]]; then - log " ! Chroot: ${path}" - continue + 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}") + drv=$(getReferrers "${path}" | head -n1) src="${path}" elif [[ -f "${drv}" ]]; then src=$(getSources "${drv}") 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 " - Source: ${src}" found+=("${drv}" "${src}") diff --git a/nix/shell.sh b/nix/shell.sh index f2b7ea16a5..f1648d6fce 100755 --- a/nix/shell.sh +++ b/nix/shell.sh @@ -41,7 +41,7 @@ shellArgs=( if [[ -n "${TARGET_OS}" ]]; then shellArgs+=("--argstr target-os ${TARGET_OS}") 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 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. # It is just a special string, not a variable, and a marker to not use `--run`. 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} else # Not all builds are ready to be run in a pure environment @@ -78,6 +78,6 @@ else if [[ -n "${_NIX_KEEP}" ]]; then shellArgs+=("--keep ${_NIX_KEEP//;/ --keep }") 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} fi