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 Jul 5, 2021
1 parent 73ab48a commit fc4cc45
Show file tree
Hide file tree
Showing 20 changed files with 172 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

75 changes: 75 additions & 0 deletions repo2docker/buildpacks/guix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""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() + [
"/var/guix/profiles/per-user/$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?id=a0178d34f582b50e9bdbb0403943129ae5b560ff
"""
return super().get_build_scripts() + [
(
"root",
"""
bash /tmp/.local/bin/guix-install.bash
""",
),

]

def get_build_script_files(self):

"""Copying guix installation script on the image"""
return {
"guix/guix-install.bash":
"/tmp/.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="/var/guix/profiles/per-user/$NB_USER/.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"))

8 changes: 8 additions & 0 deletions repo2docker/buildpacks/guix/guix-install.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# This downloads and installs a pinned version of Guix
set -ex

wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh?id=a0178d34f582b50e9bdbb0403943129ae5b560ff

yes | BIN_VER=1.3.0x86_64-linux \
bash guix-install.sh?id=a0178d34f582b50e9bdbb0403943129ae5b560ff
4 changes: 4 additions & 0 deletions tests/guix/binder-dir/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`manifest.scm` in a binder/ directory
-------------------------------------

Check if we can find and use `manifest.scm` when it is ina `binder/` sub-directory.
3 changes: 3 additions & 0 deletions tests/guix/binder-dir/binder/manifest.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(specifications->manifest
'("jupyter"
"hello"))
3 changes: 3 additions & 0 deletions tests/guix/binder-dir/verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

hello
4 changes: 4 additions & 0 deletions tests/guix/ignore-outside/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`manifest.scm` in main directory and in `binder/`
-------------------------------------------------

Check if `manifest.scm` located in the `binder/` sub-directory is prefered to the one in the main directory.
4 changes: 4 additions & 0 deletions tests/guix/ignore-outside/binder/manifest.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(specifications->manifest
'("jupyter"
"python"
"python-numpy"))
2 changes: 2 additions & 0 deletions tests/guix/ignore-outside/manifest.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(specifications->manifest
'("jupyter"))
3 changes: 3 additions & 0 deletions tests/guix/ignore-outside/verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python3

import numpy
4 changes: 4 additions & 0 deletions tests/guix/simple-channels/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`manifest.scm` and `channels.scm` in main directory
---------------------------------------------------

CHeck if we can use `manifest.scm` alongside a `channels.scm` file using `guix time-machine ...`
20 changes: 20 additions & 0 deletions tests/guix/simple-channels/channels.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(list (channel
(name 'guix)
(url "https://git.savannah.gnu.org/git/guix.git")
(commit
"f1bfd9f1948a5ff336d737c0614b9a30c2bb3097")
(introduction
(make-channel-introduction
"9edb3f66fd807b096b48283debdcddccfea34bad"
(openpgp-fingerprint
"BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA"))))
(channel
(name 'nonguix)
(url "https://gitlab.com/nonguix/nonguix")
(commit
"46c1d8bcca674d3a71cd077c52dde9552a89873d")
(introduction
(make-channel-introduction
"897c1a470da759236cc11798f4e0a5f7d4d59fbc"
(openpgp-fingerprint
"2A39 3FFF 68F4 EF7A 3D29 12AF 6F51 20A0 22FB B2D5")))))
3 changes: 3 additions & 0 deletions tests/guix/simple-channels/manifest.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(specifications->manifest
'("jupyter"
"hello"))
3 changes: 3 additions & 0 deletions tests/guix/simple-channels/verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

hello
5 changes: 5 additions & 0 deletions tests/guix/simple/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

`manifest.scm` in the main directory
----------------------------------

Check if we can find and use `manifest.scm` when it is in the main directory.
3 changes: 3 additions & 0 deletions tests/guix/simple/manifest.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(specifications->manifest
'("jupyter"
"hello"))
3 changes: 3 additions & 0 deletions tests/guix/simple/verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

hello

0 comments on commit fc4cc45

Please sign in to comment.