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

feat(nix): use our own prebuilds #3087

Merged
merged 1 commit into from
Aug 9, 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
11 changes: 6 additions & 5 deletions docs/custom-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,21 @@ https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.3.

Nix releases are downloaded from:

- `https://github.com/containerbase/nix-prebuild/releases`
- `https://hydra.nixos.org/job/nix`
- `https://releases.nixos.org`

The second url will be used soon (#2066).

The second url is used as fallback for older versions.
Starting with `2.24`, the Hydra job name is `buildStatic.nix.${arch}`, instead of `buildStatic.${arch}`.

Samples:

```txt
https://github.com/containerbase/nix-prebuild/releases/2.24.2/node-2.24.2-x86_x64.tar.xz.sha512
https://github.com/containerbase/nix-prebuild/releases/2.24.2/node-2.24.2-aarch64.tar.xz
https://github.com/containerbase/nix-prebuild/releases/2.24.2/node-2.24.2-x86_x64.tar.xz.sha512
https://github.com/containerbase/nix-prebuild/releases/2.24.2/node-2.24.2-aarch64.tar.xz
https://hydra.nixos.org/job/nix/maintenance-2.24/buildStatic.nix.x86_64-linux/latest/download-by-type/file/binary-dist
https://hydra.nixos.org/job/nix/maintenance-2.4/buildStatic.x86_64-linux/latest/download-by-type/file/binary-dist
https://releases.nixos.org/nix/nix-2.2/nix-2.2-aarch64-linux.tar.bz2
https://releases.nixos.org/nix/nix-2.2/nix-2.2-aarch64-linux.tar.bz2.sha256
```

## `node`
Expand Down
51 changes: 35 additions & 16 deletions src/usr/local/containerbase/tools/v2/nix.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
#!/usr/bin/env bash

function check_tool_requirements() {
check_semver "$TOOL_VERSION" "minor"
TOOL_VERSION=${MAJOR}.${MINOR}
}

function install_tool() {
local versioned_tool_path
local file
local arch
local build_path
local name=${TOOL_NAME}
local tool_path
local version=${TOOL_VERSION}

# if [[ ${MAJOR} -lt 2 || (${MAJOR} -eq 2 && ${MINOR} -lt 14) ]]; then
# echo "Nix version ${TOOL_VERSION} is not supported! Use v2.14 or higher." >&2
# exit 1
# fi

arch=$(uname -m)

if [[ ${MAJOR} -lt 2 || (${MAJOR} -eq 2 && ${MINOR} -lt 24) ]]; then
build_path="buildStatic.${arch}-linux"
base_url="https://github.com/containerbase/${name}-prebuild/releases/download"

# not all releases have checksums
checksum_exists=$(file_exists "${base_url}/${version}/${name}-${version}-${arch}.tar.xz.sha512")
if [[ "${checksum_exists}" == "200" ]]; then
echo "Downloading ${name} ${version} for ${arch} from github ..."
tool_path=$(create_tool_path)
checksum_file=$(get_from_url "${base_url}/${version}/${name}-${version}-${arch}.tar.xz.sha512")
# get checksum from file
expected_checksum=$(cat "${checksum_file}")
file=$(get_from_url \
"${base_url}/${version}/${name}-${version}-${arch}.tar.xz" \
"${name}-${version}-${arch}.tar.xz" \
"${expected_checksum}" \
sha512sum
)

bsdtar -C "${tool_path}" -xf "${file}"
else
build_path="buildStatic.nix.${arch}-linux"
TOOL_VERSION="${MAJOR}.${MINOR}"
echo "Downloading ${name} ${version} for ${arch} from hydra ..."
if [[ ${MAJOR} -lt 2 || (${MAJOR} -eq 2 && ${MINOR} -lt 24) ]]; then
build_path="buildStatic.${arch}-linux"
else
build_path="buildStatic.nix.${arch}-linux"
fi

file=$(get_from_url "https://hydra.nixos.org/job/nix/maintenance-${TOOL_VERSION}/${build_path}/latest/download-by-type/file/binary-dist")

versioned_tool_path=$(create_versioned_tool_path)
create_folder "${versioned_tool_path}/bin"
cp "${file}" "${versioned_tool_path}/bin/nix"
chmod +x "${versioned_tool_path}/bin/nix"
fi

file=$(get_from_url "https://hydra.nixos.org/job/nix/maintenance-${TOOL_VERSION}/${build_path}/latest/download-by-type/file/binary-dist")

versioned_tool_path=$(create_versioned_tool_path)
create_folder "${versioned_tool_path}/bin"
cp "${file}" "${versioned_tool_path}/bin/nix"
chmod +x "${versioned_tool_path}/bin/nix"
}

function link_tool() {
Expand Down