+# Steps
+class NixShellCommand(steps.ShellCommand):
+ def __init__(self, command=None, nixPackages=[], pure=True, nixFile=None, nixIncludes={}, nixArgs={}, **kwargs):
+ 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"]
+ for k, v in nixArgs.items():
+ nixcommand.append("--arg")
+ nixcommand.append(k)
+ nixcommand.append(v)
+ if pure:
+ nixcommand.append("--pure")
+ for k, v in nixIncludes.items():
+ nixcommand.append("-I")
+ nixcommand.append("{}={}".format(k, v))
+ nixcommand.append("--run")
+ nixcommand.append(command)
+ if len(nixPackages) > 0:
+ nixcommand.append("-p")
+ nixcommand += nixPackages
+ elif nixFile is not None:
+ nixcommand.append(nixFile)
+ super().__init__(command=nixcommand, **kwargs)
+