Skip to content

Commit

Permalink
Add Guix buildpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Lecomte committed Jun 21, 2021
1 parent 73ab48a commit 074a5e3
Show file tree
Hide file tree
Showing 20 changed files with 773 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/source/config_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,27 @@ to produce a reproducible environment.
To see an example repository visit
`nix binder example <https://github.com/binder-examples/nix>`_.

.. _manifest.scm:

``manifest.scm`` - the Guix package manager
===========================================

Specify packages to be installed by the `Guix package manager <https://guix.gnu.org/>`_.
All packages specified in |manifest|_ will be installed in a container using |guix_package|_. In addition, you can use different `channels <https://guix.gnu.org/manual/en/html_node/Channels.html>`_ rather
than the ones available by default (official channels of GNU Guix 1.3.0).
You must describe such channels in a ``channels.scm`` file which will be used
alongside ``manifest.scm`` with the |guix_time-machine|_ command. Furthermore, using a ``channels.scm`` file lets you `pin a specific revision <https://guix.gnu.org/manual/en/html_node/Replicating-Guix.html>`_ of Guix, allowing you to unambiguously specific the software environment to reproduce.

For more information about Guix please read the `manual <https://guix.gnu.org/manual/en/guix.html>`_.

.. |manifest| replace:: ``manifest.scm``
.. _manifest: https://guix.gnu.org/manual/en/html_node/Invoking-guix-package.html#index-profile-manifesthy

.. |guix_package| replace:: ``guix package``
.. _guix_package: https://guix.gnu.org/manual/en/html_node/Invoking-guix-package.html#Invoking-guix-package

.. |guix_time-machine| replace:: ``guix time-machine``
.. _guix_time-machine: https://guix.gnu.org/manual/en/html_node/Invoking-guix-time_002dmachine.html

``Dockerfile`` - Advanced environments
======================================
Expand Down
2 changes: 2 additions & 0 deletions repo2docker/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
PipfileBuildPack,
PythonBuildPack,
RBuildPack,
GuixBuildPack,
)
from . import contentproviders
from .utils import ByteSpecification, chdir
Expand Down Expand Up @@ -99,6 +100,7 @@ def _default_log_level(self):
CondaBuildPack,
PipfileBuildPack,
PythonBuildPack,
GuixBuildPack,
],
config=True,
help="""
Expand Down
1 change: 1 addition & 0 deletions repo2docker/buildpacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from .legacy import LegacyBinderDockerBuildPack
from .r import RBuildPack
from .nix import NixBuildPack
from .guix import GuixBuildPack
1 change: 1 addition & 0 deletions repo2docker/buildpacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,4 @@ def get_start_script(self):
# the only path evaluated at container start time rather than build time
return os.path.join("${REPO_DIR}", start)
return None

74 changes: 74 additions & 0 deletions repo2docker/buildpacks/guix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""BuildPack for guix environments"""
import os

from ..base import BuildPack, BaseImage


class GuixBuildPack(BaseImage):
"""A guix Package Manager BuildPack"""

def get_path(self):
"""Return paths to be added to PATH environment variable"""
return super().get_path() + ["/home/${NB_USER}/.guix-profile/bin"]


def get_build_scripts(self):
"""
Install guix package manager version 1.3.0.x86_64-linux, using
an unmodified installation script found at
https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
"""
return super().get_build_scripts() + [
(
"root",
"""
yes | BIN_VER=1.3.0.x86_64-linux \
bash /home/${NB_USER}/.local/bin/guix-install.bash
""",
),

]

def get_build_script_files(self):

"""Copying guix installation script on the image"""
return {
"guix/guix-install.bash":
"/home/${NB_USER}/.local/bin/guix-install.bash",
}

def get_assemble_scripts(self):
"""
Wake up the guix daemon with root permission, set guix environnement
variables, make sure we never use debian's python by error by
renaming it, then, as an user install packages listed in
manifest.scm, use guix time-machine if channels.scm file exists
"""
assemble_script ="""
/var/guix/profiles/per-user/root/current-guix/bin/guix-daemon \
--build-users-group=guixbuild --disable-chroot & \
mv /usr/bin/python /usr/bin/python.debian && \
su - $NB_USER -c '{}' && \
echo 'GUIX_PROFILE="$HOME/.guix-profile" ; \
source "$GUIX_PROFILE/etc/profile"'>> ~/.bash_profile
"""

if os.path.exists(self.binder_path("channels.scm")):
assemble_script = assemble_script.format(
"guix time-machine -C " + self.binder_path("channels.scm") +
" -- package -m " + self.binder_path("manifest.scm")
)
else:
assemble_script = assemble_script.format(
"guix package -m " + self.binder_path("manifest.scm")
)
return super().get_assemble_scripts() + [
( "root",
assemble_script,
)
]

def detect(self):
"""Check if current repo should be built with the guix BuildPack"""
return os.path.exists(self.binder_path("manifest.scm"))

Loading

0 comments on commit 074a5e3

Please sign in to comment.