Optionally prevent relevant nix store paths from being GC'ed

[?]
Mar 24, 2023, 9:35 AM
WNFTZY3MQBNYY2V6XEI2DHZEZGRUMVWK23IN34YW3OISLSJHGFYQC

Dependencies

Change contents

  • edit in demo-full.sh at line 9
    [4.165][4.1:30](),[4.319][4.1:30](),[4.10][4.1:30](),[4.30][4.320:374](),[4.374][4.166:343]()
    echo "${BASH_SOURCE[0]}"
    ${shellcheck_cmd} "${BASH_SOURCE[0]}" || return 1
    echo "$(dirname "${BASH_SOURCE[0]}")/bash/nix-container-demo-helper.sh"
    ${shellcheck_cmd} "$(dirname "${BASH_SOURCE[0]}")/bash/nix-container-demo-helper.sh" || return 1
  • replacement in demo-full.sh at line 10
    [4.285][4.292:374]()
    for f in $(find "$(dirname "${BASH_SOURCE[0]}")" -name 'demo*.sh' | sort); do
    [4.285]
    [4.286]
    for f in $(find "$(dirname "${BASH_SOURCE[0]}")" -name '*.sh' | sort); do
  • edit in demo-full.sh at line 29
    [3.56][4.3:53](),[4.454][4.3:53](),[4.53][3.57:116]()
    echo " -l|--lint: run linter on shell files"
    echo " -a|--auto: run in automatic mode (no pausing)"
  • edit in demo-full.sh at line 30
    [4.579]
    [4.579]
    echo " -a|--auto: run in automatic mode (no pausing)"
    echo " -g|--gcroots: create Nix garbage collector roots for nix build/run/develop outputs"
    echo " -l|--lint: run linter on shell files"
  • edit in demo-full.sh at line 37
    [4.609]
    [4.609]
    do_nix_make_gcroots=0
  • replacement in demo-full.sh at line 41
    [4.648][4.648:685]()
    -l|--lint)
    do_lint=1
    [4.648]
    [4.685]
    -a|--auto)
    do_interactive=0
  • replacement in demo-full.sh at line 45
    [4.714][4.714:758]()
    -a|--auto)
    do_interactive=0
    [4.714]
    [4.758]
    -g|--gcroots)
    do_nix_make_gcroots=1
  • edit in demo-full.sh at line 52
    [4.841]
    [4.841]
    ;;
    -l|--lint)
    do_lint=1
    shift
  • replacement in demo-full.sh at line 62
    [4.938][4.938:994]()
    POSITIONAL_ARGS+=("$1") # save positional arg
    [4.938]
    [4.994]
    POSITIONAL_ARGS+=("$1")
  • replacement in demo-full.sh at line 71
    [4.1090][4.1090:1138]()
    LIBDEMO_INTERACTIVE="${do_interactive}" run
    [4.1090]
    [4.1138]
    WRAP_NIX_MAKE_GCROOTS="${do_nix_make_gcroots}" LIBDEMO_INTERACTIVE="${do_interactive}" run
  • edit in bash/nix-container-demo-helper.sh at line 35
    [2.503]
    [4.2183]
    }
    __nix_make_gcroot() {
    local -r storepath="${1}"
    echo "Preventing GC for '${storepath}'"
    local -r gcroot="/nix/var/nix/gcroots/per-user/${USER}/nix-container-demo-$(basename "${storepath}")"
    rm -f "${gcroot}"
    ln -s "${storepath}" "${gcroot}"
    }
    nix() {
    if [ "${WRAP_NIX_MAKE_GCROOTS:-0}" = 0 ]; then
    command nix "$@"
    else
    local -r action=$1
    shift
    local nix_args=()
    local args=()
    local __encountered_dashes=0
    while [ $# -gt 0 ]; do
    if [ "$1" == "--" ]; then
    __encountered_dashes=1
    elif [ "${__encountered_dashes}" = 1 ]; then
    args+=("$1")
    else
    nix_args+=("$1")
    fi
    shift
    done
    local storepath
    if [ "${action}" = run ]; then
    command nix run "${nix_args[@]}" -- "${args[@]}"
    for storepath in $(command nix build "${nix_args[@]}" --no-link --print-out-paths); do
    __nix_make_gcroot "${storepath}"
    done
    elif [ "${action}" = build ]; then
    command nix build "${nix_args[@]}"
    for storepath in $(command nix build "${nix_args[@]}" --no-link --print-out-paths); do
    __nix_make_gcroot "${storepath}"
    done
    elif [ "${action}" = develop ]; then
    # shellcheck disable=SC2016
    storepath="$(command nix develop "${nix_args[0]}" --command bash -c 'echo ${NIX_GCROOT}' 2>/dev/null)"
    __nix_make_gcroot "${storepath}"
    command nix develop "${nix_args[@]}"
    else
    command nix "${action}" "${nix_args[@]}"
    fi
    fi
  • replacement in README.md at line 50
    [3.1893][4.581:620](),[4.581][4.581:620](),[4.620][3.1894:1942](),[3.1942][4.655:682](),[4.655][4.655:682]()
    -l|--lint: run linter on shell files
    -a|--auto: run in automatic mode (no pausing)
    -h|--help|-?: Show usage
    [3.1893]
    [4.682]
    -h|--help|-?: Show usage"
    -a|--auto: run in automatic mode (no pausing)"
    -g|--gcroots: create Nix garbage collector roots for nix build/run/develop outputs"
    -l|--lint: run linter on shell files"
  • edit in README.md at line 56
    [4.687]
    [4.687]
    ⚠ The garbage collector roots are of the form `/nix/var/nix/gcroots/per-user/${USER}/nix-container-demo-*`, you may want to clean them if this demo changes.
  • edit in README.md at line 63
    [4.252]
    [4.1209]
    * `WRAP_NIX_MAKE_GCROOTS`: enable (1) or disable (0, default) creation of Nix garbage collector roots for nix build/run/develop outputs.
  • replacement in .gitlab-ci.yml at line 13
    [4.151][4.1104:1145]()
    - CLICOLOR_FORCE=1 ./demo-full.sh -a
    [4.127]
    [4.151]
    - export USER="$(whoami)"
    - rm -f /nix/var/nix/gcroots/per-user/${USER}/nix-container-demo-*
    - CLICOLOR_FORCE=1 ./demo-full.sh --auto --gcroots
    - ls -1dtr /nix/var/nix/gcroots/per-user/${USER}/nix-container-demo-*