Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Make nix available in the container #187

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,23 @@ ENV GIMME_GO_VERSION "1.10"
ENV GIMME_ENV_PREFIX "/opt/buildhome/.gimme/env"
RUN gimme

################################################################################
#
# Nix
#
################################################################################
USER root
RUN mkdir -m 0755 /nix && chown buildbot /nix

USER buildbot
WORKDIR /tmp
RUN curl -o install-nix https://nixos.org/nix/install && USER=buildbot sh ./install-nix && rm install-nix
RUN mkdir -p /opt/buildhome/.nix/bin

ENV PATH=/opt/buildhome/.nix/bin:$PATH
ENV NIX_PATH=/nix/var/nix/profiles/per-user/buildbot/channels
ENV NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

# Cleanup
USER root

Expand Down
21 changes: 19 additions & 2 deletions run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ install_dependencies() {
fi

if nvm install $NODE_VERSION
then
then
NODE_VERSION=$(nvm current)
# no echo needed because nvm does that for us
export NODE_VERSION=$NODE_VERSION
Expand Down Expand Up @@ -276,7 +276,7 @@ install_dependencies() {
exit 1
fi
fi

if ! gem list -i "^bundler$" > /dev/null 2>&1
then
if ! gem install bundler
Expand Down Expand Up @@ -607,6 +607,23 @@ install_missing_commands() {
export PATH=$(npm bin):$PATH
fi
fi

# Create wrappers around nix / nix-build that divert the store to the cache
# directory. This must be done at runtime and can not be baked into the
# docker image because it depends on NETLIFY_CACHE_DIR which is available
# only during execution.
#
# Furthermore, these commands must be provided to the user command as normal
# executables. I'd love to just make wrapper functions in the shell but anything
# that's defined in this file is *not* available to the user command.

echo '#!/bin/sh
CMD=$1;shift;exec /nix/var/nix/profiles/per-user/buildbot/profile/bin/nix $CMD --store '$NETLIFY_CACHE_DIR' "$@"
' > $HOME/.nix/bin/nix
echo '#!/bin/sh
exec /nix/var/nix/profiles/per-user/buildbot/profile/bin/nix-build --store '$NETLIFY_CACHE_DIR' "$$@"
' > $HOME/.nix/bin/nix-build
chmod +x $HOME/.nix/bin/nix $HOME/.nix/bin/nix-build
}

set_go_import_path() {
Expand Down