|
| 1 | +"""BuildPack for guix environments""" |
| 2 | +import os |
| 3 | + |
| 4 | +from ..base import BuildPack, BaseImage |
| 5 | + |
| 6 | + |
| 7 | +class GuixBuildPack(BaseImage): |
| 8 | + """A guix Package Manager BuildPack""" |
| 9 | + |
| 10 | + def get_path(self): |
| 11 | + """Return paths to be added to PATH environment variable""" |
| 12 | + return super().get_path() + ["/home/${NB_USER}/.guix-profile/bin"] |
| 13 | + |
| 14 | + |
| 15 | + def get_build_scripts(self): |
| 16 | + """ |
| 17 | + Install guix package manager version 1.3.0.x86_64-linux, using |
| 18 | + an unmodified installation script found at |
| 19 | + https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh |
| 20 | + """ |
| 21 | + return super().get_build_scripts() + [ |
| 22 | + ( |
| 23 | + "root", |
| 24 | + """ |
| 25 | + yes | BIN_VER=1.3.0.x86_64-linux \ |
| 26 | + bash /home/${NB_USER}/.local/bin/guix-install.bash |
| 27 | + """, |
| 28 | + ), |
| 29 | + |
| 30 | + ] |
| 31 | + |
| 32 | + def get_build_script_files(self): |
| 33 | + |
| 34 | + """Copying guix installation script on the image""" |
| 35 | + return { |
| 36 | + "guix/guix-install.bash": |
| 37 | + "/home/${NB_USER}/.local/bin/guix-install.bash", |
| 38 | + } |
| 39 | + |
| 40 | + def get_assemble_scripts(self): |
| 41 | + """ |
| 42 | + Wake up the guix daemon with root permission, set guix environnement |
| 43 | + variables, make sure we never use debian's python by error by |
| 44 | + renaming it, then, as an user install packages listed in |
| 45 | + manifest.scm, use guix time-machine if channels.scm file exists |
| 46 | + """ |
| 47 | + assemble_script =""" |
| 48 | + /var/guix/profiles/per-user/root/current-guix/bin/guix-daemon \ |
| 49 | + --build-users-group=guixbuild --disable-chroot & \ |
| 50 | + mv /usr/bin/python /usr/bin/python.debian && \ |
| 51 | + su - $NB_USER -c '{}' && \ |
| 52 | + echo 'GUIX_PROFILE="$HOME/.guix-profile" ; \ |
| 53 | + source "$GUIX_PROFILE/etc/profile"'>> ~/.bash_profile |
| 54 | + """ |
| 55 | + |
| 56 | + if os.path.exists(self.binder_path("channels.scm")): |
| 57 | + assemble_script = assemble_script.format( |
| 58 | + "guix time-machine -C " + self.binder_path("channels.scm") + |
| 59 | + " -- package -m " + self.binder_path("manifest.scm") |
| 60 | + ) |
| 61 | + else: |
| 62 | + assemble_script = assemble_script.format( |
| 63 | + "guix package -m " + self.binder_path("manifest.scm") |
| 64 | + ) |
| 65 | + return super().get_assemble_scripts() + [ |
| 66 | + ( "root", |
| 67 | + assemble_script, |
| 68 | + ) |
| 69 | + ] |
| 70 | + |
| 71 | + def detect(self): |
| 72 | + """Check if current repo should be built with the guix BuildPack""" |
| 73 | + return os.path.exists(self.binder_path("manifest.scm")) |
| 74 | + |
0 commit comments