-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hugo Lecomte
committed
Aug 11, 2021
1 parent
73ab48a
commit 8edfa53
Showing
20 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"""BuildPack for guix environments""" | ||
import os | ||
|
||
from ..base import BuildPack, BaseImage | ||
|
||
|
||
class GuixBuildPack(BaseImage): | ||
"""A Guix Package Manager BuildPack""" | ||
|
||
def get_build_env(self): | ||
"""""" | ||
env = super().get_build_env() + [ | ||
("GUIX_DIR", "${APP_BASE}/guix") | ||
] | ||
return env | ||
|
||
def get_path(self): | ||
"""Return paths to be added to PATH environment variable""" | ||
path = super().get_path() | ||
path.insert(0, "${GUIX_DIR}/bin") | ||
return path | ||
|
||
|
||
|
||
def get_build_scripts(self): | ||
""" | ||
Install a pinned version of Guix package manager, | ||
precised in guix-install.bash. | ||
""" | ||
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): | ||
""" | ||
Launch Guix daemon with --disable-chroot to avoid the need | ||
of root privileges for the user. | ||
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. | ||
Finally set Guix environment variables. | ||
""" | ||
assemble_script =""" | ||
/var/guix/profiles/per-user/root/current-guix/bin/guix-daemon \ | ||
--build-users-group=guixbuild --disable-chroot & \ | ||
su - $NB_USER -c '{}' && \ | ||
echo 'GUIX_PROFILE="/var/guix/profiles/per-user/'$NB_USER'/guix-profile" ; \ | ||
source "$GUIX_PROFILE/etc/profile"'>> /etc/profile.d/99-guix.sh | ||
""" | ||
|
||
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")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
# This downloads and installs a pinned version of Guix using a pinned version of the installation script. | ||
# Here is the commit associated with Guix version 1.3.0 the latest version when this script was written. | ||
set -euxo pipefail | ||
|
||
GUIX_COMMIT="a0178d34f582b50e9bdbb0403943129ae5b560ff" | ||
BIN_VER="1.3.0x86_64-linux" | ||
GUIX_SHA256="bcdeaa757cd42d2c9de4791272737e9ee0d518398403955f113611f4a893380a" | ||
|
||
wget "https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh?id=$GUIX_COMMIT" | ||
|
||
echo "$GUIX_SHA256 guix-install.sh?id=$GUIX_COMMIT" | sha256sum -c | ||
|
||
(yes || true) | BIN_VER=$BIN_VER bash guix-install.sh?id=$GUIX_COMMIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(specifications->manifest | ||
'("jupyter" | ||
"hello")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(specifications->manifest | ||
'("jupyter" | ||
"python" | ||
"python-numpy")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(specifications->manifest | ||
'("jupyter")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ...` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(specifications->manifest | ||
'("jupyter" | ||
"hello")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(specifications->manifest | ||
'("jupyter" | ||
"hello")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
hello |