Jakub Sokołowski de7ce0493b
nix: optimize garbage collection
In order to prevent `nix-store --gc` from removing too much I've:

- Added the `keep-outputs = true` setting to `nix/nix.conf`
- Fixed `nix/scripts/gcroots.sh` to make symlinks in `/nix/var/nix/gcroots`
- Made `nix/scripts/build.sh` and `nix/scripts/shell.sh` use it

This way when running `make nix-gc` most recently used shells and built
derivations won't be removed along with their dependencies.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2020-06-22 16:34:27 +02:00

22 lines
638 B
Bash
Executable File

#!/usr/bin/env bash
set -Eeu
_NIX_GCROOTS="${_NIX_GCROOTS:-/nix/var/nix/gcroots/per-user/${USER}/status-react}"
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/nix/scripts/source.sh"
source "${GIT_ROOT}/scripts/colors.sh"
TARGET="${1}"
if [[ -z "${TARGET}" ]]; then
echo -e "${RED}No target specified for gcroots.sh!${RST}" >&2
exit 1
fi
# Creates a symlink to derivation in _NIX_GCROOTS directory.
# This prevents it from being removed by 'gc-collect-garbage'.
nix-instantiate --attr "${TARGET}" \
--add-root "${_NIX_GCROOTS}/${TARGET}" \
"${GIT_ROOT}/default.nix" >/dev/null