Repository: prefix-dev/pixi

Issue #1118: docker support: Let pixi create images
Created: 2024-04-04T17:06:32Z
Problem description
It would be nice if pixi could create an OCI image that consists of only the environment (ideally directly activated) without needing to invoke docker (ideally fully reproducible 🤩).
Apko can do something similar for alpine images/packages. https://github.com/chainguard-dev/apko

Duplicate issue #1298: Expose activation env vars as JSON
Created: 2024-04-29T21:12:41Z
Problem description
Motivation
In some instances, it is convenient to not require pixi run in order to make use of pixi-installed binaries (one example might be standalone binaries such as terraform). When working locally, this is easily possible by running eval $(pixi shell-hook). However, this might not be very convenient in CI environments such as GitHub Actions.
In this instance, it would be more convenient for tools to get access to the environment variables (and path modifications) that are set by the "activation" of a pixi environment and export them in a way that integrates well with the CI environment. For GitHub Actions, this would be appending to $GITHUB_PATH and $GITHUB_ENV, allowing all subsequent steps in a workflow job to access pixi-installed binaries (even if using an external action that has no notion of the installation process of the binary).
This feature request is a follow-up from the discussion in prefix-dev/setup-pixi#103.
Potential Implementation
Given the existing functionalities in pixi, the implementation seems rather straightforward. The two main questions would be:

How should this feature be integrated into the CLI interface?
What is an appropriate output format?

CLI Interface
The most straightforward implementation would likely be to add the option to emit JSON as part of the shell-hook subcommand. From a naming perspective, this is, however, not ideal (pixi shell-hook --shell json?). Instead, one could consider adding a new top-level subcommand (pixi env?) although this might be a little prominent given the narrow use case of this feature.
Output Format
Given the way that GitHub Actions distinguishes between PATH and other environment variables, a usable output format would need to supply these separately. For maximum transferability across different tools, JSON seems like an appropriate choice for the format as well.
A potential schema could be:
{
    "version": 1,
    "pathComponents": ["<path>"],
    "environmentVariables": {
        "<key>": "<value>"
    }
}
The pathComponents should provide the paths that would be added to PATH by the environment activation, environmentVariables would provide all other new & modified environment variables.
The version key is likely optional, however, it would allow for breaking changes to the format without breaking other tools relying on it silently.

Closing comment (2024-04-30T11:32:04Z): IMO this should be an opt-in feature in setup-pixi (I think we all agree on that).
We probably need to handle PATH a bit differently than the other environment variables as there is an extra addPath command that appends instead of overwrites the variable.
We probably also want to think about how pixi should behave when there are additional things happening in the activation scripts (for example in the MSVC compiler, the compilers are downloaded during activation because of licensing reasons).
This might be actually sort-of related to #1118 as setting environment variables also needs to happen in some way when creating "already activated" docker images.