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: add nix #18

Merged
merged 2 commits into from
Apr 7, 2021
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
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
golang,
java,
helm,
nix,
node,
php,
powershell,
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile.bionic
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ RUN install-tool java 11
# renovate: datasource=gradle-version lookupName=gradle versioning=gradle
RUN install-tool gradle 6.8.3

# renovate: datasource=github-releases lookupName=NixOS/nix
RUN install-tool nix 2.3.10

# renovate: datasource=docker versioning=docker
RUN install-tool node 14.16.0
# renovate: datasource=npm
Expand Down
43 changes: 43 additions & 0 deletions src/usr/local/buildpack/tools/nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -e

require_root
check_semver ${TOOL_VERSION}

if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then
echo Invalid version: ${TOOL_VERSION}
exit 1
fi

echo "max-jobs = auto" | tee -a /tmp/nix.conf >/dev/null
echo "trusted-users = root ${USER_NAME}" | tee -a /tmp/nix.conf >/dev/null

installer_options=(
--nix-extra-conf-file /tmp/nixd.conf
)

curl -sSL https://nixos.org/releases/nix/nix-$TOOL_VERSION/nix-$TOOL_VERSION-x86_64-linux.tar.xz --output nix.txz
tar xJf nix.txz
rm nix.txz

mkdir -m 0755 /etc/nix
chown -R ${USER_ID} /etc/nix
echo "sandbox = false" > /etc/nix/nix.conf

mkdir -m 0755 /nix
chown -R ${USER_ID} /nix

su ${USER_NAME} -c '"./nix-${TOOL_VERSION}-x86_64-linux/install" "${installer_options[@]}"'
ln -s /nix/var/nix/profiles/default/etc/profile.d/nix.sh /etc/profile.d/

rm -r nix-${TOOL_VERSION}-x86_64-linux*

export_path "/home/${USER_NAME}/.nix-profile/bin"
export_env NIX_PATH /nix/var/nix/profiles/per-user/${USER_NAME}/channels

nix-collect-garbage --delete-old
nix-store --optimise
nix-store --verify --check-contents

nix --version
16 changes: 16 additions & 0 deletions test/nix/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build

# renovate: datasource=github-releases lookupName=NixOS/nix
RUN install-tool nix 2.3.10

USER 1000

RUN set -ex; \
nix --version

RUN set -ex; \
nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'

RUN set -ex; \
nix-instantiate --eval -E 'with import <nixpkgs> {}; glibc.version'