From 3c9332283c6de81d04324f3b9f7050ce80e6d261 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Mon, 16 Jan 2023 09:13:18 -0800 Subject: [PATCH 1/2] Ensure we still set GITHUB_PATH Further improve logic --- action.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 86c5b70..074cee5 100644 --- a/action.yml +++ b/action.yml @@ -76,7 +76,8 @@ inputs: description: The branch of `nix-installer` to use required: false reinstall: - description: Force a reinstall if the + description: Force a reinstall if an existing installation is detected + required: false runs: using: composite @@ -84,18 +85,27 @@ runs: - name: Install Nix shell: bash run: | - if [ -f "/nix/receipt.json" ]; then - if [ -n "${{ inputs.reinstall }}" ]; then + if [ -f "/nix/receipt.json" ] && [ -f "/nix/nix-installer" ]; then + if ([ -n "${{ inputs.nix-installer-revision }}" ] || [ -n "${{ inputs.nix-installer-branch }}" ]) && [ "${{ inputs.reinstall }}" != "true" ]; then + echo "When `nix-installer-revision` or `nix-installer-branch` are set the detection of existing installs (and versions) may be unreliable, `reinstall: true` should also be set" + fi + + if [ -n "${{ inputs.reinstall }}" ] && [ "${{ inputs.reinstall }}" == "true" ]; then /nix/nix-installer uninstall --no-confirm else + EXISTING_VERSION=$(/nix/nix-installer --version | awk '{ print $2 }') + if [ -n "${{ inputs.nix-installer-tag }}" ] && [ "${{ inputs.nix-installer-tag }}" != "$EXISTING_VERSION" ]; then + echo "`nix-installer` version mismatch, if attempting to upgrade to a new tag, use `reinstall: true`, you may want to back up your `/nix/store` first" + exit 1 + fi echo "Nix was already installed, using existing install" + echo "/nix/var/nix/profiles/default/bin" >> $GITHUB_PATH exit 0 fi - fi if [ -n "${{ inputs.nix-installer-tag }}" ]; then - export NIX_INSTALLER_TAG=${{ inputs.tag }} + export NIX_INSTALLER_TAG=${{ inputs.nix-installer-tag }} echo "Set NIX_INSTALLER_TAG=$NIX_INSTALLER_TAG" fi From 78b28a0bb705e7c84d5925e5b0713f6e857d08d3 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Mon, 16 Jan 2023 09:35:30 -0800 Subject: [PATCH 2/2] Clean up wording --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 074cee5..59d260e 100644 --- a/action.yml +++ b/action.yml @@ -76,7 +76,7 @@ inputs: description: The branch of `nix-installer` to use required: false reinstall: - description: Force a reinstall if an existing installation is detected + description: Force a reinstall if an existing installation is detected (consider backing up `/nix/store`) required: false runs: @@ -87,7 +87,7 @@ runs: run: | if [ -f "/nix/receipt.json" ] && [ -f "/nix/nix-installer" ]; then if ([ -n "${{ inputs.nix-installer-revision }}" ] || [ -n "${{ inputs.nix-installer-branch }}" ]) && [ "${{ inputs.reinstall }}" != "true" ]; then - echo "When `nix-installer-revision` or `nix-installer-branch` are set the detection of existing installs (and versions) may be unreliable, `reinstall: true` should also be set" + echo "Detection of existing installation versions isn't supported when `nix-installer-revision` or `nix-installer-branch` are set, `reinstall: true` should also be set" fi if [ -n "${{ inputs.reinstall }}" ] && [ "${{ inputs.reinstall }}" == "true" ]; then @@ -95,7 +95,7 @@ runs: else EXISTING_VERSION=$(/nix/nix-installer --version | awk '{ print $2 }') if [ -n "${{ inputs.nix-installer-tag }}" ] && [ "${{ inputs.nix-installer-tag }}" != "$EXISTING_VERSION" ]; then - echo "`nix-installer` version mismatch, if attempting to upgrade to a new tag, use `reinstall: true`, you may want to back up your `/nix/store` first" + echo "`nix-installer` version mismatch, use `reinstall: true` to reinstall Nix using the new `nix-installer` version (consider backing up `/nix/store`)" exit 1 fi echo "Nix was already installed, using existing install"