Skip to content

Commit

Permalink
feat(nix)!: drop install support from hydra.nixos.org (#3358)
Browse files Browse the repository at this point in the history
- Closes #3333
  • Loading branch information
viceice committed Oct 1, 2024
1 parent 7ae4a7c commit 82f4e88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 42 deletions.
6 changes: 0 additions & 6 deletions docs/custom-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,6 @@ 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`

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:

Expand All @@ -361,8 +357,6 @@ https://github.com/containerbase/nix-prebuild/releases/2.24.2/node-2.24.2-x86_x6
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
```

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

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

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

arch=$(uname -m)
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
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
tool_path=$(create_tool_path)
checksum_file=$(get_from_url "${base_url}/${version}/${name}-${version}-${arch}.tar.xz.sha512")
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}"
}

function link_tool() {
Expand Down

0 comments on commit 82f4e88

Please sign in to comment.