X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix.git;a=blobdiff_plain;f=modules%2Fprivate%2Fbuildbot%2Fcommon%2Fbuild_helpers.py;h=acea90591f5ca16b524e0e41b7d22087ef72cf7c;hp=ed7ada368016b085e4aa8573cfae4ed1958a3d37;hb=6b017278cb0dff04fc6cde863a1bffa012ed5f59;hpb=ecd9a3060bdcc4309e4fad6c046b72b880618774 diff --git a/modules/private/buildbot/common/build_helpers.py b/modules/private/buildbot/common/build_helpers.py index ed7ada3..acea905 100644 --- a/modules/private/buildbot/common/build_helpers.py +++ b/modules/private/buildbot/common/build_helpers.py @@ -1,10 +1,11 @@ from buildbot.plugins import util, steps, schedulers from buildbot_buildslist import BuildsList +from shutil import which __all__ = [ "force_scheduler", "deploy_scheduler", "hook_scheduler", "clean_branch", "package_and_upload", "SlackStatusPush", - "XMPPStatusPush" + "XMPPStatusPush", "NixShellCommand" ] # Small helpers" @@ -30,6 +31,26 @@ def package_and_upload(package, package_dest, package_url): command=["rm", "-f", package]), ] +# Steps +class NixShellCommand(steps.ShellCommand): + def __init__(self, command=None, pure=True, nixfile=None, **kwargs): + assert(isinstance(command, str)) + oldpath = kwargs.get("env", {}).get("PATH", None) + if which("nix-shell", path=oldpath) is None: + kwargs["env"] = kwargs.get("env", {}) + if isinstance(oldpath, str): + kwargs["env"]["PATH"] = "/run/current-system/sw/bin:" + oldpath + elif isinstance(oldpath, list): + kwargs["env"]["PATH"] = ["/run/current-system/sw/bin"] + oldpath + nixcommand = ["nix-shell"] + if pure: + nixcommand.append("--pure") + nixcommand.append("--run") + nixcommand.append(command) + if nixfile is not None: + nixcommand.append(nixfile) + super().__init__(command=nixcommand, **kwargs) + # Schedulers def force_scheduler(name, builders): return schedulers.ForceScheduler(name=name,