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

Commit

Permalink
Create wrappers around nix / nix-build that divert the store to the n…
Browse files Browse the repository at this point in the history
…etlify cache directory
  • Loading branch information
wereHamster committed Aug 14, 2018
1 parent 4b4993a commit e8e4604
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,10 @@ 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=/nix/var/nix/profiles/per-user/$USER/profile/bin:/nix/var/nix/profiles/per-user/$USER/profile/sbin:$PATH
ENV NIX_PATH=/nix/var/nix/profiles/per-user/$USER/channels
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
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

0 comments on commit e8e4604

Please sign in to comment.