2023-01-13 18:04:16 +00:00
name : Nix Installer
branding :
icon : 'box'
color : 'purple'
2023-01-13 20:09:36 +00:00
description : Install Nix
2023-01-13 18:04:16 +00:00
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
2023-01-24 16:17:18 +00:00
start-daemon :
2023-01-24 18:51:02 +00:00
description : "If the daemon should be started , requires `planner: linux-multi`"
2023-01-24 16:17:18 +00:00
required : false
init :
2023-01-24 18:51:02 +00:00
description : "The init system to configure, requires `planner: linux-multi` (allowing the choice between `none` or `systemd`)"
2023-01-24 16:17:18 +00:00
required : false
2023-01-13 18:04:16 +00:00
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`)
2023-01-24 17:29:24 +00:00
required : falseg
2023-01-13 18:04:16 +00:00
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 :
2023-01-24 16:51:23 +00:00
description : The tag of `nix-installer` to use (conflicts with `nix-installer-revision`, `nix-installer-branch`, `nix-installer-pr`)
2023-01-13 18:04:16 +00:00
required : false
nix-installer-revision :
2023-01-24 16:51:23 +00:00
description : The revision of `nix-installer` to use (conflicts with `nix-installer-tag`, `nix-installer-branch`, `nix-installer-pr`)
2023-01-13 18:04:16 +00:00
required : false
nix-installer-branch :
2023-01-24 16:51:23 +00:00
description : The branch of `nix-installer` to use (conflicts with `nix-installer-tag`, `nix-installer-revision`, `nix-installer-pr`)
required : false
nix-installer-pr :
description : The PR of `nix-installer` to use (conflicts with `nix-installer-tag`, `nix-installer-revision`, `nix-installer-branch`)
2023-01-13 18:04:16 +00:00
required : false
2023-01-13 20:09:36 +00:00
reinstall :
2023-01-16 17:35:30 +00:00
description : Force a reinstall if an existing installation is detected (consider backing up `/nix/store`)
2023-01-16 17:13:18 +00:00
required : false
2023-01-13 18:04:16 +00:00
runs :
using : composite
steps :
- name : Install Nix
shell : bash
run : |
2023-01-16 17:13:18 +00:00
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
2023-01-16 17:35:30 +00:00
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"
2023-01-16 17:13:18 +00:00
fi
if [ -n "${{ inputs.reinstall }}" ] && [ "${{ inputs.reinstall }}" == "true" ]; then
2023-01-13 20:09:36 +00:00
/nix/nix-installer uninstall --no-confirm
else
2023-01-16 17:13:18 +00:00
EXISTING_VERSION=$(/nix/nix-installer --version | awk '{ print $2 }')
if [ -n "${{ inputs.nix-installer-tag }}" ] && [ "${{ inputs.nix-installer-tag }}" != "$EXISTING_VERSION" ]; then
2023-01-16 17:35:30 +00:00
echo "`nix-installer` version mismatch, use `reinstall: true` to reinstall Nix using the new `nix-installer` version (consider backing up `/nix/store`)"
2023-01-16 17:13:18 +00:00
exit 1
fi
2023-01-13 20:09:36 +00:00
echo "Nix was already installed, using existing install"
2023-01-16 17:13:18 +00:00
echo "/nix/var/nix/profiles/default/bin" >> $GITHUB_PATH
2023-01-13 20:09:36 +00:00
exit 0
fi
fi
2023-01-13 18:04:16 +00:00
if [ -n "${{ inputs.nix-installer-tag }}" ]; then
2023-01-16 17:13:18 +00:00
export NIX_INSTALLER_TAG=${{ inputs.nix-installer-tag }}
2023-01-13 18:04:16 +00:00
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
2023-01-24 16:51:23 +00:00
if [ -n "${{ inputs.nix-installer-pr }}" ]; then
export NIX_INSTALLER_URL=https://install.determinate.systems/nix/pr/${{ inputs.nix-installer-pr }}
elif [ -n "${{ inputs.nix-installer-tag }}" ]; then
export NIX_INSTALLER_URL=https://install.determinate.systems/nix/tag/${{ inputs.nix-installer-tag }}
elif [ -n "${{ inputs.nix-installer-revision }}" ]; then
export NIX_INSTALLER_URL=https://install.determinate.systems/nix/rev/${{ inputs.nix-installer-revision }}
elif [ -n "${{ inputs.nix-installer-branch }}" ]; then
export NIX_INSTALLER_URL=https://install.determinate.systems/nix/branch/${{ inputs.nix-installer-branch }}
2023-01-13 18:16:26 +00:00
else
2023-01-13 18:04:16 +00:00
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
2023-01-24 16:17:18 +00:00
if [ -n "${{ inputs.init }}" ]; then
export NIX_INSTALLER_INIT=${{ inputs.init }}
echo "Set NIX_INSTALLER_INIT=$NIX_INSTALLER_INIT"
fi
if [ -n "${{ inputs.start-daemon }}" ]; then
export NIX_INSTALLER_START_DAEMON=${{ inputs.start-daemon }}
echo "Set NIX_INSTALLER_START_DAEMON=$NIX_INSTALLER_START_DAEMON"
fi
2023-01-13 18:04:16 +00:00
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