You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+7-9Lines changed: 7 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,14 +123,14 @@ self-contained.
123
123
124
124
There is a GitHub Action for `rattler-build`. It can be used to install `rattler-build` in CI/CD workflows and run a build command. Please check out the [GitHub Action documentation](https://github.com/prefix-dev/rattler-build-action) for more information.
125
125
126
-
###The recipe format
126
+
## The Recipe Format
127
127
128
128
> **Note** You can find all examples below in the [`examples`](https://github.com/prefix-dev/rattler-build/tree/main/examples)
129
129
> folder in the codebase and run them with `rattler-build`.
130
130
131
131
A simple example recipe for the `xtensor` header-only C++ library:
132
132
133
-
```yaml
133
+
```yaml title="recipe.yaml"
134
134
context:
135
135
name: xtensor
136
136
version: 0.24.6
@@ -198,7 +198,7 @@ extra:
198
198
199
199
A recipe for the `rich` Python package (using `noarch`):
200
200
201
-
```yaml
201
+
```yaml title="recipe.yaml"
202
202
context:
203
203
version: "13.4.2"
204
204
@@ -251,7 +251,7 @@ about:
251
251
252
252
A recipe for the `curl` library:
253
253
254
-
```yaml
254
+
```yaml title="recipe.yaml"
255
255
context:
256
256
version: "8.0.1"
257
257
@@ -298,9 +298,7 @@ about:
298
298
299
299
For the `curl` library recipe, two additional script files (`build.sh` and `build.bat`) are needed.
If you only need to set environment variables when an environment is activated (rather than running arbitrary shell code), you can use JSON files in the `etc/conda/env_vars.d/` directory. This is more efficient and portable than using activation scripts.
60
+
61
+
### Package-specific environment variables
62
+
63
+
To set environment variables from your package, create a JSON file in `etc/conda/env_vars.d/`:
64
+
65
+
```text
66
+
<prefix>/etc/conda/env_vars.d/<package_name>.json
67
+
```
68
+
69
+
The JSON file should contain a simple object with string key-value pairs:
70
+
71
+
```json
72
+
{
73
+
"MY_PACKAGE_HOME": "/path/to/data",
74
+
"MY_PACKAGE_CONFIG": "default",
75
+
"SOME_API_ENDPOINT": "https://api.example.com"
76
+
}
77
+
```
78
+
79
+
To include this in your package, add to your build script:
### Using the $PREFIX path in environment variables
99
+
100
+
Since JSON files contain static values, you need to expand the `$PREFIX` environment variable when creating the file during the build. Use a heredoc **without** quotes to allow bash variable expansion:
Note the difference: `<< 'EOF'` (quoted) prevents variable expansion, while `<< EOF` (unquoted) allows bash to expand `$PREFIX` before writing the file.
123
+
124
+
### Complete directory structure
125
+
126
+
Here's the complete structure of activation-related files in a conda environment:
│ └── zzz-override.json # Loaded last due to filename
144
+
└── conda-meta/
145
+
├── pkg1-1.0.0-h1234.json # Package metadata
146
+
├── pkg2-2.0.0-h5678.json
147
+
└── state # Environment-level state (JSON)
148
+
```
149
+
150
+
### Processing order
151
+
152
+
When an environment is activated, the activation system:
153
+
154
+
1. Reads all `.json` files from `etc/conda/env_vars.d/` in **lexicographical order**
155
+
2. Reads the `conda-meta/state` file (if it exists)
156
+
3. Merges all variables, with later files overriding earlier ones
157
+
158
+
This means:
159
+
160
+
- If multiple packages define the same variable, the package whose filename comes later alphabetically will win
161
+
- You can prefix filenames with numbers (e.g., `00-base.json`, `50-mypkg.json`) to control priority
162
+
- The `conda-meta/state` file always has the highest priority
163
+
164
+
29
165
## Post-link and pre-unlink scripts
30
166
31
167
The `post-link` and `pre-unlink` scripts are executed when the package is installed or uninstalled. They are both heavily discouraged but implemented for compatibility with conda in `rattler-build` since version 0.17.
0 commit comments