Home Explore Blog CI



nix

src/nix/print-dev-env.md
7fdf7b40015e7f13eed5c8ca9f34b9e30c5c2ec2cf47a7d5000000030000046e
R""(

# Examples

* Apply the build environment of GNU hello to the current shell:

  ```console
  # . <(nix print-dev-env nixpkgs#hello)
  ```

* Get the build environment in JSON format:

  ```console
  # nix print-dev-env nixpkgs#hello --json
  ```

  The output will look like this:

  ```json
  {
    "bashFunctions": {
      "buildPhase": " \n    runHook preBuild;\n...",
      ...
    },
    "variables": {
      "src": {
        "type": "exported",
        "value": "/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz"
      },
      "postUnpackHooks": {
        "type": "array",
        "value": ["_updateSourceDateEpochFromSourceRoot"]
      },
      ...
    }
  }
  ```

# Description

This command prints a shell script that can be sourced by `bash` and
that sets the variables and shell functions defined by the build
process of [*installable*](./nix.md#installables). This allows you to get a similar build
environment in your current shell rather than in a subshell (as with
`nix develop`).

With `--json`, the output is a JSON serialisation of the variables and
functions defined by the build process.

)""

Chunks
5f293ca5 (1st chunk of `src/nix/print-dev-env.md`)
Title: nix print-dev-env: Usage and Description
Summary
The `nix print-dev-env` command outputs a shell script or JSON representation of the build environment for a given installable. When sourced, the shell script sets variables and functions in the current shell, mimicking the build environment. The `--json` flag outputs a JSON serialization of these variables and functions. Examples are provided for applying the build environment of GNU hello to the current shell and retrieving the build environment in JSON format.