Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add nix 2.25.3 (installer 0.32.1) #1

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on: push
jobs:
test:
strategy:
matrix:
os:
- macos-13
- macos-14
- macos-15
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-24.04
runs-on: ${{ matrix.os }}
steps:
- uses: actions/[email protected]
- run: ./test.sh
13 changes: 13 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

set -o errexit
set -o nounset

export IS_RUNHUB_TEST="${IS_RUNHUB_TEST:-no}"

runhub_dir="$(dirname "$0")"
scripts_dir="${runhub_dir}"/scripts

. "${scripts_dir}"/run-nix-daemon.sh
"${scripts_dir}"/install-upgrade-nix.sh
. "${scripts_dir}"/run-nix-daemon.sh
13 changes: 13 additions & 0 deletions scripts/confirm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

set -o errexit
set -o nounset

printf '%s ([Y]es/[n]o): ' "$1"

if [ "${IS_RUNHUB_TEST}" = 'no' ]; then
IFS= read -r yes_no
echo "${yes_no}" | grep -Eqi '^$|^y(es)?$'
else
echo
fi
77 changes: 77 additions & 0 deletions scripts/install-upgrade-nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh

set -o errexit
set -o nounset

if [ "${IS_RUNHUB_TEST}" = 'no' ]; then
set -o monitor
fi

scripts_dir="$(dirname "$0")"

minimum_required_version='2.25.3'
minimum_required_installer_version='0.32.1'

get_installed_version() {
installed_version_stdout="$(nix --version)"
echo "${installed_version_stdout}" | sed -n -e 's/^nix (Nix) \(.*\)$/\1/p'
}

get_installed_installer_version() {
installed_installer_version_stdout="$(/nix/nix-installer --version)"
echo "${installed_installer_version_stdout}" | sed -n -e 's/^nix-installer \(.*\)$/\1/p'
}

is_installed_upgraded() {
if command -v nix >/dev/null; then
installed_version="$(get_installed_version)"
is_upgraded="$("${scripts_dir}"/is-version-greater-equal.sh \
"${installed_version}" "${minimum_required_version}")"

if [ "${is_upgraded}" = 'yes' ]; then
if command -v /nix/nix-installer >/dev/null; then
installed_installer_version="$(get_installed_installer_version)"
"${scripts_dir}"/is-version-greater-equal.sh \
"${installed_installer_version}" "${minimum_required_installer_version}"
else
echo 'yes'
fi
else
echo 'no'
fi
else
echo 'no'
fi
}

install_upgrade() {
if command -v /nix/nix-installer >/dev/null; then
installed_installer_version="$(get_installed_installer_version)"
/nix/nix-installer split-receipt --no-confirm
/nix/nix-installer uninstall /nix/uninstall-phase1.json --no-confirm
fi

installer_install_script="$(curl --proto '=https' --tlsv1.2 -sSf -L \
https://install.determinate.systems/nix/tag/v"${minimum_required_installer_version}")"
echo "${installer_install_script}" | sh -s -- install --no-confirm
}

main() {
. "${scripts_dir}"/run-nix-daemon.sh
is_installed_upgraded="$(is_installed_upgraded)"

if [ "${is_installed_upgraded}" = 'no' ]; then
"${scripts_dir}"/confirm.sh \
'Install/Upgrade Nix v'"${minimum_required_version}"' with Determinate Nix Installer v'"${minimum_required_installer_version}"'?'
install_upgrade
. "${scripts_dir}"/run-nix-daemon.sh
was_installed_upgraded="$(is_installed_upgraded)"

if [ "${was_installed_upgraded}" = 'no' ]; then
echo 'Nix v'"${minimum_required_version}"' or higher is required.'
exit 1
fi
fi
}

main "$@"
38 changes: 38 additions & 0 deletions scripts/is-version-greater-equal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

set -o errexit
set -o nounset

is_version() {
echo "$1" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'
}

get_version_part() {
echo "$1" | cut -f "${version_part_index}" -d '.'
}

main() {
is_version "$1"
is_version "$2"

version_part_index=1
while [ "${version_part_index}" -le 3 ]; do
version_1_part="$(get_version_part "$1" "${version_part_index}")"
version_2_part="$(get_version_part "$2" "${version_part_index}")"

if [ "${version_1_part}" -gt "${version_2_part}" ]; then
break
fi

if [ "${version_1_part}" -lt "${version_2_part}" ]; then
echo 'no'
exit
fi

version_part_index="$((version_part_index + 1))"
done

echo 'yes'
}

main "$@"
10 changes: 10 additions & 0 deletions scripts/run-nix-daemon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -o errexit
set -o nounset

nix_daemon_script='/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'

if ! command -v nix >/dev/null && [ -e "${nix_daemon_script}" ]; then
. "${nix_daemon_script}"
fi
10 changes: 10 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -o errexit
set -o nounset

export IS_RUNHUB_TEST='yes'

runhub_dir="$(dirname "$0")"

"${runhub_dir}"/dev.sh