Skip to content
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
44 changes: 0 additions & 44 deletions src/usr/local/buildpack/tools/nix.sh

This file was deleted.

29 changes: 29 additions & 0 deletions src/usr/local/buildpack/tools/v2/nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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

versioned_tool_path=$(create_versioned_tool_path)
ARCH=$(uname -m)

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

create_folder "${versioned_tool_path}/bin"
cp "${file}" "${versioned_tool_path}/bin/nix"
chmod +x "${versioned_tool_path}/bin/nix"
}

function link_tool() {
local versioned_tool_path
versioned_tool_path=$(find_versioned_tool_path)

shell_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin"
nix --version
}
4 changes: 2 additions & 2 deletions test/Dockerfile.bionic
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ RUN install-tool java 17.0.5+8
# renovate: datasource=gradle-version packageName=gradle versioning=gradle
RUN install-tool gradle 7.5.1

# renovate: datasource=github-releases packageName=NixOS/nix
RUN install-tool nix 2.3.10
# renovate: datasource=github-tags packageName=NixOS/nix
RUN install-tool nix 2.11.1

# renovate: datasource=node
RUN install-tool node v16.18.0
Expand Down
4 changes: 2 additions & 2 deletions test/Dockerfile.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ RUN install-tool java 17.0.5+8
# renovate: datasource=gradle-version packageName=gradle versioning=gradle
RUN install-tool gradle 7.5.1

# renovate: datasource=github-releases packageName=NixOS/nix
RUN install-tool nix 2.3.10
# renovate: datasource=github-tags packageName=NixOS/nix
RUN install-tool nix 2.11.1

# renovate: datasource=node
RUN install-tool node v18.12.0
Expand Down
157 changes: 157 additions & 0 deletions test/bash/tools/nix.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
setup_file() {
export TEST_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)"

# set up the cache
load "$TEST_DIR/../cache.sh"
export BUILDPACK_CACHE_DIR="$(create_temp_dir TEST_CACHE_DIR)"
}

setup() {
load '../../../node_modules/bats-support/load'
load '../../../node_modules/bats-assert/load'

TEST_ROOT_DIR=$(mktemp -u)
USER_NAME=testuser

load "$TEST_DIR/../../../src/usr/local/buildpack/util.sh"

# load v2 overwrites
load "$TEST_DIR/../../../src/usr/local/buildpack/utils/v2/overrides.sh"

# load test overwrites
load "$TEST_DIR/../util.sh"

setup_directories

# set default test user
TEST_ROOT_USER=1000

# load nix
load "$TEST_DIR/../../../src/usr/local/buildpack/tools/v2/nix.sh"

}

teardown() {
rm -rf "${TEST_ROOT_DIR}"
}

teardown_file() {
clean_temp_dir $BUILDPACK_CACHE_DIR TEST_CACHE_DIR
}

@test "nix: check_tool_requirements" {
TOOL_NAME=nix

TOOL_VERSION=foobar \
run check_tool_requirements
assert_failure

TOOL_VERSION=2.11 \
run check_tool_requirements
assert_success
}

@test "nix: check_tool_installed" {
local TOOL_NAME=nix
local TOOL_VERSION

# renovate: datasource=github-tags packageName=NixOS/nix
TOOL_VERSION=2.11.1

run check_tool_installed
assert_failure

check_tool_requirements

run install_tool
assert_success

run check_tool_installed
assert_success
}

@test "nix: install_tool" {
local TOOL_NAME=nix
local TOOL_VERSION

# renovate: datasource=github-tags packageName=NixOS/nix
TOOL_VERSION=2.11.1

check_tool_requirements

run install_tool
assert_success

local versioned_tool_path=$(find_versioned_tool_path)

PATH="${versioned_tool_path}/bin" \
run nix --version
assert_success
assert_output --partial "${TOOL_VERSION}"

# don't update
TOOL_VERSION=2.10.3

check_tool_requirements

run install_tool
assert_success

local versioned_tool_path=$(find_versioned_tool_path)

PATH="${versioned_tool_path}/bin" \
run nix --version
assert_success
assert_output --partial "${TOOL_VERSION}"
}

@test "nix: link_tool" {
local TOOL_NAME=nix
local TOOL_VERSION
local bin_path=$(get_bin_path)

# renovate: datasource=github-tags packageName=NixOS/nix
TOOL_VERSION=2.11.1

check_tool_requirements

run install_tool
assert_success

PATH="${bin_path}:$PATH" \
run link_tool
assert_success
assert_output --partial "${TOOL_VERSION}"

PATH="${bin_path}" \
run nix --version
assert_success
assert_output --partial "${TOOL_VERSION}"

local versioned_tool_path=$(find_versioned_tool_path)

PATH="${versioned_tool_path}/bin" \
run nix --version
assert_success
assert_output --partial "${TOOL_VERSION}"

# don't update
TOOL_VERSION=2.11.1

check_tool_requirements

run install_tool
assert_success

PATH="${bin_path}:$PATH" \
run link_tool
assert_success
assert_output --partial "${TOOL_VERSION}"

local versioned_tool_path=$(find_versioned_tool_path)

PATH="${versioned_tool_path}/bin" \
run nix --version
assert_success
assert_output --partial "${TOOL_VERSION}"
}
62 changes: 59 additions & 3 deletions test/nix/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build
FROM ${IMAGE} as base

RUN touch /.dummy

COPY --chown=1000:0 test test

WORKDIR /test

#--------------------------------------
# test: nix 2.10
#--------------------------------------
FROM base as testa

ARG APT_HTTP_PROXY

# old nix version, not for renovating
RUN install-tool nix 2.11.1

USER 1000

RUN set -ex; \
nix --version

RUN set -ex; \
cd a; \
nix \
--extra-experimental-features nix-command \
--extra-experimental-features flakes \
eval --impure --expr '{example = import ./flake.nix;}'

RUN set -ex; \
cd a; \
nix \
--extra-experimental-features nix-command \
--extra-experimental-features flakes \
flake update

#--------------------------------------
# test: nix 2.11
#--------------------------------------
FROM base as testb

ARG APT_HTTP_PROXY

Expand All @@ -12,7 +52,23 @@ RUN set -ex; \
nix --version

RUN set -ex; \
nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
cd a; \
nix \
--extra-experimental-features nix-command \
--extra-experimental-features flakes \
eval --impure --expr '{example = import ./flake.nix;}'

RUN set -ex; \
nix-instantiate --eval -E 'with import <nixpkgs> {}; glibc.version'
cd a; \
nix \
--extra-experimental-features nix-command \
--extra-experimental-features flakes \
flake update

#--------------------------------------
# final
#--------------------------------------
FROM base

COPY --from=testa /.dummy /.dummy
COPY --from=testb /.dummy /.dummy
27 changes: 27 additions & 0 deletions test/nix/test/a/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions test/nix/test/a/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
description = "update-flake-lock";

inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

outputs =
{ self
, nixpkgs
}:
let
nameValuePair = name: value: { inherit name value; };
genAttrs = names: f: builtins.listToAttrs (map (n: nameValuePair n (f n)) names);

allSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: genAttrs allSystems
(system: f {
inherit system;
pkgs = import nixpkgs { inherit system; };
});
in
{
devShell = forAllSystems
({ system, pkgs, ... }:
pkgs.stdenv.mkDerivation {
name = "update-flake-lock-devshell";
buildInputs = [ pkgs.shellcheck ];
src = self;
});
};
}