lix-install-action/action.yml
2023-01-13 10:16:26 -08:00

237 lines
9.7 KiB
YAML

name: Nix Installer
branding:
icon: 'box'
color: 'purple'
description: An experimental Nix installer using `nix-install`
inputs:
planner:
description: A planner to use
required: false
extra-args:
description: Extra args to pass to the planner (prefer using structured `with:` arguments unless using a custom planner!)
required: false
github-token:
description: A Github Token so that authenticated requests can be made (set this to `secrets.GITHUB_TOKEN`)
channels:
description: Channel(s) to add (eg `nixpkgs=https://nixos.org/channels/nixpkgs-unstable`)
required: false
modify-profile:
description: Modify the user profile to automatically load nix
required: false
nix-build-user-count:
description: Number of build users to create
required: false
nix-build-group-name:
description: The Nix build group name
required: false
nix-build-group-id:
description: The Nix build group GID
required: false
nix-build-user-prefix:
description: The Nix build user prefix (user numbers will be postfixed)
required: false
nix-build-user-base:
description: The Nix build user base UID (ascending)
required: false
nix-package-url:
description: The Nix package URL
required: false
extra-conf:
description: Extra configuration lines for `/etc/nix.conf` (includes `access-tokens` with `secrets.GITHUB_TOKEN` automatically if `github-token` is set)
required: false
mac-encrypt:
description: Force encryption on the volume (Mac only)
required: false
mac-case-sensitive:
description: Use a case sensitive volume (Mac only)
required: false
mac-volume-label:
description: The label for the created APFS volume (Mac only)
required: false
mac-root-disk:
description: The root disk of the target (Mac only)
required: false
nix-installer-url:
description: A URL pointing to a `nix-installer.sh` script
required: false
logger:
description: The logger to use for install (eg. `pretty`, `json`, `full`, `compact`)
required: false
local-root:
description: A local `nix-installer` binary root, overrides the `nix-installer-url` setting (a `nix-installer.sh` should exist, binaries should be named `nix-installer-$ARCH`, eg. `nix-installer-x86_64-linux`)
required: false
log-directives:
description: A list of Tracing directives, comma separated, `-`s replaced with `_` (eg. `nix_installer=trace`, see https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives)
required: false
backtrace:
description: The setting for `RUST_BACKTRACE` (see https://doc.rust-lang.org/std/backtrace/index.html#environment-variables)
required: false
nix-installer-tag:
description: The tag of `nix-installer` to use
required: false
nix-installer-revision:
description: The revision of `nix-installer` to use
required: false
nix-installer-branch:
description: The branch of `nix-installer` to use
required: false
runs:
using: composite
steps:
- name: Install Nix
shell: bash
run: |
if [ -n "${{ inputs.nix-installer-tag }}" ]; then
export NIX_INSTALLER_TAG=${{ inputs.tag }}
echo "Set NIX_INSTALLER_TAG=$NIX_INSTALLER_TAG"
fi
if [ -n "${{ inputs.nix-installer-revision }}" ]; then
export NIX_INSTALLER_TAG=${{ inputs.nix-installer-revision }}
echo "Set NIX_INSTALLER_TAG=$NIX_INSTALLER_TAG"
fi
if [ -n "${{ inputs.nix-installer-branch }}" ]; then
export NIX_INSTALLER_BRANCH=${{ inputs.nix-installer-branch }}
echo "Set NIX_INSTALLER_BRANCH=$NIX_INSTALLER_BRANCH"
fi
if [ -n "${{ inputs.channels }}" ]; then
export NIX_INSTALLER_CHANNELS=${{ inputs.channels }}
echo "Set NIX_INSTALLER_CHANNELS=$NIX_INSTALLER_CHANNELS"
fi
if [ -n "${{ inputs.modify-profile }}" ]; then
export NIX_INSTALLER_MODIFY_PROFILE=${{ inputs.modify-profile }}
echo "Set NIX_INSTALLER_MODIFY_PROFILE=$NIX_INSTALLER_MODIFY_PROFILE"
fi
if [ -n "${{ inputs.daemon-user-count }}" ]; then
export NIX_INSTALLER_NIX_BUILD_USER_COUNT=${{ inputs.nix-build-user-count }}
echo "Set NIX_INSTALLER_NIX_BUILD_USER_COUNT=$NIX_INSTALLER_NIX_BUILD_USER_COUNT"
fi
if [ -n "${{ inputs.nix-build-group-name }}" ]; then
export NIX_INSTALLER_NIX_BUILD_GROUP_NAME=${{ inputs.nix-build-group-name }}
echo "Set NIX_INSTALLER_NIX_BUILD_GROUP_NAME=$NIX_INSTALLER_NIX_BUILD_GROUP_NAME"
fi
if [ -n "${{ inputs.nix-build-group-id }}" ]; then
export NIX_INSTALLER_NIX_BUILD_GROUP_ID=${{ inputs.nix-build-group-id }}
echo "Set NIX_INSTALLER_NIX_BUILD_GROUP_ID=$NIX_INSTALLER_NIX_BUILD_GROUP_ID"
fi
if [ -n "${{ inputs.nix-build-user-prefix }}" ]; then
export NIX_INSTALLER_NIX_BUILD_USER_ID_BASE=${{ inputs.nix-build-user-prefix }}
echo "Set NIX_INSTALLER_NIX_BUILD_USER_ID_BASE=$NIX_INSTALLER_NIX_BUILD_USER_ID_BASE"
fi
if [ -n "${{ inputs.nix-build-user-base }}" ]; then
export NIX_INSTALLER_NIX_BUILD_USER_PREFIX=${{ inputs.nix-build-user-base }}
echo "Set NIX_INSTALLER_NIX_BUILD_USER_PREFIX=$NIX_INSTALLER_NIX_BUILD_USER_PREFIX"
fi
if [ -n "${{ inputs.nix-package-url }}" ]; then
export NIX_INSTALLER_NIX_PACKAGE_URL=${{ inputs.nix-package-url }}
echo "Set NIX_INSTALLER_NIX_PACKAGE_URL=$NIX_INSTALLER_NIX_PACKAGE_URL"
fi
if [ -n "${{ inputs.extra-conf }}" ]; then
if [ -n "${{ inputs.github-token }}" ]; then
export NIX_INSTALLER_EXTRA_CONF="${{ inputs.extra-conf }}access-tokens = github.com=${{ inputs.github-token }}"
else
export NIX_INSTALLER_EXTRA_CONF="${{ inputs.extra-conf }}"
fi
echo "Set NIX_INSTALLER_EXTRA_CONF=$NIX_INSTALLER_EXTRA_CONF"
else
if [ -n "${{ inputs.github-token }}" ]; then
export NIX_INSTALLER_EXTRA_CONF="access-tokens = github.com=${{ inputs.github-token }}"
echo "Set NIX_INSTALLER_EXTRA_CONF=$NIX_INSTALLER_EXTRA_CONF"
fi
fi
if [ -n "${{ inputs.mac-encrypt }}" ]; then
export NIX_INSTALLER_ENCRYPT=${{ inputs.mac-encrypt }}
echo "Set NIX_INSTALLER_ENCRYPT=$NIX_INSTALLER_ENCRYPT"
fi
if [ -n "${{ inputs.mac-case-sensitive }}" ]; then
export NIX_INSTALLER_CASE_SENSITIVE=${{ inputs.mac-case-sensitive }}
echo "Set NIX_INSTALLER_CASE_SENSITIVE=$NIX_INSTALLER_CASE_SENSITIVE"
fi
if [ -n "${{ inputs.mac-volume-label }}" ]; then
export NIX_INSTALLER_VOLUME_LABEL=${{ inputs.mac-volume-label }}
echo "Set NIX_INSTALLER_VOLUME_LABEL=$NIX_INSTALLER_VOLUME_LABEL"
fi
if [ -n "${{ inputs.mac-root-disk }}" ]; then
export NIX_INSTALLER_ROOT_DISK=${{ inputs.mac-root-disk }}
echo "Set NIX_INSTALLER_ROOT_DISK=$NIX_INSTALLER_ROOT_DISK"
fi
if [ -n "${{ inputs.local-root }}" ]; then
if [ "$RUNNER_OS" == "macOS" ]; then
export PYTHON="python3"
else
export PYTHON="python"
fi
$PYTHON -m http.server --directory ${{ inputs.local-root }} --bind 0.0.0.0 8000 &
export HTTP_PID=$!
echo "Started simple http server for ${{ inputs.local-root }} on 0.0.0.0:8000"
while (! (: </dev/tcp/localhost/8000) &> /dev/null); do
sleep 1
done
export NIX_INSTALLER_FORCE_ALLOW_HTTP="1"
echo "Set NIX_INSTALLER_FORCE_ALLOW_HTTP=$NIX_INSTALLER_FORCE_ALLOW_HTTP"
export NIX_INSTALLER_URL=0.0.0.0:8000/nix-installer.sh
echo "Set NIX_INSTALLER_URL=$NIX_INSTALLER_URL"
export NIX_INSTALLER_BINARY_ROOT=http://0.0.0.0:8000/
echo "Set NIX_INSTALLER_BINARY_ROOT=$NIX_INSTALLER_BINARY_ROOT"
export NIX_INSTALLER_FORCE_ALLOW_HTTP=1
echo "Set NIX_INSTALLER_FORCE_ALLOW_HTTP=$NIX_INSTALLER_FORCE_ALLOW_HTTP"
else
if [ -n "${{ inputs.nix-installer-url }}" ]; then
export NIX_INSTALLER_URL=${{ inputs.nix-installer-url }}
else
if [ -n "$NIX_INSTALLER_TAG" ]; then
export NIX_INSTALLER_URL=https://install.determinate.systems/nix/tag/$NIX_INSTALLER_TAG
elif [ -n "$NIX_INSTALLER_REVISION" ]; then
export NIX_INSTALLER_URL=https://install.determinate.systems/nix/rev/$NIX_INSTALLER_REVISION
elif [ -n "$NIX_INSTALLER_REVISION" ]; then
export NIX_INSTALLER_URL=https://install.determinate.systems/nix/branch/$NIX_INSTALLER_BRANCH
else
export NIX_INSTALLER_URL=https://install.determinate.systems/nix
fi
fi
echo "Set NIX_INSTALLER_URL=$NIX_INSTALLER_URL"
fi
if [ -n "${{ inputs.logger }}" ]; then
export NIX_INSTALLER_LOGGER=${{ inputs.logger }}
echo "Set NIX_INSTALLER_LOGGER=$NIX_INSTALLER_LOGGER"
fi
if [ -n "${{ inputs.log-directives }}" ]; then
export NIX_INSTALLER_LOG_DIRECTIVES=${{ inputs.log-directives }}
echo "Set NIX_INSTALLER_LOG_DIRECTIVES=$NIX_INSTALLER_LOG_DIRECTIVES"
fi
if [ -n "${{ inputs.backtrace }}" ]; then
export RUST_BACKTRACE=${{ inputs.backtrace }}
echo "Set RUST_BACKTRACE=$RUST_BACKTRACE"
fi
export NIX_INSTALLER_NO_CONFIRM=true
echo "Set NIX_INSTALLER_NO_CONFIRM=$NIX_INSTALLER_NO_CONFIRM"
curl --retry 20 -L $NIX_INSTALLER_URL | sh -s -- install ${{ inputs.planner }} ${{ inputs.extra-args }}
if [ -n "$HTTP_PID" ]; then
kill $HTTP_PID
fi